Mail merge to PDF

D

Divinite

I've got a large mail merge document that I'm using to create multiple
reports. I'm using the add-in from here:

http://www.gmayor.com/individual_merge_letters.htm

The issue I'm having is that the automatically generated ToC won't
update when I do the merge (all the graphics do)

Since the ToC won't change as the design is static and only numbers in
tables and graphics change, I tried pasting a static version in and
creating bookmarks in Word pointing to the section headers. When I
run the merge (and my PDF settings all say to keep bookmarks), it
strips the ToC and doesn't place the bookmarks in the created files.

I upgraded to Acrobat 9 yesterday to see if that would help, it
didn't.

Any ideas?

Thank you in advance.
 
G

Graham Mayor

The reason this occurs is that the add-in simply prints to the Adobe driver
and does not use the Adobe add-in for Word which transfers the bookmarks. I
cannot see an easy solution to your problem, though Doug may have some
ideas.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Doug Robbins - Word MVP

Hi Graham,

I think if Word 2007 is being used, we should be able to use code like the
following, instead of using the PDF printer

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Documents and Settings\Doug Robbins\My Documents\Chris
Armstrong\Doc3.pdf" _
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False,
OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1,
To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True,
_
CreateBookmarks:=wdExportCreateHeadingBookmarks,
DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False

The above was recorded, except that I changed the CreateBookmarks setting to
wdExportCreateHeadingBookmarks, which I assume may allow the functionality
to click on a table of contents entry and have the focus move to that part
of the document.

I am not however completely sure of that and think that a "roll-your-own"
equivalent to mailmerge may be required where you start with the main
documnet in the form of a template with DOCVARIABLE fields in place of
MERGEFIELDS and then have a macro that iterates through the data source
creating a new document from the template for each record and setting the
values of variables in the document to the values in the fields in that
record, then saving that file in the required format.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

Good thinking - though it was not so straightforward to modify the add-in to
adopt this procedure and maintain compatibility with Word versions below
2007 :(

I think I have cracked it and have posted a version on my web site -
http://www.gmayor.com/Extras/MMtoDocsRev32.zip

which the OP can try out. It requires the Microsoft PDF plug-in for Word
2007 -
http://www.microsoft.com/downloads/...11-3e7e-4ae6-b059-a2e79ed87041&displaylang=en .
, but still requires Acrobat for Word versions below 2007.

It works with Word 2007 and my test files, adding the extension .pdf to the
filename produced by the splitter eg filename.docx.pdf. I suppose I could
have stripped off the docx before renaming, but frankly life's too short.

Please try and break it. :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Divinite

I just tried it out and here's what I noticed:

- It created bookmarks based on headers for the document (yeah!)
- It did not create the bookmark links that I created in the ToC at
the beginning of the document (Question here - If I left in the
generated ToC would it work?)
- It removed the transparency on my logo images in the header, adding
a black background to them
- It did not include the .docx on the first merge, but did on the rest
(I'd prefer it didn't on all, of course)
- It messed up the formatting on my cover page (put a huge color block
instead of just a border on the first one, put one of the sides as
gray instead of the assigned color on the rest)
- It changed the style for my section intros (previously with a dashed
border on top and one side, now a solid border)

Thank you!

Jessica
 
D

Doug Robbins - Word MVP

I doubt that any of the "features" that you are getting can be controlled by
tweaking the addin.

Going back to your original quest, I believe, though I have not tried it,
that even if you mailmerge to a new document (that will contain all of the
reports), the links from the table of contents to the sections of the
document will not be present.

That being the case, it would be necessary to create a "roll-your-own"
equivalent to mail merge that instead of using a mail merge main document
containing MERGEFIELDS, used a template with DOCVARIABLE fields in place of
the merge fields and then you use VBA code to iterate through what was the
data soure, creating a new document from the template for each record in the
data source, and setting the values of variables in the document to the
values in the fields for the current record, and then updated the fields in
the document so that the DOCVARIABLE fields displayed that data. The code
would then save that document before going on to the next record and
repeating the process.

You then maybe able to use something like fellow MVP Jonathon West's
Multilinker to create the .pdf documents

See http://www.intelligentdocuments.co.uk/multilinker.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

While I agree with Doug, have you tried simply exporting the document to PDF
using the Word add-in (without for the moment worrying about the merge). Are
there any settings of the PDF options that reproduce the graphics in your
document correctly? If so the options can be changed in the add-in.

When you say that it did not include docx in the first merge, do you mean
after installing the revised add-in? If so did you remove the original
add-in first?

While it would be possible to change the filename to remove docx from the
PDF name, I don't feel inclined to do so for a one off that does not even
provide the functionality required to print your document (which is also why
this version of the add-in has not replaced the add-in available to download
normally from my web site).

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Divinite

I've exported the doc straight to PDF without doing the merge and all
graphics have appeared correctly. This was using, at separate times,
the Acrobat ribbon "Create PDF" and the print dialog. The last
version of the plug-in I was using (28) exported all graphics
correctly. I'm not sure how to get it to specifically print using the
Word add-in for PDF. There was no place to select the Word add-in for
PDF. I'm using Acrobat 9 (although I also exported it on ver 8), with
standard settings. The only thing I changed was to unclick the "Show
PDF result" and "Prompt for filename" options.

I installed the file SaveAsPDFandXPS.exe and it said it was
successful. It's not showing up anywhere (in the macro list or on the
add-ins ribbon). Since I can't find it, I don't know where the
settings would be. Where should it be?

After installing the revised add-in the file name for the first one
was file1.pdf and from there on out they were file2.docx.pdf. I
removed my old version of the add-in, but I did leave the last version
of the exports in the same export folder. While it's possible to
change the file names, the issue for us comes in distribution of our
reports since we're not printing them. We're sending out reports to
1500 people, mail merging in the filenames to a download location.
They'll be on print letters and going to people that are not the most
tech savvy, so it's important to us that the file names are very
simple. Needless to say, with 550 customized reports among this group
of people, that's a bit too many files to rename. It wouldn't be an
issue except the client specifically requested bookmark functionality.

If the ToC links don't show up, that's not a killer for me. I don't
think I can figure out VB code (at least in the short amount of time I
have for this project) and it's not that important as long as they
exist in the PDF.

Thank you,
Jessica
 
G

Graham Mayor

The current version of the add-in available for download from my web site is
Version 31. This one (and version 28) print to the AdobePDF driver and thus
require Acrobat installed. The only changes you can make to the settings are
those in the printer driver. It does not use the Acrobat add-in with its
extra functionality.

The later versions of the Splitmerge add-in include a macro to create a
template to use for the merge when the merge document template is not
available - presumably you have the merge document template - and use the
merge document template when it is available, but the normal template if it
is not available. Using the normal template can produce formatting anomalies
if the merge document was based on some other template.

The additional version (32) linked to this thread is not fully developed and
uses the SaveAsPDFandXPS.exe add-in. This PDF add-in does not have any
Ribbon commands. It adds an option to the Save As menu.(PDF or XPS) and if
you select the PDF option, the dialog has an options button. (32) is
configured to save with 'Document structure tags for accessibilty' and ISO
19005-1 compliance checked, but it would be simple enough to change that.
You will find the relevant code:

If MakePDF = True Then
If Application.Version < 12 Then
NewDoc.PrintOut Background:=False
Else
NewDoc.ExportAsFixedFormat OutputFileName:= _
FldrPath & fnames(i) & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=True
End If
End If.

in the
Private Sub app_MailMergeAfterMerge(ByVal Doc As Document, ByVal DocResult
As Document)
code which you will find in the Merge Application class module.

In order to remove the docx. part of the filename, you can start by changing
the above section of code to:

If MakePDF = True Then
If Application.Version < 12 Then
NewDoc.PrintOut Background:=False
Else
NewDoc.ExportAsFixedFormat OutputFileName:= _
Left(FldrPath & fnames(i), _
Len(FldrPath & fnames(i)) - 5) & ".pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=True
End If
End If

If you find the right combination of Microsoft PDF parameters to give you
the results you require, then please let me know, either by this thread or
to my web site and I will ad the changes to the live version of the add-in.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Divinite

I altered the lines for the file names and now they don't have the
docx in front of them. However, the first file, which was exporting
without the docx previously, is cutting off part of the merged file
name now. Not a huge deal since it's only one file and I know it will
always be the first in the list, but something to note.

I turned off the UseISO19005_1 option (False) and adjusted the
formatting of the cover page. This seems to have kept the formatting
as I want it (no color changes or type changes, etc). I have not been
able to figure out how to get the ToC to link, but at least there are
bookmarks in the PDF!

I tried to change the OptimizeFor:=wdExportOptimizeForPrint option
since we're screen viewing these only, but I couldn't figure out what
option should be for screen optimization.

Thank you,
Jessica
 
D

Doug Robbins - Word MVP

Set it to

wdExportOptimizeForOnScreen

According to the VBE Help, it results in a lower quality image and results
in a smaller file size. Therefore, I do not think that it will affect the
TOC Linking, but you never know until you try it.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

I altered the lines for the file names and now they don't have the
docx in front of them. However, the first file, which was exporting
without the docx previously, is cutting off part of the merged file
name now. Not a huge deal since it's only one file and I know it will
always be the first in the list, but something to note.

I turned off the UseISO19005_1 option (False) and adjusted the
formatting of the cover page. This seems to have kept the formatting
as I want it (no color changes or type changes, etc). I have not been
able to figure out how to get the ToC to link, but at least there are
bookmarks in the PDF!

I tried to change the OptimizeFor:=wdExportOptimizeForPrint option
since we're screen viewing these only, but I couldn't figure out what
option should be for screen optimization.

Thank you,
Jessica
 
G

Graham Mayor

I cannot imagine why you are getting a problem with the first file - it
doesn't happen here; however if you change the filenaming section to

If MakePDF = True Then
If Application.Version < 12 Then
NewDoc.PrintOut Background:=False
Else
NewDoc.ExportAsFixedFormat OutputFileName:= _
Replace(FldrPath & fnames(i), ".docx", "") & ".pdf", _
ExportFormat:=wdExportFormatPDF, ......etc

it uses a different method of stripping docx out of the filename that may
work for you.

You could also try replacing
wdExportCreateHeadingBookmarks
with
wdExportCreateWordBookmarks

to try and overcome your links problem.

Please let us know how you get on with this.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top