Home:ALL Converter>Creating a pdf using Word VBA and Adobe Acrobat

Creating a pdf using Word VBA and Adobe Acrobat

Ask Time:2018-06-28T04:26:27         Author:Adam Jacobs

Json Formatter

I am trying to write a macro that creates a pdf of a Word document.

The code I have been using to do this uses ActiveDocument.ExportAsFixedFormat. This works up to a point, but it tends to fail when creating a pdf of a large document (and some of the documents I'll be processing with this macro run to thousands of pages).

My understanding is that the ExportAsFixedFormat method uses Word's built-in PDF creation methods. What I really want to do is use Adobe Acrobat to do the PDF conversion. If I do that manually by clicking on the export as pdf buttons within Word (I have Adobe Acrobat installed on my machine) then everything is fine. It uses the actual Adobe Acrobat PDF conversion, and my PDF gets created without errors even on documents large enough to cause the ExportAsFixedFormat method to fail.

I've been trying to figure out how to automate the conversion to PDF from VBA using Acrobat, and banging my head against a brick wall.

I discovered the CreatePDFEx method, which in theory looks like it should do what I want, but I also discovered warnings that this is not a supported method and is not recommended. See here:

https://forums.adobe.com/thread/286431

And indeed when I tried it, it didn't work.

I then discovered the AcroExch.AVDoc and AcroExch.PDDoc objects, which looked like it might be another way. See, for example, here:

https://forums.adobe.com/thread/301714

That also came with a warning that it wasn't supported. When I tried it, it worked, but it was painfully slow, even with documents of just a few pages. I hate to think what it would be like with a 5000 page document.

Is it actually possible to do this? It doesn't seem like it should be rocket science, but I am failing to find anything that works.

All I want to be able to do is to reliably create pdfs from large Word docs. I think that probably the way to do that is to figure out how to use Adobe's tools via VBA (is there a supported method?), but I'd be perfectly happy with the built in Word method if I could solve the problem of it failing with large documents.

Many thanks for any help.

Edit: I should also have mentioned that I need my Word headings to end up as PDF bookmarks. The ExportAsFixedFormat method does that, but some other methods don't.

Author:Adam Jacobs,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/51070906/creating-a-pdf-using-word-vba-and-adobe-acrobat
macropod :

You can use the SaveAs or SaveAs2 method to save as a PDF instead of ExportAsFixedFormat. For example:\n\nActiveDocument.SaveAs FileName:=\"Filename.pdf\", FileFormat:=wdFormatPDF",
2018-06-28T04:57:21
yy