Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write lines on PDF

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);
like image 652
Ateeq Avatar asked Apr 25 '14 15:04

Ateeq


People also ask

Can you write with a pen on a PDF?

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.

Can you add grid lines to a PDF?

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.


1 Answers

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

like image 180
I liked the old Stack Overflow Avatar answered Sep 20 '22 15:09

I liked the old Stack Overflow