I want to write line by line on a pdf document the code I have is writing the text in the center of the page how can I write line by line?
// 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);
You can write on a PDF like you would a printed document, making the stylus the perfect solution for reviewing, editing, and signing documents on the go.
Choose View > Show/Hide > Rulers & Grids > Rulers. Do one of the following: Drag down from the horizontal ruler to create a horizontal guide, or drag right from the vertical ruler to create a vertical guide.
With new XRect(0, 0, page.Width, page.Height)
you specify where text will be drawn.
Use a smaller rectangle and increase the second value from line to line.
PDFsharp includes several examples:
http://pdfsharp.net/wiki/PDFsharpSamples.ashx
Especially check Text Layout. Sample code included with the source package of PDFsharp.
Also check out MigraDoc as it adds pagebreaks automatically.
http://pdfsharp.net/wiki/MigraDocSamples.ashx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With