javascript - printing pdf to multiple pages using jscrip via VBA
问题描述
After many days searching to print multiples pages of a pdf file in a single sheet by using only VBA code on Excel I find a way to use javascript via VBA thanks to user ReFran https://stackoverflow.com/a/49538950/16279586
Combining the code ReFran wrote with this reference https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_jsapiref.pdf#G4.1959527 I build some Frankenstein monster that doesn't work at all.
Suposedly it will open a pdf file, then print 2x2 pages on a single sheet and save in the same document the changes (turning from a 4 pages pdf to a 1 page pdf) I'm a newbie in VBA and absolutely ignorant in javascript, can anyone give me a helping hand with this?
Sub test()
Dim app As acroApp
Dim avdoc As AcroAVDoc
Dim aform As AFormApp
Path = "C:\1.pdf"
Set app = CreateObject("Acroexch.app")
app.Show
Set avdoc = CreateObject("AcroExch.AVDoc")
Set aform = CreateObject("AFormAut.App") 'from AFormAPI
If avdoc.Open(Path, "") Then
'// write some js code on a vbs variable
js = "pp = this.getPrintParams();" _
& "pp.printerName = "";" _
& "pp.pageHandling = pp.constants.handling.nUp;" _
& "pp.nUpPageOrders = pp.constants.nUpPageOrders.Horizontal;" _
& "pp.nUpNumPagesH = 2;" _
& "pp.nUpNumPagesV = 2;" _
& "pp.nUpPageBorder=true;" _
& "this.print(pp);"
'//execute the js code
aform.Fields.ExecuteThisJavaScript js
End If
Set aform = Nothing
Set avdoc = Nothing
Set app = Nothing
End Sub
解决方案
推荐阅读
- apache-kafka - 检查消息已使用命令行写入 kafka 主题
- opensql - 在 ABAP CDS“POS(1) invalid exponent”中转换后出错
- c - 无法理解当我运行此代码时会发生什么
- python - 如何使我的数据适应这种线性矩阵 pytorch 优化方法?
- android - SingleTask 活动在同一个进程中被多次创建
- sql - SQL 查询联接 4 个表
- flutter - 如何防止图表中的 setState() 上的指标点消失
- html - 所需的模板驱动表单允许空字符串 - Angular 7/8
- xamarin.forms - Xamarin 表单自定义内容视图(复合控件)隐式样式错误
- selenium-webdriver - 将 translate() 函数用于 xpath 不区分大小写时的混淆