gpt4 book ai didi

vba - 在新页面部分中初始存在的 pdf 文件末尾添加打印区域内容(附加)

转载 作者:行者123 更新时间:2023-12-03 01:42:26 25 4
gpt4 key购买 nike

为了生成报告,我使用以下方法创建了 pdf。

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

ActiveSheet中,有指定的打印区域,Witch包含一个Table,因此表的列过滤值已通过编程方式更改,并且需要:

我想要通过更改过滤标准来改革打印区域的新面貌;在新页面部分中悄悄地在初始 pdf 文件末尾添加内容,无需创建新的 pdf 文件。

我怎样才能做到这一点?

我已在我的系统上安装了 ADOBE Acrobat Professional,并且能够在 VBA 引用中添加适当的引用。

最佳答案

您只需要“Acrobat”库。

一个简单的解决方案是使用 native ExportAsFixedFormat 方法首先将每个部分保存为单独的 PDF 文件,例如“C:\temp\Part1.pdf”和“C:\temp\Part2.pdf”

然后使用 Acrobat API 中的 InsertPages 方法,如下例所示:

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:\temp\Part1.pdf")
Part2Document.Open ("C:\temp\Part2.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:\temp\MergedFile.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

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

Adobe 开发人员指南:http://www.adobe.com/devnet/acrobat/pdfs/iac_developer_guide.pdf

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

关于vba - 在新页面部分中初始存在的 pdf 文件末尾添加打印区域内容(附加),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46327666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com