1

使用 VBA,对于给定的 JPEG(或 GIF 或 BMP),我想将其打印为 PDF,并在打印前设置页面大小。我已经研究了几种不同的打印方式,但似乎没有一种能够做我想做的事:

  • 使用 Acrobat SDK 调用AVDoc.Open(), AVDoc.GetPDDoc(), 然后PDDoc.Save(): can't choose page size using this method

  • 声明 WinAPI 函数SetDefaultPrinterShellExecute,用于SetDefaultPrinter将打印机设置为 PDF 打印驱动程序,然后调用ShellExecute(1,"print",filepath,"",rootdirectory,1):我还没有找到使用此方法设置页面大小的方法

可以使用与 Office 文档对象关联的方法设置页面大小,例如Worksheet.PageSetup.PaperSize = xlPaper11x17,但这仅设置该对象的页面大小,而不是我要打印的 JPEG。

4

1 回答 1

1

您可以将其导入 Excel 工作簿并从那里打印。这是一个基本的例子:

Dim ws As Worksheet
Dim pic As Picture

Set ws = ActiveSheet
ws.PageSetup.PaperSize = xlPaperA4
'Can also specify margins, etc.

ws.Range("A1").Activate
Set pic = ws.Pictures.Insert("C:\mypic.jpg")   
'Set picture size.
With pic.ShapeRange
    .LockAspectRatio = msoFalse
    .Height = Application.CentimetersToPoints(20)
    .Width = Application.CentimetersToPoints(15)
    'Or you could match the size to the paper margins from above.
End With

ws.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:="C:\mypic.pdf", OpenAfterPublish:=True

在 Excel 2010 中测试。

于 2012-09-07T08:28:56.757 回答