使用iTextSharp设置PDF版本 [英] Set PDF Version using iTextSharp
问题描述
任何人都知道如何使用iTextSharp以编程方式将PDF保存为较低的PDF版本,以便您可以使用要求PDF为5或更低版本的某些iTextSharp功能?
<我正在尝试将两个PDF版本7文档合并在一起,它坚持认为它们是版本5或更低。
有多奇怪PDF版本大多是一个建议。 PDF必须以下列内容开头:
%PDF-1.x
其中X为0,1,2,...
这只是一个线索阅读PDF的应用程序。唯一的线索。我从各种客户看到的大多数我需要版本X请求都是假的。我的同事iText编程员知道这一点,所以我觉得奇怪的是 iText 正在请求一个不同的版本。
您确定 iText 请求v5?
无论如何,要回答您的问题:
是的,iText可以更改PDF的版本号。遗憾的是,它只能在写出PDF时才能完成,而不是在读取时。您必须打开PDF,更改其版本,然后再次保存。
<你可能会作弊。将PDF读入字节数组并
pdfBytes [7] = 4;
,然后将这些字节传递给 PdfReader
。 PDF规范的版本1是1.0
版本2是1.1
...
所以如果你想要pdf版本5,你需要写出1.4,而不是1.5。
如果你不舒服戳一个像那么,你可以解析整个PDF,更改版本,然后再写出来:
PdfReader reader = new PdfReader( pdfPath);
PdfStamper压模= new PdfStamper(reader,outputStream);
stamper.setPdfVersion(PdfWriter.PDF_VERSION_1_4);
stamper.close();
然后你再读一遍,然后像以前一样把它合并。
Anyone know how to save a PDF as a lower PDF version programmatically using iTextSharp so that you can use certain iTextSharp features that require the PDF to be version 5 or lower?
I'm trying to merge two PDF version 7 documents together and it insists that they be version 5 or lower.
How odd. PDF versions are mostly a suggestion. PDFs must start with something like:
%PDF-1.x
Where the X is 0,1,2,...
This is just a clue to the app reading the PDF. The only clue. Most "I need version X" requests I see from various customers are bogus. My fellow iText coders know this, so it strikes me as odd that iText is requesting a different version.
You're sure its iText requesting v5?
At any rate, to answer your question:
Yes, iText can change the version number of a PDF. Sadly, it can only be done when writing out a PDF, not when reading it in. You'll have to open the PDF, change its version, and save it again.
You could probably cheat. Read the PDFs into byte arrays and pdfBytes[7] = 4;
, then pass those bytes on to a PdfReader
.
Version 1 of the PDF spec is 1.0 Version 2 is 1.1 ...
So if you want pdf version 5, you need to write out "1.4", not "1.5".
If you're not comfortable poking a byte like that, you can parse the whole PDF, change the version, then write it all out again:
PdfReader reader = new PdfReader(pdfPath);
PdfStamper stamper = new PdfStamper(reader, outputStream);
stamper.setPdfVersion(PdfWriter.PDF_VERSION_1_4);
stamper.close();
You'd then read it in again, and combine it as you have been.
这篇关于使用iTextSharp设置PDF版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!