Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

vba - Add print area content (appending) at the end of initial existed pdf file in a new page section

For generating a report, I have create pdf with bellow approach.

ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    fileName:=ThisWorkbook.path & "
ep.pdf", _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

In the ActiveSheet, there were specified Print Area, Witch contains a Table, so table's column filtered value have change programmatically, and need:

I want new face of the print area that reforms by changing filtering criteria; get appends at the end of initial pdf file quietly, without creating a new pdf file, in a new page section.

How can I do that?

I have installed ADOBE Acrobat Professional on my system and able to add appropriate references in VBA references.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You just need the "Acrobat" library.

One simple solution is to use the native ExportAsFixedFormat method to save each section as a separate PDF file first, e.g. "C:empPart1.pdf" and "C:empPart2.pdf"

Then use the InsertPages method in the Acrobat API as per example below:

Sub MergePDF()

Dim AcroApp As Acrobat.CAcroApp

Dim Part1Document As Acrobat.CAcroPDDoc
Dim Part2Document As Acrobat.CAcroPDDoc

Dim numPages As Integer

Set AcroApp = CreateObject("AcroExch.App")

Set Part1Document = CreateObject("AcroExch.PDDoc")
Set Part2Document = CreateObject("AcroExch.PDDoc")

Part1Document.Open ("C:empPart1.pdf")
Part2Document.Open ("C:empPart2.pdf")

' Insert the pages of Part2 after the end of Part1
numPages = Part1Document.GetNumPages()

If Part1Document.InsertPages(numPages - 1, Part2Document, 
0, Part2Document.GetNumPages(), True) = False Then
    MsgBox "Cannot insert pages"
End If

If Part1Document.Save(PDSaveFull, "C:empMergedFile.pdf") = False Then
    MsgBox "Cannot save the modified document"
End If

Part1Document.Close
Part2Document.Close

AcroApp.Exit
Set AcroApp = Nothing
Set Part1Document = Nothing
Set Part2Document = Nothing

MsgBox "Done"

End Sub

Reference: http://www.khk.net/wordpress/2009/03/04/adobe-acrobat-and-vba-an-introduction/

Adobe Developer Guide: http://www.adobe.com/devnet/acrobat/pdfs/iac_developer_guide.pdf

Adobe API Reference: http://www.adobe.com/devnet/acrobat/pdfs/iac_api_reference.pdf


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...