我正在尝试通过VBA在Excel中创建大量的PDF文档。这些文档中的每一个都必须与我尚未创建的另一PDF合并(它始终仅是一页,应添加到我创建的文档的末尾)。
尽管用于合并PDF的代码可以正常工作,但它始终将纸张尺寸设置为标准格式A4并垂直旋转。
这是用于合并PDF的代码的一部分:
Sub MergeDocs()
Dim arrayFilePaths() As Variant
Set app = CreateObject("Acroexch.app")
arrayFilePaths = Array("first_document.pdf","second_document.pdf")
Set primaryDoc = CreateObject("AcroExch.PDDoc")
OK = primaryDoc.Open(arrayFilePaths(0))
Debug.Print "PRIMARY DOC OPENED & PDDOC SET: " & OK
For arrayIndex = 1 To UBound(arrayFilePaths)
numPages = primaryDoc.GetNumPages() - 1
Set sourceDoc = CreateObject("AcroExch.PDDoc")
OK = sourceDoc.Open(arrayFilePaths(arrayIndex))
Debug.Print "SOURCE DOC OPENED & PDDOC SET: " & OK
numberOfPagesToInsert = sourceDoc.GetNumPages
OK = primaryDoc.InsertPages(numPages, sourceDoc, 0, numberOfPagesToInsert, False)
Debug.Print "PAGES INSERTED SUCCESSFULLY: " & OK
OK = primaryDoc.Save(PDSaveFull, arrayFilePaths(0))
Debug.Print "PRIMARYDOC SAVED PROPERLY: " & OK
Set sourceDoc = Nothing
Next arrayIndex
Set primaryDoc = Nothing
app.Exit
Set app = Nothing
End Sub
我该怎么做才能保持second_document.pdf
的原始格式,或者手动设置其纸张尺寸和方向?
答案 0 :(得分:0)
这可能有帮助:
FileName = "second_document.pdf"
ActiveSheet.PageSetup.PaperSize = xlPaperA3
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName