我用iText7替换PdfSharp,我不知道为什么当我使用相同的x和y坐标时,我会得到不同的结果。我在两者上都使用735
和520
,但它们在pdf文件的不同位置打印。任何帮助都将是伟大的。PdfSharp使用double
,iText7使用float
,但它们完全相同。
原点(0,0(位于左上角,坐标向右和向下增长。测量单位始终为点(1/72英寸(。http://www.pdfsharp.net/wiki/Graphics.ashx
PdfSharp
PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page);
dfSharp.Drawing.Layout.XTextFormatter tf = new XTextFormatter(gfx);
pnt = new XPoint(735, 520);
gfx.DrawString("Text Enter", font, XBrushes.White, pnt);
iText7
iText.Kernel.Geom.Rectangle rectangle = new iText.Kernel.Geom.Rectangle(735, 520, 100, 100);
Canvas canvas = new Canvas(pdfCanvas, rectangle);
Style normal = new Style();
PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
normal.SetFont(font).SetFontSize(34).SetFontColor(ColorConstants.WHITE);
Paragraph p = new Paragraph()
.Add(_versionNumber)
.SetFontSize(34)
.SetFontColor(ColorConstants.WHITE)
.SetFont(font);
段落。SetFixedPosition(8800200(将把你放在页面的左上边缘,200是宽度。Itext7 PDF坐标从左下角开始。(0,0(通常是文档的左下角。