每次打开pdf时都会收到“打开方式”提示

时间:2013-04-17 12:54:55

标签: c# winforms itextsharp

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);

1 个答案:

答案 0 :(得分: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);