我有用于从文件流打印 PDF 文档的代码(使用 PdfSharp 库):
private HttpResponseMessage PrintPdfDocument2(MemoryStream fileStream)
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(fileStream);
PdfSharp.Pdf.PdfDictionary dict = new PdfSharp.Pdf.PdfDictionary(document);
dict.Elements["/S"] = new PdfSharp.Pdf.PdfName("/JavaScript");
dict.Elements["/JS"] = new PdfSharp.Pdf.PdfString("this.print(true);\r");
document.Internals.AddObject(dict);
document.Internals.Catalog.Elements["/OpenAction"] = PdfSharp.Pdf.Advanced.PdfInternals.GetReference(dict);
var outputStream = new MemoryStream();
document.Save(outputStream);
result.Content = new ByteArrayContent(outputStream.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return result;
}
Run Code Online (Sandbox Code Playgroud)
它在 chrome 和 ie 中运行良好,但在 Firefox 中不起作用
对这个问题有什么想法吗????
谢谢你们的阅读!