我正在使用 iTextSharp 和 .NET 3.5 SP1(在 C# 中,您可以猜到)并使用 PdfStamper
类修改一些现有的 PDF。 现在我有两个问题:
转换坐标系
正如我所见,iTextSharp 使用(后记?)点作为测量单位,但我想将这些坐标转换为毫米。 现在,实现这一目标的最佳方法是什么?
查看文档揭示了以下方法:
PdfContentByte cb = new PdfContentByte();
System.Drawing.Drawing2D.Matrix scale = new System.Drawing.Drawing2D.Matrix(
0.352777778, 0, 0.352777778, 0, 0, 0); // 1 point = 0.352777778 mm
cb.Transform(scale);
我希望我得到了正确的变换矩阵。 但问题是:没有 System.Drawing.Drawing2D
程序集! 这个程序集是被删除了还是发生了什么? 我该怎么做才能将 iTextSharp 的坐标转换为毫米。 我这里是不是走错路了?
PDF 中的文本在使用相同坐标的不同 PDF 中被替换
我注意到,在修改具有相同内容的两个不同 PDF 文件时,相同的坐标被替换,并且文本没有放置在完全相同的位置。 造成这种情况的原因是什么以及如何预防?
这是第一个 PDF:
这是第二个 PDF,使用 iTextSharp 中完全相同的坐标创建:
任何帮助表示赞赏。
I'm working with iTextSharp and .NET 3.5 SP1 (in C#, as you can guess) and modify some existing PDFs using the PdfStamper
class. Now I've got two problems:
Transforming the coordinate system
As I see it, iTextSharp is using (postscript?) points as unit of measurement, but I'd like to transform these coordinates to millimeter. Now, how's the best way to achieve this?
Taking a look in the documentation revealed the following approach:
PdfContentByte cb = new PdfContentByte();
System.Drawing.Drawing2D.Matrix scale = new System.Drawing.Drawing2D.Matrix(
0.352777778, 0, 0.352777778, 0, 0, 0); // 1 point = 0.352777778 mm
cb.Transform(scale);
I hope I got the transformation matrix right. But the problem is: There is no System.Drawing.Drawing2D
Assembly! Was this assembly dropped or what happened to it? What can I do to transform the coordinates of iTextSharp to millimeter. Am I on the wrong way here?
Text in PDF gets displaced in a different PDF using the same coordinates
I noticed that while modifying two different PDF files with the same content, that the same coordinates got displaced and the text is not being placed at the exact same positions. What is causing this and how can I prevent it?
This is the first PDF:
This is the second PDF, created using the exact same coordinates in iTextSharp:
Any help is appreciated.
发布评论
评论(2)
http://msdn.microsoft.com/en- us/library/system.drawing.drawing2d.matrix.aspx(在 System.Drawing.dll 中)
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.matrix.aspx (in System.Drawing.dll)
好吧,我解决了第二个问题,尽管使用了相同的坐标,但文本仍然被移位。
事实证明,第一个 PDF 包含一些不可见的修剪空间,而第二个 PDF 则没有。 修剪空间不可见,因为视图空间是使用 PDF 创建器裁剪的,但看起来修剪空间仍然存在并计入坐标。
Okay, I solved the second problem with the text being displaced despite the same coordinates being used.
As it turned out, the first PDF included some non-visible trimming space, the second didn't. The trimming space isn't visible 'cause the view space was cropped using the PDF creator, but as it appears the trimming space was still there and counted for the coordinates.