小编Nam*_* Vũ的帖子

PdfSharp - 在 PDF 文档中注入的 Javascript 在 Firefox 中不起作用

我有用于从文件流打印 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 中不起作用

对这个问题有什么想法吗????

谢谢你们的阅读!

javascript c# pdf asp.net pdfsharp

5
推荐指数
1
解决办法
1781
查看次数

标签 统计

asp.net ×1

c# ×1

javascript ×1

pdf ×1

pdfsharp ×1