0

C# 2008 Express,Winforms。使用 iTextSharp,每次我从存储在服务器上的模板创建 pdf 时,我都会收到“打开方式”提示,询问我想使用什么程序来打开 pdf ..这显然是 Acrobat 并且是打开任何程序的默认程序.pdf 如果我从存储在本地驱动器上的 pdf 执行相同操作,我不会收到消息,当我打开任何 pdf 时也不会收到此消息。由于我要分发这个程序,我不希望用户每次都收到这个提示。

string pdfTemplate = @"\\server\files\Temp\invoice.pdf";
string newFile = @"\\server\files\Temp\completed_invoice";

PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
pdfFormFields.SetField("Name", invoiceName);
pdfFormFields.SetField("Date", invoiceDate);
pdfFormFields.SetField("Address", invoiceAddress);
pdfFormFields.SetField("City", invoiceCity);
pdfFormFields.SetField("State", invoiceState);
pdfFormFields.SetField("Zip", invoiceZip);
pdfStamper.FormFlattening = false;
pdfStamper.Close();
Process.Start(newFile);
4

1 回答 1

0

尝试

string pdfTemplate = @"\\server\files\Temp\invoice.pdf";
string newFile = @"\\server\files\Temp\completed_invoice";

PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
AcroFields pdfFormFields = pdfStamper.AcroFields;
pdfFormFields.SetField("Name", invoiceName);
pdfFormFields.SetField("Date", invoiceDate);
pdfFormFields.SetField("Address", invoiceAddress);
pdfFormFields.SetField("City", invoiceCity);
pdfFormFields.SetField("State", invoiceState);
pdfFormFields.SetField("Zip", invoiceZip);
pdfStamper.FormFlattening = false;
pdfStamper.Close();


ProcessStartInfo start = new ProcessStartInfo(newFile); //or any other file name.
start.ErrorDialog = false;
start.UseShellExecute = false;
Process.Start(start);
于 2013-04-17T13:00:23.810 回答