方法1: 在PDF文件中使用嵌入式javascript您可以尝试使用javascript调用创建iText
PDFAction对象
this.print(false)(可以
newPdfAction(PdfAction.PRINTDIALOG)用于此操作),并将其与pdf文件的OpenAction事件相关联。
iText Java中的代码应如下所示:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("file.pdf"));...PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);writer.setOpenAction(action);...它在C#中应该不太不同。
附带说明一下,对于Amyuni PDF Creator
.Net,也可以通过在文档类中将属性“
AutoPrint”设置为TRUE来实现( 通常使用免责声明 )。
acPDFCreatorLib.Initialize();acPDFCreatorLib.SetLicenseKey("Amyuni Tech.", "07EFCDA00...BC4FB9CFD");Amyuni.PDFCreator.Iacdocument document = pdfCreator1.document;// Open a PDF document from fileSystem.IO.FileStream file1 = new System.IO.FileStream("test_input.pdf", FileMode.Open, FileAccess.Read, FileShare.Read);Iacdocument document = new Iacdocument(null);if (document.Open(file1, "")){ //Set AutoPrint document.Attribute("AutoPrint").Value = true; //Save the document System.IO.FileStream file2 = new System.IO.FileStream("test_output.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write); document.Save(file2, Amyuni.PDFCreator.IacFileSaveOption.acFileSaveView);}// Disposing the document before closing the stream clears out any data structures used by the document objectdocument.Dispose();file1.Close();// terminate library to free resourcesacPDFCreatorLib.Terminate();这种方法要求在要进行打印的阅读器中打开PDF文件,并且它的缺点是,如果将文件保存在本地,则每次以后打开文件时,都会显示打印对话框。
方法2: 使用浏览器中的javascript与显示该文件的阅读器进行通信。
我在这个SO问题中发现了另一种可能值得尝试的方法:
<html><script language="javascript">timerID = setTimeout("exPDF.print();", 1000);</script><body><object id="exPDF" type="application/pdf" data="111.pdf" width="100%" height="500"/></body></html>这个想法是在浏览器中使用javascript来指示PDF阅读器打印文件。这种方法适用于HTML页面中嵌入的PDF文件。



