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

标签 javascript c# asp.net pdf pdfsharp

我有用于从文件流打印 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;
    }

它在 chrome 中工作正常,但在 Firefox 中不工作

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

感谢大家阅读!

最佳答案

我找到了解决方案(通过查看 pdf.js source code )

var dict = new PdfDictionary(document);
dict.Elements["/Type"] = new PdfName("/Action");
dict.Elements["/S"] = new PdfName("/Named");
dict.Elements["/N"] = new PdfName("/Print");
document.Internals.AddObject(dict);
document.Internals.Catalog.Elements["/OpenAction"] = PdfSharp.Pdf.Advanced.PdfInternals.GetReference(dict);

关于javascript - PdfSharp - 在 PDF 文档中注入(inject)的 Javascript 在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34410950/

相关文章:

c# - Asp.net 从控件中检索内容

c# - 对 sqlcommand.executescalar 使用声明

javascript - 使用jquery合并动态创建表的选定单元格

javascript - 用于匹配包含 ID 的工作表名称并使其可见的 Apps 脚本

javascript - 显示/隐藏一个 div 有条件地点击另一个 div 中的链接

c# - 许多按钮的单个单击事件

c# - 序列化与编码

javascript - 更改图像标签列表的图像源并将其替换为特定列表

c# - 数据集更新时更新缓存

asp.net - 在某些情况下如何覆盖/更改 FormsAuthentication LoginUrl