![]() |
|||||||||||||
|
How It Works? This library uses a particular approach to PDF creation. The most important object is the “pdfDocument” and it is the first object that should be created. This object represents the real PDF document that will be generated and it’s a kind of empty container. After the creation of the document, you have to create document’s pages. The “pdfPage” is the base pdf element. On this object you can add everything you want, it’s like a white paper you can write on. At this point I’ve to introduce a definition about pdf objects. I’ve divided objects in two main categories: real and abstract objects. PDF Real Objects Pdf real objects are all the elements that are directly written into the pdf code. These elements aren't accessible, but you can use they with page's methods (such as page.drawLine). These are basic elements : text, paragraph, line, rectangle, circle and image. The text object represents a normal string written on a pdf page. It has different parameters. Infact you can choose the font style, the font size, the position and the color. You can put a text object on a page with pdfPage.addText method, that put the object into the page's elements collection. The paragraph object represents a normal paragraph into a pdf page. It can be configured with different settings. A paragraph can be created in two ways : infact you can create your own paragrah using a class that implements the Ienumerable interface, or you can auto-generate your paragraph form a string and paragraph width. There are different settings that you can change : line height, font style, font size, paragraph alignment and font color. You can add your paragraph using the pdfPage.addParagraph method. The image object represents a image into a pdf page. When you put an image into a page you can choose the position and you can resize it. The image will be converted into a jpeg image, so the image stream can be stored directly into the document (this action is completely trasparent and It's done by the Image Object). You can create your images using the pdfPage.addImage method. The line object represents a line into a pdf page. You can draw lines on a page and you can modify some settings : line position(start and end position), line with, line style and line color. You can draw your lines using the pdfPage.drawLine method. The rectangle object represents a rectangle into a pdf page. You can draw rectangles on a page and you can choose : position(start and end position), border width, border style, border color, fill color. You can draw your rectangles using the pdfPage.drawRectangle method. The circle object represents a circle into a pdf page. You can draw circles on a page and you can choose : position(center position and ray size), border width, border style, border color, fill color. You can draw your circles using the pdfPage.drawCircle method. PDF ABSTRACT OBJECTS Pdf abstract objects are elements that can be created with a collection of real objects (for example, a table is composed by lines and texts). These elements are accessible and you can create an istance of these objects. They are composed elements: table, page marker and persisten page. The table object represents a table on a pdf page. You can create your own tables with lines, rectangle, texts and other real objects, or you can use the abstract table object. This object can help you during the process of creating tables with different settings. You have to create a new istance of the table object and add the columns to the table’s header(with the column’s alignment and column’s size). So the table object returns the row objects that you can fill with your data(note that the column data must be strings and when a string is longer then the size of a column, it will be truncated). You can also create a style for your header and for your rows (there is a row style and an alternate row style, such as the ASP.NET DataGrid object) and you can choose the cellpadding of your table. After you have finished the table’s creation process you can put your table on a page with the pdfPage.addTable method. The page marker object represents a label that shows the number of pages on each pdf’s page. You can create yourself your page marker, but you’ve to put it on all the pages. Otherwise, with page marker, these operations are done by the document object. You’ve to create a new istance of the pageMarker object and put it on the document, setting the pdfDocument.pageMarker property. You can set the position, font style, font size and font color of your marker. You can also choose the style of the marker, infact you can use an arabic numeration or a roman numeration. After that you can change the pattern of your page marker. The default is “Page #n# of #N#” where “#n#” is the acual page and “#N#” is the number of pages. With this pattern the result on the page its like “Page 1 of 12”. You can ,for example, change your pattern with this “#n# / #N#” and the result is “1 / 12”. Or you can use a pattern like “This is page #n#” and the result is “This is page 1”. The persisten page object represents a collection of persistent elements that are cloned on all document’s pages. It’s very helpfully when you have to implement ,for example, an header on all pages. So you can create a new persistent page object and you add all the elements you need. After that you put your persistent page on the document, setting the pdfDocument.persistenPage property. So the object document does all the work and during the creation of the document, it copies all the objects on each page. The bookmark object represents a bookmark element on the left side of the page. It allows to move inside your pdf document. The bookmark's structure is like a tree. You can add first level bookmars on your document and you can also add other bookmark nodes to an existing node(bookmark's child). When you create a new bookmark you have to set the page of your "link". After that you can choose a destination(see the pdfDestinationFactory) inside the page. |
||||||||||||