使用ContentByteUtils进行原始PDF操作 [英] Using ContentByteUtils for raw PDF manipulation
问题描述
这是一个跟进问题:
我有一个我在Illustrator中创建的pdf,它在页面中间基本上是黑色的形状,没有别的。我需要动态改变那个形状的颜色。
I have a pdf I created in Illustrator that has basically a black shape in the middle of the page and nothing else. I need to change the color of that shape dynamically.
从上面的帖子的回复中我使用iTextSharp(.NET C#)通过ContentByteUtils.GetContentBytesForPage()获取PDF的原始内容并更改颜色原始水平。
From the response to the post above I am using iTextSharp (.NET C#) to get the raw contents of the PDF through ContentByteUtils.GetContentBytesForPage() and changing the color at the raw level.
问题是我找不到通过iTextSharp将结果保存回原始PDF或新PDF文件的任何方法。我目前仍然坚持原始内容的字节数组,但需要弄清楚如何保存。
Problem is that I can't find any way of saving the results back into either the original PDF or a new PDF file via iTextSharp. I'm currently stuck with a byte array of the raw contents but need to figure out how to save.
请帮助!
推荐答案
为什么使用 ContentByteUtils.GetContentBytesForPage()
?
我会用:
PdfReader reader = new PdfReader(src);
byte[] content = reader.GetPageContent(pageNumber);
// do stuff with content
reader.SetPageContent(pageNumber, content);
using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (PdfStamper stamper = new PdfStamper(reader, fs)) {
}
}
这篇关于使用ContentByteUtils进行原始PDF操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!