使用iTextSharp从pdf中读取javascript [英] Read javascript from pdf using iTextSharp
本文介绍了使用iTextSharp从pdf中读取javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本,在加载pdf文件后运行,并填充pdf中的一些表单字段。我假设它是在场景后面运行的某种javascript。在javascript代码中存储了一些我需要检索的值。我使用iTextSharp来处理pdf文件。是否可以读取javascript代码或值,以便我可以在我的c#代码中以某种方式使用它们?
I have a script that runs after the pdf-file has been loaded and that populates some form fields in the pdf. I assume it is some kind of javascript running behind the scene. In the javascript code some values are stored that I need to retrieve. I use iTextSharp to work with the pdf-file. Is it possible to read the javascript code or the values so I can work with them in my c# code somehow?
推荐答案
这个问题回答:
var pdfReader = new PdfReader(infilename);
using (MemoryStream memoryStream = new MemoryStream())
{
PdfStamper stamper = new PdfStamper(pdfReader, memoryStream);
for (int i = 0; i <= pdfReader.XrefSize; i++)
{
PdfDictionary pd = pdfReader.GetPdfObject(i) as PdfDictionary;
if (pd != null)
{
PdfObject poAA = pd.Get(PdfName.AA); //Gets automatic execution objects
PdfObject poJS = pd.Get(PdfName.JS); // Gets javascript objects
PdfObject poJavaScript = pd.Get(PdfName.JAVASCRIPT); // Gets other javascript objects
//use poJS.GetBytes(), poJS.ToString() etc to inspect details...
}
}
stamper.Close();
pdfReader.Close();
File.WriteAllBytes(rawfile, memoryStream.ToArray());
}
这是PdfObject的参考页面班级。
Here's a reference page for the PdfObject class.
这篇关于使用iTextSharp从pdf中读取javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文