我需要打印一个我已更改的 pdf 文档,而不将其保存为新的 pdf 文档。下面的代码可以正常工作。但是,我想以完全不同的方式做到这一点,并且我同时有大脑滞后并且看不到解决方案。
我的代码示例
byte[] result;
using (MemoryStream ms = new MemoryStream())
{
PdfReader pdfReader = new PdfReader("c:\\templatePdf.pdf");
PdfStamper pdfStamper = new PdfStamper(pdfReader, ms);
/* abbreviated but here I alter the template pdf */
pdfStamper.FormFlattening = true;
pdfStamper.Close();
result = ms.GetBuffer();
}
/* Instead of saving a new file I would rather like to print
the altered template pdf in memory and then discard it */
using (FileStream fs = File.Create("C:\\Test.pdf"))
{
fs.Write(result, 0, (int)result.Length);
}
Process process = new Process();
process.StartInfo.FileName = "C:\\Test.pdf";
process.StartInfo.Verb = "printto";
process.StartInfo.Arguments = "\"" + ppr_PrinterDropDown.Text + "\"";
process.Start();
File.Delete("C:\\Test.pdf");