如何用iTextsharp重新调整pdf内容的大小 [英] how to re-sizing pdf content with iTextsharp
问题描述
我只需要调整PDF文件中的页面内容,它与减少文件大小无关我只需要减少每个页面的内容,这是一个图像,能够打印为横向模式的小册子。
所以我需要减少每个页面内容的高度和宽度。
我使用ctext的itextSharp
最简单的方法是更改相关网页的默认用户空间单位大小。 >可以使用页面字典条目 / UserUnit 在每页的基础上配置默认用户空间单位,cf。 PDF规范中的表30 ISO 32000-1: 2008 :
UserUnit 编号(可选; PDF 1.6)一个正数,应给出默认用户空间单位的大小,以1/72英寸的倍数。
支持的值的范围应该取决于实现。
默认值:1.0(用户空间单位为1/72英寸)。
因此,您需要做的是为您的PDF文件创建PdfReader的PdfStamper,遍历页面字典,读取它们当前的 UserUnit 值(默认值:1.0),根据需要将其减少,写回,将页面字典标记为更改,并写入PdfStamper的结果。
I just need to resize page content in a pdf file, it's not related to Reducing file size I just need to reduce each page content which is one image to be able to print it as a booklet in landscape mode. So I need to reduce the height and the width of each page content.
I'm using iTextSharp with c#
The easiest way might be to change the size of default user space units for the pages in question.
The default user space units can be configured on a per-page basisusing the page dictionary entry /UserUnit, cf. table 30 in the PDF specification ISO 32000-1:2008:
UserUnit number (Optional; PDF 1.6) A positive number that shall give the size of default user space units, in multiples of 1⁄72 inch. The range of supported values shall be implementation-dependent.
Default value: 1.0 (user space unit is 1⁄72 inch).
Thus, all you have to do is create a PdfStamper for a PdfReader for your PDF file, iterate over the page dictionaries, read their current /UserUnit value (default: 1.0), reduce it as desired, write it back, mark the page dictionary as changed, and write the result of the PdfStamper.
这篇关于如何用iTextsharp重新调整pdf内容的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!