使用 .net 在 pdf 中编辑 javascript

发布于 2024-10-19 21:21:14 字数 332 浏览 2 评论 0原文

是否可以使用 .net 编辑 pdf 文档的 javascript?

我查看了 Acrobat SDK,但运气不佳。看起来您可以从表单等中检索值,但不能编辑文档。

我是不是偏离了轨道?这可能吗?

我尝试过 iTextSharp,但由于 pdf 包含表单字段,因此当我保存pdf。

有什么建议吗?

Is it possible to edit the javascript of a pdf document with .net?

I've looked at the Acrobat SDK, but without much luck. It looks like you can retrieve values from forms etc. but not edit the document.

Am I way off track? Is this even possible?

I've tried iTextSharp, but since the pdf contains form fields, the fields are lost when I save the pdf.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

把梦留给海 2024-10-26 21:21:14

好吧,显然你可以使用 iTextSharp:

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        PdfReader reader = new PdfReader(@"Source.pdf");
        FileStream output = new FileStream(@"Destination.pdf", FileMode.Create);

        PdfStamper pdfStamper = new PdfStamper(reader, output, '\0', true);               
        pdfStamper.JavaScript = "app.alert(\"Hello world!\");";

        pdfStamper.FormFlattening = false;
        pdfStamper.Close();
        reader.Close();

(这个问题有帮助)

Well, apparently you can with iTextSharp:

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        PdfReader reader = new PdfReader(@"Source.pdf");
        FileStream output = new FileStream(@"Destination.pdf", FileMode.Create);

        PdfStamper pdfStamper = new PdfStamper(reader, output, '\0', true);               
        pdfStamper.JavaScript = "app.alert(\"Hello world!\");";

        pdfStamper.FormFlattening = false;
        pdfStamper.Close();
        reader.Close();

(This question helped)

坐在坟头思考人生 2024-10-26 21:21:14

iTextSharp 上+1。至于保存时丢失的字段,值得注意的是 Fox It Reader 是免费的,并且允许保存可编辑的 PDF。如果这不是一个选项,那么大多数公司通常会选择 Acrobat Standard。您可以使用任意数量的 PDF 打印驱动程序并将编辑后的 ​​PDF 表单打印为 PDF,尽管此时它是只读的(在某些情况下仍然有用)。

+1 on iTextSharp. As to the fields being lost on save, it is worth noting that Fox It Reader is free and allows saving editable PDFs. If that isn't an option then it is usually Acrobat Standard at most companies. You could use any number of PDF print drivers and print the edited PDF form to PDF though it will be readonly at that point (still of some use in cases).

海的爱人是光 2024-10-26 21:21:14

当然,PDF文档的javascript是可以编辑的。

我不知道如何在其他库中完成它,但使用 Docotic.Pdf (我工作对于 Bit Miracle),您可以为整个控件、页面和文档添加/删除/编辑 javascript 操作。

这是设置和更改 javascript 操作的示例。该代码假设文档包含一个按钮。

PdfDocument doc = new PdfDocument("document-with-button.pdf");
// assume that first widget is a button
PdfButton button = doc.Widgets[0] as PdfButton; 

// add javascript action for OnMouseEnter event
PdfJavaScriptAction action = doc.CreateJavaScriptAction("app.alert('OnMouseEnter JavaScript Action',3)");
button.OnMouseEnter = action;

// change javascript action for OnMouseEnter event
(button.OnMouseEnter as PdfJavaScriptAction).Script = "app.alert('Well, hello from OnMouseEnter JavaScript Action',3)";

doc.Save("output.pdf");

Sure, javascript of a PDF document can be edited.

I don't know how it can be done in other libraries but with Docotic.Pdf (I work for Bit Miracle) you can add/remove/edit javascript actions for controls, pages and document as a whole.

Here is a sample for setting and changing javascript action. The code assumes that document contain a button.

PdfDocument doc = new PdfDocument("document-with-button.pdf");
// assume that first widget is a button
PdfButton button = doc.Widgets[0] as PdfButton; 

// add javascript action for OnMouseEnter event
PdfJavaScriptAction action = doc.CreateJavaScriptAction("app.alert('OnMouseEnter JavaScript Action',3)");
button.OnMouseEnter = action;

// change javascript action for OnMouseEnter event
(button.OnMouseEnter as PdfJavaScriptAction).Script = "app.alert('Well, hello from OnMouseEnter JavaScript Action',3)";

doc.Save("output.pdf");
情话难免假 2024-10-26 21:21:14

PDF4NET 可以加载 PDF 文件,并且可以让您访问所有 J​​avaScript 片段,无论它们位于何处在文档级别或字段/注释操作级别。

免责声明:我在开发 PDF4NET 的公司工作。

PDF4NET can load PDF files and it gives you access to all JavaScript fragments, whether they are located at document level or at field/annotation actions level.

Disclaimer: I work for the company that develops PDF4NET.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文