liu_kunlun 发表于 2006-12-21 20:08:00

转PDF

<p>下面的程序能够把p1,p2构成的区域打印n份。<br/>现在我想用程序将图形转PDF,但我不知道怎样将打印机名设为"Adobe PDF",也不知道怎样设定PDF文件名。<br/>请高手帮忙。</p><p>ThisDrawing.ModelSpace.Layout.RefreshPlotDeviceInfo<br/>ThisDrawing.ActiveLayout.PlotType = acWindow<br/>ThisDrawing.ActiveLayout.UseStandardScale = True<br/>ThisDrawing.ActiveLayout.StandardScale = acScaleToFit<br/>ThisDrawing.ActiveLayout.SetWindowToPlot p1, p2</p><p>ThisDrawing.Plot.NumberOfCopies = n<br/>ThisDrawing.Plot.PlotToDevice</p>

兰州人 发表于 2006-12-24 16:34:00

<font face="MS UI Gothic" size="2"><p><font face="宋体" color="#000000" size="2">基本原理如下:</font></p><p><font face="宋体" color="#000000" size="2">1. 使用Acrobat Distiller打印激活worksheet or range生成postscript文件</font></p><p><font face="宋体" color="#000000" size="2">2. 使用Acrobat Distiller API 将postscript转化成 .PDF 文件</font></p></font><p><font face="MS UI Gothic" size="2">其次要做以下几步</font></p><p><font face="MS UI Gothic" size="2">A 在VBA工程中引用Acrobat Distiller</font></p><p><font color="#000000" size="2">B 然后,进行Acrobat Distiller的打印设置</font></p><p><font color="#000000">&nbsp;Public
                        Sub MakePDF(ByVal strPDFFileName As
                        String)</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ' Define the postscript and .pdf file names.</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dim strPSFileName As
                        String</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dim xlWorksheet As Worksheet</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Dim objPdfDistiller As PdfDistiller</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strPSFileName = Left(strPDFFileName, InStrRev(strPDFFileName, "\")) &amp; "tmpPostScript.ps"</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ' Print the Excel ActiveSheet to the postscript file</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Set xlWorksheet = ActiveSheet</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Call xlWorksheet.PrintOut(copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, prtofilename:=strPSFileName)</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ' Convert the postscript file to .pdf</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Set objPdfDistiller = New PdfDistiller</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Call objPdfDistiller.FileToPDF(strPSFileName, strPDFFileName, "")</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ' Finally, delete the postscript file</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Call Kill(strPSFileName)</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;</font></p><p style="MARGIN: 0px;"><font color="#000000">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; End
                        Sub</font></p><p style="MARGIN: 0px;"><font color="#000000"></font></p><p style="MARGIN: 0px;"><font color="#000000">细节见</font><a href="http://blog.csdn.net/fangxinggood/archive/2006/02/14/599045.aspx"><font color="#000000">http://blog.csdn.net/fangxinggood/archive/2006/02/14/599045.aspx</font></a></p>

liu_kunlun 发表于 2006-12-25 15:42:00

<p>谢谢兰州人,我下来慢慢消化。</p>
页: [1]
查看完整版本: 转PDF