我想在pdf文档上一行一行地写
我拥有的代码是在页面中央写入文本
我怎样才能一行一行地写?
// Create a new PDF document
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
// Create an empty page
PdfPage page = document.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormats.TopCenter);
最佳答案
与 new XRect(0, 0, page.Width, page.Height)
您指定将在何处绘制文本。
使用较小的矩形并逐行增加第二个值。
PDFsharp 包括几个示例:
http://pdfsharp.net/wiki/PDFsharpSamples.ashx
特别是检查文本布局。 PDFsharp 源包中包含的示例代码。
还可以查看 MigraDoc,因为它会自动添加分页符。
http://pdfsharp.net/wiki/MigraDocSamples.ashx
关于pdf - 在 PDF 上写行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23297223/