6

我想在 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);
4

1 回答 1

7

new XRect(0, 0, page.Width, page.Height)您指定将在何处绘制文本。
使用较小的矩形并逐行增加第二个值。

PDFsharp 包括几个例子:
http://pdfsharp.net/wiki/PDFsharpSamples.ashx
特别检查文本布局。PDFsharp 源包中包含的示例代码。

还可以查看 MigraDoc,因为它会自动添加分页符。
http://pdfsharp.net/wiki/MigraDocSamples.ashx

于 2014-04-26T06:12:10.023 回答