我有一个 pdf 文件,其中包含一些内容。它实际上是一个模板。我已设法从 pdf 中读取内容并根据要求进行更改并将其保存在字符串变量中。现在我必须创建一个新的 pdf 文件,该文件将进行更改,并且初始模板文件不会更改。
为了提高透明度,我附上了代码示例。我无法反映新 pdf 文件中的更改。它与初始模板文件相同,但文件名不同。
{
string oldpath = @ "../../../JobAdminLib/pdfTemplate/sample_new.pdf";
string newpath = @ "../../../JobAdminLib/pdfTemplate/sample_result_1.pdf";
if (File.Exists(oldpath)) {
PdfReader pdfReader = new PdfReader(oldpath);
for (int page = 1; page <= pdfReader.NumberOfPages; page++) {
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default,
Encoding.UTF8, Encoding.Default.GetBytes(currentText)));
string altertext = currentText.Replace("[_job]", "hahaha");
string alterjobno = altertext.Replace("[DMxxxxxxx]", "DM12345");
string text = alterjobno;
text.Append(alterjobno);
}
}
}
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)