Pdf Elements |
Select.Pdf supports a large number of element types that can be added to the pdf documents it manages:
Text Element (PdfTextElement)
Image Element (PdfImageElement)
HTML Element (PdfHtmlElement)
Graphic elements: Circle Element (PdfCircleElement), Ellipse Element (PdfEllipseElement), Ellipse Slice Element (PdfEllipseSliceElement), Ellipse Arc Element (PdfEllipseArcElement), Line Element (PdfLineElement), Polygon Element (PdfPolygonElement), Rectangle Element (PdfRectangleElement), Bezier Curve Element (PdfBezierCurveElement)
Annotation Element (PdfAnnotationElement)
Sound Link Element (PdfSoundLinkElement)
File Attachment Element (PdfFileAttachmentElement)
External File Element (PdfExternalFileElement)
Internal Link Element (PdfInternalLinkElement)
External Link Element (PdfExternalLinkElement)
Digital Signature Element (PdfDigitalSignatureElement)
To add an element to a pdf document, at least one pdf page (instance of PdfPage) needs to be defined. To create a pdf page into a new document, the following code can be used:
// create a new pdf document PdfDocument doc = new PdfDocument(); // add a new page to the document PdfPage page = doc.AddPage();
Pdf elements are added to pdf pages using the Add(PdfPageElement) method of the PdfPage object. Add(PdfPageElement) returns a PdfRenderingResult object that contains information about the position where the pdf element was rendered.
The following code shows how to add a text element to a pdf page and how to retrieve the rendering results object:
// define a rendering result object PdfRenderingResult result; // create a new text element and add it to the page // Important: get the rendering result returned by Add() // into the PdfRenderingResult object PdfTextElement text = new PdfTextElement(0, 0, "Hello world!", font); result = page.Add(text);
The following sample code shows how to create a new PDF document using Select.Pdf and add several text elements to it, for each additional element using the finish position of the previous element, to introduce some space between the lines of text.
// create a new pdf document PdfDocument doc = new PdfDocument(); // add a new page to the document PdfPage page = doc.AddPage(); // create a new pdf font PdfFont font = doc.AddFont(PdfStandardFont.Helvetica); font.Size = 20; // define a rendering result object PdfRenderingResult result; // create a new text element and add it to the page // Important: get the rendering result returned by Add() // into the PdfRenderingResult object PdfTextElement text = new PdfTextElement(0, 0, "Hello world!", font); result = page.Add(text); // add 10 more text element, leaving 30pt between the text lines for (int i = 1; i <= 10; i++) { PdfTextElement elem = new PdfTextElement(0, result.PdfPageLastRectangle.Bottom + 30, "Text line " + i, font); result = page.Add(elem); } // save pdf document doc.Save(file); // close pdf document doc.Close();