Home

XMLPDF Manual

image

Contents

1. 480 750 24 1 Absolute Positioning Any block element such as a lt block gt lt table gt or lt show image gt eleme positioned at an absolute location on the page using the following attributes Attribute Description ax The absolute x location on the page in points of the top left corner of the block ay The absolute y location on the page in points of the top left corner of the block Using the following XML we can position the image at location 480 750 where the units are points at 72 points per inch and the bottom left corner of the page is location 0 0 and the top right is 595 841 so x 480 y 750 is in the top right quarter of the page lt show image image name ferret scale width 50 ax 480 ay 750 gt Absolutely positioned elements are outside the normal flow of the document and so are not paginated You are responsible for making sure they fit on the page 24 2 Relative Positioning Any block element such as a lt block gt lt table gt or lt show image gt element can be positioned relative to another block element using the following attributes Attribute Description TX The relative x location on the page in points of the top left corner of the block ry The relative y location on the page in points of the top left corner of the block relative to The name given to the block which we are relative to using the relative name attribute on that other blo
2. recordset related using System Data using System Data SqlClient public DataTable RetrieveRowsWithDataTable string CONNECTIONSTRING server local Integrated Security SSPI database pubs SqlConnection conn null try conn new SqlConnection CONNECTIONSTRING SqlCommand cmd new SqlCommand select from sales conn cmd CommandType CommandType Text SqlDataAdapter da new SqlDataAdapter cmd DataTable dt new DataTable sales da Fill dt return dt finally if conn null conn Close 22 4 2 Creating the PDF File The following code calls the RetrieveRowsWithDataTable method and creates the PDF file PDFDocument doc new PDFDocument DataTable reader RetrieveRowsWithDataTable doc addNamedObject sales_datatable reader doc generate testrecordset xml testrecordset pdf The source code for this article is in file testrecordset cs The file is called testrecordset cs_ you will need to rename it to testrecord cs The key thing in this code is the call to doc addNamedObject This associates a logical name sales_datatable with the recordset Within the template XML in file testrecordset xml this name is used in the lt foreach gt tag to tell XMLPDF which object to iterate over The full content of the XML template is www xmlpdf com xmlpdf user manual page 67 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data lt xml versio
3. 26 24 26 25 Summary of attributes Attribute Description field The field to insert into the document Current valid values are version to insert the current XMLPDF version and date to insert the date flags When field date this can be used to specifiy the date format This can be any value specified for the java text SimpleDateFormat class See examples below This element is replaced in the PDF file by the field specified Examples of date formatting are Field Flags Result date yyyy MM dd G at hh mm ss z 2003 05 29 G at 11 44 20 12 date EEE MMM d yy EEE May 29 03 date h mm a 11 44 a date bh o clock a zzzz 11 oclock a 12 00 date K mm a z K 44 a 12 lt link gt Summary of attributes Attribute Description url Specifies the URL this link points to This can be either a hyperlink such as http www xmlpdf com or a mailto link such as mailto support xmlpdf com The link element is used to insert a hyperlink into the PDF document When the user clicks on the link their browser will be launched and will go to the specified url Click on the www xmlpdf com link at the bottom left of this page to see how this works The link element contains text which appears in the document This text is independent of the url attribute For example the link at the bottom of this page is created with the following XML lt link url http www xmlpdf com gt
4. As each element is loaded from the document template XML the type of the element is compared with the names of all defined styles In the case of the example above any element of type lt block gt will automatically get the attributes shown on the style If the name attribute of the lt style gt element is a simple word the style applies to any element of the named type If the name starts with a as in name h1 it applies to any element of any type which has its class set to the same name without the For example the style lt style name code font name courier gt can be applied to a block element by giving the block the associated class as in lt block class code gt some code lt block gt xmlpdf user manual page 55 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 20 Document Security www xmlpdf com 20 1 20 2 20 3 CHAPTER 20 Document Security Passwords You can limit access to the PDF document by providing a password PDF supports two distinct passwords the user password and the owner password The user who knows only the user password has limited rights to print modify or paste from the document The owner who knows the owner password owns the document and can do anything to it If set the user password must be entered in Acrobat Reader in order to open the document Once open what the user can do is limited by the restrictions placed on the document when it was created
5. New Project x Project Types Templates E Ej pen f visual C Projects E Visual C Projects 3 Setup and Deployment Projects a l H E Other Projects ASP NET Web ASP NET Web Web Control Visual Studio Solutions Application Service Library a a G Console Windows Empty Project Application Service a project for creating a command line application Name ConsoleApplication1 Location D cs2 z Browse Project will be created at D cs2 ConsoleApplication1 More Cancel Help In the Templates box select Console Application enter TextXMLPDF in the Name text box and enter a suitable directory in the Location text box This should look like this xmlpdf user manual page 12 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 6 Visual Basic Example LIM x oe Project Types Templates E H 4 Visual Basic Projects Visual C Projects Visual C Projects Setup and Deployment Projects Other Projects ASP NET Web ASP NET Web Web Control Application Service Library Visual Studio Solutions aa ve Console Windows Empty Project Application Service fd a project for creating a command line application Name vbconsole Location d work 7 Browse Add to Solution Close Solution Project will be created at d work vbconsole More oa Cancel Help Press OK to create the project 3 Reference the XMLPDF DLL In the Solution
6. Project Types Templates ee Ea m visual C Projects E Visual C Projects Setup and Deployment Projects w Other Projects ASP NET Web ASP NET Web Web Control visual Studio Solutions Application Service Library a GG Console Windows Empty Project Application Service X a project for creating a command line application Name ConsoleApplication1 Location D cs2 X Browse Project will be created at D cs2 ConsoleApplication1 More Cancel Help xmlpdf user manual page 9 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 In the Templates box select Console Application enter TextXMLPDF in the Name text box and enter a suitable directory in the Location text box This www xmlpdf com should look like this LIM i x Project Types Templates visual Studio Solutions Service 42 Visual C Projects 7 A Visual C Projects m E Setup and Deployment Projects ASP NET Web ASP NET Web Web Control C Other Projects Application Service Library T m a Windows Empty Project a project for creating a command line application Name TestXMLPDF Location d work E Browse Project will be created at d work TestxMLPDF More ro Cancel Help Press OK to create the project 3 Reference the XMLPDF DLL 5 C Example In the Solution Explorer window right click on the References branch and select Add Reference This brings up
7. lt cell gt lt show image image name dol gt lt cell gt lt row gt lt table gt lt document gt This XML produces a PDF file like this B Adobe Acrobat Test0 pdf O Xx T Eile Edit Document Tools view Window Help x 1ofi1 gt MW 596x842p O S on An image can be displayed any number of times using a single image element and multiple show image elements A show image element can be used both inside a document element to display the image inline like a text block or inside a cell element to display the image inside a table www xmipdf com xmlpdf user manual page 50 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 18 Images 18 2 Image Size Images displayed within a table will be scaled to fit the cell width Images in the main body of the document can be resized using the scale width and scale height attributes The above example shows an image at its default size Here it has indent left 5cm and ident right 5cm so the image is scaled to fit the width available B Adobe Acrobat Test pdf BE cle git Document Tools view window Help la x gt S544 8 H N 5 2 BS PaE E n 4 BART omnem and here it has scale width 100 so the image is scaled and the aspect ratio is preserved alol xj 181 amp OQ 8 M4 NSO ae T ow o DAR 5 and with scale width 100 and scale height 200 so the im
8. lt student number 10101 name M Jones age 30 gt lt student number 20202 name K Jackson age 20 gt lt student number 30303 name Wilbur Fish age 40 gt lt students gt lt course gt lt course gt lt course gt lt coursedata gt We can expand on the previous looping example to add an inner loop which iterates over the students who are taking each course To list all the students by course we use the template coursestudents xml In addition to the lt foreach gt loop seen in the previous example this template contains the a nested lt foreach gt element to loop over the students like this lt foreach iterator course itr xpath coursedata course gt lt block gt Course code lt merge root course itr xpath code gt Name lt merge root course itr xpath name gt lt block gt lt foreach iterator student itr root course itr xpath students student gt lt block indent left 6cm gt Student Name lt merge root student itr xpath name gt lt block gt lt foreach gt lt foreach gt The inner lt foreach gt element specifies the root attribute root course itr This makes XMLPDF apply the xpath attribute based on the current node in the course itr iterator If the root attribute is not specified the XPath expression is applied from the root node in the data XML which does give you the ability to loop over another unrelated collection of records XMLPDE applies the
9. www xmlpdf com lt link gt lt merge gt Summary of attributes Attribute Description source element name Specifies the name of the element to be merged from the data XML This element is used to include an element from the data XML into the PDF document The value of the source element name attribute must match the name of a lt source element gt element in the data XML xmlpdf user manual page 89 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 26 26 27 26 28 26 29 The merge element is replaced completely by the contents of the source element element from the data XML The source element element can contain any amount of XML for instance the document XML might contain a table element and the header for the table and all of the rows might be merged from the data XML with a single merge element See Section 22 Merging Data for an example of merging data lt new page gt Summary of attributes Attribute Description next page number Specifies the number of the next page This is optional This element causes an immediate page break in the PDF document Setting the next page number attribute will change the page number of the following page This is used in this manual to make the second physical page be page number instead of 2 The total number of pages in the document retrieved by the forward reference element is also adjusted lt nex
10. It should only be called after one of the generate methods described above has been called XML Validation To use a DTD for validating the XML you must explictly enable validation for each document This is done by setting the ValidationType property on the document to one of the values in the System Xml ValidationType enumeration for example PDFDocument doc new PDFDocument doc ValidationType System Xml ValidationType DTD The default value is System Xml None in which case no validation is done Versions Pressing control D in the Acrobat Reader displays the Document Summary dialog box The Producer value indicates the version of XMLPDF used to create the PDF file This will be a release number such as 1 1 5 plus the letter J for the Java version of XMLPDF or M for the NET version License File Non evaluation versions of XMLPDF require a license file to run This file is distributed to all licensed users and must be placed in a location where XMLPDF can open the file For most applications placing the file in the directory from which the application is started is all that is required If the license file is not found by default to tell XMLPDF where the license file is located you can set a property on the xmlpdf licensing Generator object as shown here PDFDocument doc new PDFDocument xmlpdf licensing Generator LicenseFileLocation d xmlpdf testlic xmlpdf lic Where d xmlpdf testlic xmlpdf lic s
11. NET version 4 7 and above It is possible to merge image file names from the data XML using a nested lt file name gt element like this lt document gt lt image image name iml gt lt file name gt lt merge xpath data image name gt lt file name gt lt image gt lt show image image name im1 gt lt document gt In this example the image name attribute of the image element is set to the name attribute of the image element in the data XML xmlpdf user manual page 66 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data An example of data XML which would work with this template is lt data gt lt image name clouds jpg gt lt data gt 22 4 Integration with ADO NET This section describes how iterate over a NET DataTable object to insert values from database records into the PDF file A DataTable object represents data extracted from a database The DataTable is created using a SqlDataAdapter object XMLPDF is able to iterate over the DataTable using the lt foreach gt element and to extract individual fields from the DataTable using the lt merge gt merthod 22 4 1 Creating the DataTable The following code shows a method which creates and returns a DataTable The table returned is the sales table from the pubs database which is part of the SQL Server default installation using System using System Text using System 1I0 using System Diagnostics using System Collections
12. The lt span gt element pushes new values onto the stack and these become the current values until the lt span gt end element is encountered at which point the values used before the opening lt span gt are restored For example to print a sentence with only the word Hello in bold using Helvetica the document would look like this lt document font name helvetica font size 12 gt lt block gt For example to print a sentence with only the word lt span font name helvetica bold gt Hello lt span gt in bold using Helvetica the document would look like this lt block gt lt document gt This would result in the following output For example to print a sentence with only the word Hello in bold using Helvetica the document would look like this www xmlpdf com xmlpdf user manual page 22 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 11 Fonts www xmlpdf com 11 3 11 4 Line height or leading The leading is the vertical distance between the baselines of adjacent lines of text The leading can be set with the leading attribute The leading is always defined using points without any units specified so leading 15 selects a leading of 15 points Setting the leading to less than the font size will cause the lines of text to overlap so this is generally not a useful thing to do The leading can also be set using the font size attribute This is done by separating the font size and the leading values with
13. These restictions are described below The user password is set using the user password attribute on the lt document gt element If set the owner password can be entered by the user to perform functions which are restricted such as printing or modifying the document The owner password is set using the owner password attribute on the lt document gt element If both passwords are set and are different then when opening the document in Acrobat Reader the user will be prompted for a password At this point the user can enter the user password and get limited access to the document or enter the owner password and get full access to the document If both passwords are set and are identical then when opening the document in Acrobat Reader the user will be prompted for a password At this point the user can enter the password and get full access to the document because they have entered the owner password If only the owner password is set then a password is not required to open the document with restrictions applied The owner password can be used after opening to bypass the restrictions set when the document was created If only the user password is set then that password is required to open the document but all restrictions can be bypassed because no password is required to become the owner of the document Restrictions To prevent users printing the document set the deny print attribute to true on the document element To prevent u
14. When using approach a the special characters should be replaced with the values from this table Character Name Use amp ampersand amp amp single quote amp apos double quote amp quot lt less than amp lt gt greater than amp gt For more information on XML refer to http www w3 org row 1998 REC xml 19980210 xmlpdf user manual page 17 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 9 XML Characters and Entities www xmlpdf com 9 2 Using XML Entities This section describes how to use XML entities XML entities can be defined in the DOCTYPE declaration at the start of the XML template file This example defines two entities deg which has a Unicode value of 176 and euro which has a Unicode value of 8364 being the symbols for degree and euro lt xml version 1 0 encoding utf 8 gt lt DOCTYPE document lt ENTITY deg amp 176 gt lt ENTITY euro amp 8364 gt lt ENTITY nbsp amp 160 gt gt lt document gt These entities can then be placed in the template XML like this lt block gt The degree symbol is amp deg lt block gt which results in this output The degree symbol is Note that this only works if the font you are using actually contains the symbol you wish to display For instance if the current font is zapfdingbats which does not have the degree symbol you will see a different character like this lt block gt The degree symbol is lt sp
15. number The number of boxes number down The number of rows of boxes The boxes element is used to display one or more square boxes as typically found on a form which is designed to be completed by a person For example this is produced with this XML lt graphic gt lt boxes box width 12 box height 12 number 8 line width 1 gt lt graphic gt Using XMLPDF you can insert text into the boxes by placing it in the lt boxes gt element like this lt graphic gt lt boxes box width 12 box height 12 number 22 line width 1 gt THIS IS IN THE BOXES lt boxes gt lt graphic gt This produces this output THIS I S IN THE BOXES Multiple rows of boxes can be created using the number down attribute and filled by using lt br gt elements to split the lines like this xmlpdf user manual page 77 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference lt graphic gt lt boxes box width 12 box height 12 number 30 line width 1 number down 2 gt THIS IS IN LINE ONE lt br gt THIS IS IN LINE TWO lt boxes gt lt graphic gt This produces this output THIS I S IN LINE THIS I S IN LINE www xmlpdf com xmlpdf user manual page 78 of 101 XMLPDF 5 5 7 Programmers Guide www xmlpdf com 26 6 lt block gt November 2006 26 Reference Summary of attributes Attribute align Description Specifies the text alignment to use for this block This specifies
16. 90 lt page number gt 91 lt restore gt 91 lt row gt 92 lt sequence get gt 93 lt segment gt 93 lt show image gt 94 lt set gt 96 lt space gt 96 lt span gt 96 lt style gt 97 lt table gt 99 lt watermark gt lt xref gt 101 100 wwwxmlpdf com XMLPDF 5 5 7 Programmers Guide November 2006 1 Introduction 1 1 1 2 1 3 1 4 1 5 www xmlpdf com CHAPTER 1 Introduction This is the user manual for the XMLPDF library The XMLPDF library creates PDF documents dynamically from Java and NET programming environments Why create PDF files Industry standard Portable Document Format PDF files provide a convenient way to distribute documents and forms PDF files are platform independent so someone viewing your document will see exactly the same thing on different operating systems such as Windows and Linux PDF documents provide precise control over formatting and alignment and produce the same output on all printers Most web browsers support PDF files through integration with Adobe Acrobat With XMLPDF you can create PDF files dynamically and stream them directly to the browser from your application without requiring they be saved to disk Why use PDF instead of HTML PDF files are used instead of HTML for the following reasons Consistent output When a user prints a PDF document they get what they expect When they print an HTML page what they get depends on which browser version they ar
17. Example using System using xmlpdf public class Create public static void main string args PDFDocument doc new PDFDocument doc generate args 0 args 1 5 Compile Select Build Build Solution from the menu to compile the project 6 Run Either configure the command line arguments using the Project Properties dialog or execute the program from the command line like this testxmlpdf helloworld xml helloworld pdf This will create the file helloworld pdf www xmlpdf com xmlpdf user manual page 11 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 6 Visual Basic Example www xmlpdf com CHAPTER 6 Visual Basic Example A simple VB program for calling the XMLPDF library to create the PDF file looks like this Imports System Imports xmlpdf Module Modulel Sub Main Dim doc As New PDFDocument Dim args As String Command Split ToCharArray doc generate args 0 args 1 End Sub End Module This program takes as command line arguments two file names first the name of the XML file and then the name of the PDF file This program is executed with a command such as Create HelloWorld xml HelloWorld pdf Assuming the system is installed correctly this will create the file HelloWorld pdf The steps involved in creating the above program are shown here 1 Start Visual Studio NET 2 Create a new project Select File New Project from the menu to bring up the New Project dialog
18. Explorer window right click on the References branch and select Add Reference This brings up the Add Reference dialog Add Reference J xj NET com Projects Program Files Microsoft N CustomMarshalers 1 0 3300 0 D WINNTX Microsoft NET Fr envdte 7 0 3300 0 D WINNTX Microsoft NET Fr extensibility 7 0 3300 0 d Program Files Microsoft Yis lEExecRemote 1 0 3300 0 D WINNTX Microsoft NET Fr TEHost 1 0 3300 0 D WINNTX Microsoft NET Fr TIEHost 1 0 3300 0 D WINNTX Microsoft NET Fr ISymWrapper 1 0 3300 0 D WINNTX Microsoft NET Fr Managed C Compiler 7 0 3300 0 D WINNTX Microsoft NET Fr Microsoft Visual Basic NET Ru 7 0 3300 0 D WINNTX Microsoft NET Fr Micrnsoft 1Scrint 7 0 3300 0 Di WINNTX Microasoft NFTIFr B Selected Components Component Name Type Source Remove OK Cancel Help Click on Browse and navigate to the xmlpdf dll Click OK The Solution Explorer should now show a reference from the new project to the XMLPDF DLL like this alala we Solution TestXMLPDF 1 project E Al TestxMLPDF 2 System System Data 2 System XML xmipdf l App ico E AssemblyInfo cs class1 cs 4 Add the Code Paste the following code into the Module1 vb file which was created when the project was created Replace all of the code in the file www xmlpdf com xmlpdf user manual page 13 of 101 XMLPDF 5 5 7 Programmers Guide Novembe
19. Logger getLogger addHandler new TraceHandler When running in the Visual Studio IDE messages will be logged to the Output window and when running executables messages will be written to the output debug stream where they can be read using a utility like Debug View Logging to Multiple Destinations Errors can be logged to any number of handlers The following example logs to a file called xmlpdf log and to a memory stream and to the console Logging to the console is done by not removing the default handler with a call to clearHandlers using System using System IO using xmlpdf using xmlpdf logging public class Create static void Main string args MemoryStream ms new MemoryStream Logger getLogger addHandler new StreamHandler ms addHandler new FileHandler xmlpdf log xmlpdf user manual page 59 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data www xmlpdf com 22 1 22 2 CHAPTER 22 Merging Data Basics XMLPDF is designed to allow creation of a document template in XML and then generation of PDF files based on merging data into the template This is designed to be done on a web or application server which serves dynamically created PDF files to a browser Within the document XML use the lt merge gt element and set the source element name attribute of this element to the name of an element in the data XML Whatever is in the named eleme
20. a slash so to use font size 15 and leading 18 throughout a document you do this lt document font name helvetica font size 15 18 gt lt block gt Hello World lt block gt lt document gt The leading defaults to the font size plus 2 points TrueType fonts Adobe Acrobat and the PDF format support TrueType fonts which are fonts provided as separate font files In a Windows NT environment TrueType fonts are in the directory winnt fonts Each font is held in a separate font file with a name like Arial ttf You can view fonts by using Control Panel Fonts and opening a font file to see what is in it Note that different styles of a font i e bold bold italic etc are different font files and must be referenced as separate fonts Adobe recommend that TrueType fonts be embedded The following XML will produce a document printed in 12 point Arial lt document gt lt fonts gt lt font font name arial font file arial ttf type truetype gt lt fonts gt lt block font name arial font size 12 gt Hello World lt block gt lt document gt To use a TrueType font you have to tell XMLPDF about the font before you can use it This is done by placing a lt font gt element into the lt fonts gt element near the start of the document xmlpdf user manual page 23 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 11 Fonts www xmlpdf com Attributes of the lt font gt element are Attribute Des
21. com xmlpdf user manual page 68 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 23 Links CHAPTER 23 Links 23 1 Basics XMLPDF supports URL s in the PDF document so that when the user clicks on the link their browser is started and the linked web page is retrieved For example click on www xmlpdf com to go to the XMLPDF web site A sample document with one link looks like this lt document gt lt style name link decoration underline gt lt block gt The link is lt link url http www sun com gt The Sun Site lt link gt lt block gt lt document gt Note the use of the style named link which is automatically applied to all link elements and makes them underlined The example creates a link which looks like this The link is The Sun Site The attributes of the lt link gt element are Attribute Description url This indicates which web site or file will be displayed when the user clicks on the link Links to web pages should start with http as shown in the example above Mailto links are implemented like this lt link url mailto test xmlpdf com gt test xmlpdf com lt link gt url show border Setting url show border true will draw a box around the URL which is useful for showing where the hit region is when you are developing the document A link with a border looks like this lt document gt lt style name link decoration underline gt lt block gt T
22. condition either true or false is defined in the data XML Each condition is defined in a lt condition gt element within a single lt conditions gt element like this xmlpdf user manual page 60 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data www xmlpdf com 22 3 22 3 1 lt data gt lt conditions gt lt condition name cust known value false gt lt conditions gt lt source element name cust name gt john smith lt source element gt lt source element name cust age gt 123 lt source element gt lt data gt Each condition must have a unique name and a value which must be true or false Within the document XML you can determine if a part of the document will be included by placing it inside a lt if gt element as shown here lt document gt lt block gt Dear lt if condition cust known gt lt merge source element name cust name gt lt if gt lt ifnot condition cust known gt Sir Madam lt ifnot gt lt block gt lt document gt This produces output like this Dear Sir Madam Changing the value of the cust known condition in the data XML so the data XML looks like this lt data gt lt conditions gt lt condition name cust known value true gt lt conditions gt lt source element name cust name gt john smith lt source element gt lt source element name cust age gt 123 lt source element gt lt data gt produces outpu
23. follows lt auto sequence inc level 1 name Introduction gt lt auto sequence inc level 2 name Overview gt This creates a hierarchy like this 1 Introduction 1 1 Overview Having set the title for the current level of the outline we can retrieve it and insert it into the document using the auto sequence get name element Specifying the level attribute on the element determines which heading is inserted into document For instance the element lt auto sequence get name level 1 gt would insert the string Introduction into the document If we change the level to 2 as in lt auto sequence get name level 2 gt we would insert the string Overview into the document The auto sequence get name element has an attribute called uid which is used to specify a unique identifier for this heading when it appears in the document This uid can then be used to create a cross reference in the document using the xref element See Section 26 42 lt xref gt lt auto sequence inc gt Summary of attributes Attribute Description level The level of the hierarchy for which to set the name and increment the counter name The title to be given to this level in the hierarchy XMLPDF automatically maintains a document outline which is used to number headings and subheadings and to generate the outline which Acrobat displays on the left side of the screen Use of this feature is optional Each heading in the do
24. merge gt element can be formatted before insertion into the PDF This is done using the format and format type attributes Within XMLPDF formatting is done using the StringBuilder AppendFormat method The value returned by the XPath expression is converted to the type specified by the format type attribute which defaults to string and then passed to the AppendFormat method The format attribute specifies the formatting of the values returned from the XPath expression This follows the standard NET formatting rules The valid values of the format type attribute are string date double integer Note that NET formatting requires that the format match the type Specifying a numeric format like with a string type will not automatically convert the string to a number and so will not work Examples Date Formatting Given a date such as 2003 01 12T14 07 41 277 we can format it as dd mm yyyy like this lt merge xpath coursedata term start format 0 dd mm yyyy format type date gt Number Formatting Given a number such as 100 20 can format it to 5 decimal places like this lt merge xpath coursedata term start format O 0 format type double gt Hexadecimal Formatting Given a number such as 34 can format it as hex like this lt merge xpath coursedata integer format 0x 0 x format type integer gt Merging Image File Names This is currently only in
25. new PDFDocument doc setAttributeTranslation Sbase This will make the final path to the font file fonts arial ttf and XMLPDF will try to load the font from this directory relative to your current directory When running the same template in a ASP NET server set the base variable to the server s virtual directory like this PDFDocument doc new PDFDocument doc setAttributeTranslation base Server MapPath This will make the final path to the font file something like c inetpub wwwroot webapplication1 fonts arial ttf and XMLPDF will try to load the font from this directory xmlpdf user manual page 16 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 9 XML Characters and Entities 9 1 www xmlpdf com CHAPTER 9 XML Characters and Entities Escaping XML Characters This section describes how to use special XML characters in XML In order to use some characters in XML you need to escape them so as not to confuse the XML parser These characters are amp ampersand single quote double quote lt less than gt greater than There are two appraches to escaping text in XML either a replace each special character with its entity value or b enclose all text in a CDATA section Given the text string Smith amp Jones we can either a replace just the ampersand to get Smith amp amp Jones b enclose the whole string in a CDATA to get lt I CDATA Smith amp Jones gt
26. of SVG these files are located in the build subdirectory and are called Sharp VectorCss dll Sharp VectorObjectModel dll Sharp VectorRenderingEngine dll SharpVectorScripting dll Sharp VectorXml dll SharpZipLib dll If you have problems getting SVG integration to work try setting the logging level to Level INFO see previous chapters for more information on error handling You should see messages logged similar to this when things go wrong info Loading image file from file butterfly svg info Failed to load optional assembly from d xmlpdf cs2 testit bin release SharpVectorCss dll info Optional SVG support is disabled Or like this when things go well info Loading image file from file butterfly svg info Loaded optional SVG assemblies ok These messages will tell you where XMLPDF is looking for the SVG DLLs Set the environment variable SVGDIR to the directory which contains the SVG files and XMLPDF will load them from this directory For instance if you have SVG installed in d SharpVectorGraphics then the DLLs will be in d SharpVectorGraphics build and you can set SVGDIR like this set SVGDIR d SharpVectorGraphics build SVG images are used in the same manner as other types of images in XMLPDF The image is defined using an lt image gt element and then placed on the page using a lt show image gt element For example to create a PDF file containing the image butterfly svg you create an XML template file some
27. of contents itself gt lt block indent left 2 5cm font name helvetica font size 24 align center gt Contents lt block gt lt create a table gt lt table widths 5 10 width 85 block align center gt lt iterate over the top level elements gt lt foreach list contents iterator itr gt lt create a row for each element gt lt row padding top 12 padding bottom 6 destination page itr page gt lt a cell for the element number gt lt cell gt lt merge method itr number gt lt cell gt lt a cell for the element text and page number gt lt cell font size 10 colspan 2 gt lt span font name helvetica bold gt lt merge method itr text gt lt span gt lt merge method itr page gt lt cell gt lt row gt lt iterate over the child elements gt lt foreach list itr contents iterator level2 gt lt row destination page level2 page gt lt cell gt lt cell gt lt merge method level2 number gt lt cell gt lt cell gt lt merge method level2 text gt lt merge method level2 page gt lt cell gt lt row gt lt foreach gt lt foreach gt lt table gt lt toc gt The XML above will create a two level table of contents If we wanted another levels we could have another nested foreach element contained within the second foreach loop 25 2 Table Of Contents Page Layout The toc element can contain page header
28. preceding XML sample to preserve the indentation Leading Leading is the vertical distance between the baselines of adjacent lines of text The leading can be set with the leading attribute The leading is always defined using points without any units specified so leading 15 selects a leading of 15 points Setting the leading to less than the font size will cause the lines of text to overlap so this is not generally a useful thing to do The leading can also be set using the font size attribute This is done by separating the font size and the leading values with a slash so to use font size 15 and leading 18 throughout a document you do this lt document font name helvetica font size 15 18 gt lt block gt Hello World lt block gt lt document gt Rise This is used to display subscript and superscript text The word SUP amp SCPE has rise 5 set The word has rise 5 set subscript Non Breaking Space As with HTML a non breaking space character ASCII code 160 can be inserted into XML to create a space where normal XML processing would remove it This is useful to create two spaces together The syntax for this is lt document font name helvetica font size 15 18 gt lt block gt Hello amp 160 amp 160 World lt block gt lt document gt That example puts two spaces between the words Hello and World like this Hello World Changing Text Formatting The lt span gt element can be use
29. the Add Reference dialog add reference Browse Select NET com Projects component Name __ Version __ Path__ a i ji f 1 0 7 0 3300 0 y a Program Files Microsoft N CustomMarshalers 1 0 3300 0 D WINNTX Microsoft NET Fr envdte 7 0 3300 0 D WINNTX MicrosoFt NET Fr extensibility 7 0 3300 0 d Program Files Microsoft Vis TEExecRemote 1 0 3300 0 D WINNTX Microsoft NET Fr TEHost 1 0 3300 0 D WINNTX MicrosoFt NET Fr TIEHost 1 0 3300 0 D WINNTX Microsoft NET Fr ISymWrapper 1 0 3300 0 D WINNTX Microsoft NET Fr Managed C Compiler 7 0 3300 0 D WINNTS Microsoft NET Fr Microsoft Visual Basic NET Ru 7 0 3300 0 D WINNTX Microsoft NET Fr Micrnsnft 1Scrint 7 0 3300 01 DA WINNT Micrasoft MFTIFr z Selected Components Component Name type sowe Remove Click on Browse and navigate to the xmlpdf dll Click OK x The Solution Explorer should now show a reference from the new project to the XMLPDF DLL like this Solution Explorer el a os Solution TestXMLPDF 1 project E TestxMLPDF System Data System XML xmipdf El App ico fey AssemblyInfo cs E Classt cs 4 Add the Code Paste the following code into the Classl cs file which was created when the project was created Replace all of the code in the file xmlpdf user manual page 10 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 5 C
30. then be displayed at a given point by using a show image element with the name attribute corresponding to the name given on the image element An image can be displayed any number of times using a single image element and multiple show image elements A show image element can be used both inside a document element to display the image inline like a text block or inside a cell element to display the image inside a table xmlpdf user manual page 94 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference Images displayed within a table will be scaled to fit the cell width Images in the main body of the document can be resized using the scale width and scale height attributes The following example shows an image at its default size B Adobe Acrobat Test0 pdf Eile Edit Document Tools view Window Help Q B Blid gt I BQSNUAEaT fe D OWS and with indent left 5cm and ident right 5cm so the image is scaled to fit the width available Bi Adobe Acrobat Test0 pdf ojx ee Edt Document Toos viw Window Help Zax AEE CELT EINER AA CATT Bl BANHART s onime and with scale width 100 so the image is scaled and the aspect ratio is preserved bat Testo pdr mi Poe cok boomen Tok yon areon ep ixi pensg a aa m 4 N B 7 2 8 Oa t E 4 O ijesnaar om e0 oma and with scale width 100 and scale he
31. way in which Acrobat will open the document With page mode bookmarks Acrobat will display the bookmarks window on the left of the document With page mode thumbs Acrobat will display the thumbnails window on the left of the document With page mode fullscreen Acrobat will open the document in full screen mode with no toolbars or menus page size Sets the size of the page for the whole document See Section 10 2 Page sizes for details on page sizes Fonts element lt fonts gt lt font font name arial font file d winntx fonts arial ttf type truetype gt lt fonts gt The lt fonts gt element is used to hold lt font gt elements for any TrueType fonts used in the document If no TrueType fonts are used the fonts element is not required See Section 11 Fonts for a description of these elements Images element The lt images gt element is used to hold lt images gt elements for any images PNG or JPEG files used in the document If no images are used the images is not required See Section 18 Images for a description of these elements xmlpdf user manual page 26 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 12 Document Structure 12 6 Content elements After the font and image elements the document content appears The content of the document is included in lt table gt lt block gt and lt show image gt elements Each of these elements can appear any number of times in any order Thes
32. which is 10cm wide by 20 cm high you would do this lt document height 20cm width 10cm gt lt block gt Hello World lt block gt lt document gt Page orientation Page orientation is set using the orientation attribute on the lt document gt element By default the orientation is portrait An example of a landscape document is lt document orientation landscape gt lt block gt Hello World lt block gt lt document gt The page orientation can be changed within the document using the lt next page gt element See Section 26 27 lt next page gt Margins Page margins are set using the following attributes on the lt document gt element margin left margin right margin top margin bottom xmlpdf user manual page 20 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 10 Units of Measurement www xmlpdf com 10 6 Each of these sets the amount of space between the edge of the page and the edge of the content All of these attributes have a default value of 36 points or 1 2 an inch The page margins can be changed within the document using the lt next page gt element See Section 26 27 lt next page gt Default values The default values for a document are Attribute Default Value align left font name times font size 12 14 kern true margin left 36 margin right 36 margin top 36 margin bottom 36 page size A4 xmlpdf user manual page 21 of 101 XMLPDF 5
33. width top border width bottom border width left border width right www xmlpdf com Sets the widths of table row and cell borders xmlpdf user manual page 28 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 12 Document Structure www xmlpdf com 12 6 3 12 6 4 Attribute Description border color all Sets the color of table row and cell borders See border color inner Section 15 Colors border color outer border color top border color bottom border color left border color right padding all Sets cell padding Padding is the amount of space padding inner between the border of a cell and the text or image in it padding outer padding top padding bottom padding left padding right Show image element The lt show image gt element is used to place an image in the PDF document This places the image into the flow of the document in a way similar to a table or block element Images can also be placed in tables using the lt show image gt element inside a cell element This is described in section Section 18 Images All of the attributes described in the preceding section on the block element can also be applied to the table element The following additional elements affect the way the image appears These are explained in detail in section Section 18 Images Attribute Description image name Specifies which image to display The image must have previously been defined using an image e
34. you change the page number using the next page number attribute and then show the total pages in the document in the footer as is done in this manual the total pages figure will still be correct Dynamic Attributes Its is possible to programatically change the value of XML attributes at runtime Assuming you want to change the value of the orientation attribute at runtime a change your document template xml to prefix the orientation value with a character like this lt document orientation Sorientation margin left lcm margin right lcm font name helvetica font size 9 gt b in the calling program do this to set the value of the orientation variable assuming PDFDocument doc new PDFDocument doc setAttributeTranslation Sorientation landscape or doc setAttributeTranslation Sorientation portrait When the PDF is produced if the program finds an attribute with a value starting with it looks up the list of translations defined with setAttributeTranslation calls and changes the value to the one you have defined xmlpdf user manual page 31 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 13 Text Formatting CHAPTER 13 Text Formatting 13 1 Basics Text is inserted into a document using the lt block gt element as shown here lt document gt lt fonts gt lt font font name arial font file arial ttf type truetype gt lt fonts gt lt block font name ar
35. 1 XMLPDF 5 5 7 Programmers Guide November 2006 15 Colors www xmlpdf com 15 1 15 2 15 3 15 4 CHAPTER 15 Colors Basics By default text appears as black print on a white background The color of text can be changed with the text color attribute The background color of table cells can be changed with the fill color attribute The value of the text color and fill color attribute is either a predefined color or a custom hexadecimal value Predefined Colors The predefined colors are white lightgray gray darkgray black red pink orange yellow green magenta cyan blue For example to make a block or word appear blue you would set text color blue as in lt block text color blue gt this appears in blue lt block gt which produces this this appears in blue Custom Colors Colors can be defined using the same notation as HTML where a color is set to a value starting with a character as in fill color FF3344 The hex value consists of three parts Each two character pair represents a hex value from 0 to 255 The first pair specifies the value for red the next pair for green and the last pair for blue For example this lt block text color 008899 gt this appears in blue lt block gt which produces this this appears in a strange light green color CMYK Colors CMYK colors are defined using four values one each for the C M Y and K components of the color For CMYK colors to
36. 2006 26 Reference www xmlpdf com 26 30 26 31 The page header can be changed at any point by putting another page header element in the XML The page header element has the same attributes and contents as a lt table gt element See Section 26 40 lt table gt for more details In addition to the normal table attributes the first page and last page attributes can also be used to limit the range of pages on which this page header will be displayed lt page number gt This element is used to insert the current page number into the document For instance the following XML lt block gt This is page lt page number gt lt block gt Produces this output This is page 91 This element has no attributes lt restore gt This element is used to restore the values of text formatting attributes such as font size and font name which have been changed using a lt set gt element See Section 11 2 Changing fonts for an example of this This element has no attributes xmlpdf user manual page 91 of 101 XMLPDF 5 5 7 Programmers Guide 26 32 lt row gt www xmlpdf com November 2006 26 Reference Summary of attributes Attribute align Description Specifies the text alignment for text which appears inside cells which are in this row See Section 13 2 Horizontal alignment background gray Specifies gray shading which appears in the background all cells in the row This is expressed as a per
37. 5 7 Programmers Guide November 2006 11 Fonts CHAPTER 11 Fonts 11 1 Basics Adobe Acrobat and the PDF format support a set of fonts called Type 1 Fonts The names of these fonts as used by XMLPDF are courier helvetica times symbol courier bold helvetica bold times bold zapfdingbats courier italic helvetica italic times italic courier bold italic helvetica bold italic times bold italic These fonts or suitable substitution fonts are guaranteed to be available to the viewer application on all platforms Although technically the sloped versions of the Times font is italic and the Helvetica and Courier fonts are oblique for simplicity they are all named ending with italic in XMLPDF The characters used in the font technically the glyphs are independent of the font size A specific size and font face are defined by using both the font name and font size attributes The following XML will produce a document printed in 12 point Helvetica lt document font name helvetica font size 12 gt lt block gt Hello World lt block gt lt document gt Font settings are inherited in that a single font name and font size can be defined for an element such as a table and all objects contained within that table will be displayed using that font 11 2 Changing fonts To change the font face or font size used during a block of text use the lt span gt element Conceptually the current text characteristics are stored on a stack
38. 6 S 7 T 8 U 9 The following example shows splitting a table which contains two nested tables one a normal layout table and the other a newspaper layout table Normal Table Newspaper Table A B A E C D B F E F C G G H D H www xmlpdf com xmlpdf user manual page 45 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables Normal Table Newspaper Table I J I W K L J X M N K Y O P L Z Q R M 0 S T N 1 U V O 2 W X P 3 Y Z Q 4 0 1 R 5 2 3 S 6 4 5 T 7 6 7 U 8 8 9 V 9 See http www xmlpdf com articles newspaper html for an example 16 11 Other attributes vertical align top bottom middle center We can set the vertical alignment of cell contents using the vertical align attribute Valid values for this are top bottom middle and center of which the last two are the same If we add vertical alignment to the previous example we get lt table border width all 1 indent left 3cm indent right 3cm padding all 2 gt lt row vertical align middle gt lt cell gt one lt cell gt lt cell gt this cell has many words so is higher than the cell on the left lt cell gt lt xrow gt lt table gt And the resulting table looks like this www xmipdf com xmlpdf user manual page 46 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables this cell has many words so one is higher than the cell on the left www xmlpdf com xmlpdf user manual page 47 of 101 XMLPDF 5 5 7 Progra
39. ContentType sets the MIME type of the content so the browser knows to start Acrobat to handle the returned file The PDF is generated into a System IO MemoryStream object on the server This is done so that we can obtain the number of bytes to be returned to the client This is used when we call Response AddHeader to set the length of the content Response BinaryWrite copies the PDF bytes to the client browser While it is possible to pass the Response OutputStream object directly to the generate call as the second parameter this is not reliable when the PDF file size is very small xmlpdf user manual page 15 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 8 ASP NET Virtual Directories www xmlpdf com CHAPTER 8 ASP NET Virtual Directories lt font gt and lt image gt elements have a directory attribute which enables you to define the paths to your font and image files as relative paths so that the same XML template files will work both standalone and when running in an ASP NET server To use relative directories define the directory attribute on a font or image element like this lt font file name fonts arial ttf directory base gt When the XML is parsed to create the PDF file the value of the attribute directory base will be translated as described in Section 12 9 Dynamic Attributes When using this template outside an ASP NET server set the base variable to like this PDFDocument doc
40. World this is XMLPDF Any attribute which applies to text can be specified on the set element lt Sspace gt This element has no attributes or content This element is used to insert a space character into the PDF document where normal XML processing might remove the space See Space Handling for a discussion of space handling lt span gt Any attribute which can be applied to text can be used with this element xmlpdf user manual page 96 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 39 This element is used to change the formatting of text within a block or cell element The change specified is applied to all text contained within span element Given the following XML lt document font name helvetica font size 12 gt lt block gt Hello World this is XMLPDF lt block gt lt document gt We can change the word World to a courier by enclosing it in a span element as shown here lt document font name helvetica font size 12 gt lt block gt Hello lt span font name courier gt World lt span gt this is XMLPDF lt block gt lt document gt This changes the output from this Hello World this is XMLPDF to this Hello World this is XMLPDF Any attribute which applies to text can be specified on the set element Span elements can be nested inside other span elements lt style gt Summary of attributes Attribute Description name Specifies the name o
41. XMLPDF Library NET Programmers Guide Version 5 5 7 16 November 2006 Produced with XMLPDF 5 5 7M XMLPDF 5 5 7 Programmers Guide November 2006 Contents Introduction 1 1 1 Why create PDF files 1 1 2 Why use PDF instead of HTML 1 1 3 Development Environments 1 1 4 Do I need to know about the PDF file format 1 1 5 About this manual 1 Features 2 2 1 Document templates 2 2 2 Text Formatting 2 2 3 Fonts 2 2 4 Images 2 2 5 Pagination 3 2 6 Tables 3 2 7 Merging Data 3 2 8 Styles 3 2 9 Links 3 2 10 Sequences 3 Installation 4 Usage 5 4 1 Introduction 5 4 2 Hello world XML file 5 4 3 API 5 44 XML Validation 7 4 5 Versions 7 4 6 License File 7 C Example 9 5 1 C Code 9 5 2 Step by Step 9 Visual Basic Example 12 ASP NET Example 15 ASP NET Virtual Directories 16 XML Characters and Entities 17 9 1 Escaping XML Characters 17 9 2 Using XML Entities 18 Units of Measurement 19 10 1 Units 19 10 2 Page sizes 20 10 3 Custom page sizes 20 10 4 Page orientation 20 10 5 Margins 20 wwwxmlpdf com XMLPDF 5 5 7 Programmers Guide 10 6 Default values 21 11 Fonts 22 11 1 Basics 22 11 2 Changing fonts 22 11 3 Line height or leading 23 11 4 TrueType fonts 23 11 5 Unicode fonts 24 12 Document Structure 25 12 1 Basics 25 12 2 XML encoding 25 12 3 Document element 26 12 4 Fonts element 26 12 5 Images element 26 12 6 Content elements 27 12 7 Formatting elements 31 12 8 New page
42. XMLPDF applies this XPath expression to the data XML and returns the single value A Stone which is inserted into the PDF file like coursetutor pdf Looping XMLPDF can iterate over a group of XML nodes using the lt foreach gt element The xpath attribute of the lt foreach gt element should specify an XPath expression which returns a list of one or more nodes The coursedata xml file specifies the data for two courses like this xmlpdf user manual page 62 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data 22 3 4 www xmlpdf com lt coursedata gt lt course gt lt code gt COMP 101 lt code gt lt name gt Introduction to Computer Science lt name gt lt course gt lt course gt lt code gt WELL 401 lt code gt lt name gt Advanced Welding lt name gt lt course gt lt coursedata gt The lt foreach gt element has these attributes The iterator attribute specifies a unique identifier which is then used by lt merge gt elements within the lt foreach gt element lt merge gt elements within the lt foreach gt element can optionally specify the name of an iterator to be the root node from which the xpath value of the lt merge gt element is applied To list all the courses we use the template courselist xml This template contains the following elements a A lt foreach gt element to loop over the courses like this lt foreach iterator course itr xpath coursedata course gt l
43. XPath expression specified on the outer lt foreach gt element to get a list of course XML nodes from the data XML Then the XPath expression from the inner lt foreach gt is evaluated to get a list of students for that course This creates coursestudents pdf 22 3 5 Using Selection with lt foreach gt It is possible to select a subset of the nodes in an XML element using the XPath expression on the lt foreach gt element The coursedata xml file specifies a list of courses and for each course specifies a list of students taking the course like this lt coursedata gt lt course gt lt code gt COMP 101 lt code gt lt name gt Introduction to Computer Science lt name gt lt students gt lt student number 10101 name M Jones age 30 gt lt student number 20202 name K Jackson age 20 gt lt student number 30303 name Wilbur Fish age 40 gt lt students gt lt course gt lt course gt lt course gt lt coursedata gt www xmlpdf com xmlpdf user manual page 64 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data www xmlpdf com 22 3 6 22 3 7 If we wanted to include in the PDF file only students who were age 30 or more we use an XPath expression like this lt foreach iterator course itr xpath coursedata course gt lt block gt Course code lt merge root course itr xpath code gt Name lt merge root course itr xpath name gt lt block gt lt foreach iterat
44. a crop mark drawn near the bottom left corner This was drawn with the following XML lt graphic gt lt segment width 1 x1 90 x2 110 y1 100 y2 100 gt lt segment width 1 x1 100 x2 100 y1 110 y2 90 gt lt graphic gt xmlpdf user manual page 48 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 18 Images CHAPTER 18 Images 18 1 Basics XMLPDF allows PNG GIF and JPEG format images to be included in the PDF file To use a image you have to tell XMLPDF about the image before you can use it This is done by placing an lt image gt element into the lt images gt element near the start of the document Attributes of the lt image gt element are Attribute Description anti aliasing Specifies whether the PDF reader will apply anti aliasing to the image Anti aliasing removes jagged borders and lines especially when the image is viewed at high zoom levels By default anti aliasing is on The following two images are loaded from the same file the one on the left has anti aliasing false the one on the right uses the default setting directory Specifies the name of a directory in which to look for the named file This attribute is optional If it is used then the directory name is prepended to the file name value in order to make a full path to the image file This should not be used of the file name attribute specifies a URL image type As of version 1 8 of the XMLPDF library this
45. age and the edge of the text image or table The distance from the left edge of the page to the content is the left margin value from the document element plus the indent left value of the block indent right Specifies the right indentation of the text Indentation is the amount of space between the margin of the page and the edge of the text image or table The distance from the right edge of the page to the content is the right margin value from the document element plus the indent right value of the block keep together If set to true will prevent the block being split if it appears near the end of a page and will not fit If keep together is false the default the block will be split over two pages if it does not fit in the available space at the end of the page If keep together is true the block will not be split and will be moved completely to the start of the next page keep with next If set to true will keep the block on the same page as the next block level element If necessary a page break will be inserted to keep the block and the following block or table together layout If set to newspaper will format cells like a newspaper with cells going down one column from top to bottom then going down the next column from top to bottom until all columns are filled space before Sets the amount of white space which appears before the content of the block space after Sets t
46. age is scaled and the aspect ratio is not preserved If Mote coh y Pie tome To en Wo tp lil BESAN ANEO NELTA QE 4 ESGET jaw 6 DORIY Loi iat Do Sean oe Within a table the image can be horizontally aligned to left right or center by using the align attribute on the cell element not the show image element of the cell which contains the image The following shows a small image aligned left center and right in a table www xmipdf com xmlpdf user manual page 51 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 18 Images www xmlpdf com 18 3 18 4 18 5 If some text is used to make the left hand column higher we can also do vertical positioning of the image Here it is shown with top center and bottom vertical alignment some text to make the height of the table higher than the height of the small image so we can demonstrate vertical positioning of images Image Resolution Images resolution is the number of pixels in the image per unit of physical measurement usually expressed in terms of dots per inch or DPI Images with higher DPI are clearer and crisper when printed but take up more room in the PDF file For JPEG and SVG images you can specify the DPI using the dpi attribute on the lt image gt element like this lt document gt lt images gt lt image file name dolphins jpg dpi 300 image name dol gt lt images gt lt table padding
47. ak is inserted immediately where the new page element is found To change the page number or orientation of the page following the break use a next page element Grouping You can group pages into groups with each group having its own page number sequence Each group of pages is identified by a unique name A group is created using the lt begin page number group gt element which creates a named group which contains all the pages until the next begin page number group element is encountered Each group has its own total number of pages in the group which is inserted using the lt forward reference gt element like this lt document gt lt begin page number group group name s1 gt lt block gt section 1 page number lt page number gt of lt forward reference group name group pages gt lt block gt lt new page gt lt block gt section 1 page number lt page number gt of lt forward reference group name group pages gt lt block gt lt new page next page number 1 gt lt begin page number group group name s2 gt lt block gt section 2 page number lt page number gt of lt forward reference group name group pages gt lt block gt lt document gt Page grouping is useful if you want to generate many documents such as invoices into a single PDF file It enables you restart the page number sequence for each invoice so the first page of each invoice will be number 1 xmlpdf user manual page 37 of 10
48. all 2 gt lt row gt lt cell gt lt show image image name dol gt lt cell gt lt row gt lt table gt lt document gt Specifying a lower DPI enables you to reduce the PDF document size Merging the file name value An alternate syntax can be used to provide the value for the file name attribute By using a separate nested lt file name gt element it becomes possible to merge the value of the file name attribute from the data XML The lt file name gt element should contain only characters and which will be treated as if they had been specified for the file name attribute lt document gt lt image image name iml1 gt lt file name gt lt merge root invoice itr xpath linkTC gt lt file name gt lt image gt lt show image image name im1 gt lt document gt Using Scalable Vector Graphics XMLPDF for NET version 3 8 2 and higher provides support for including SVG images into the PDF document xmlpdf user manual page 52 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 18 Images www xmlpdf com Scalable Vector Graphics is a standard XML vocabulary used to define an image XMLPDF uses the Sharp Vector Graphics SVG library for SVG support Currently version 0 30 is supported Support for SVG is an optional feature XMLPDF will run without SVG being installed To activate SVG support download and install SVG and set the SVGDIR enviornment variable as described below In version 0 3
49. allows you to create the template XML in memory and not have to save it to file first As an aside to create a Stream of XML in memory you can use code like this Dim Xml As New StringBuilder Xml Append lt document gt lt block gt Xml Append Hello World Xml Append lt block gt lt document gt Dim stream As New MemoryStream ASCIIEncoding ASCII GetBytes Xml ToString xmlpdf user manual page 6 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 4 Usage www xmlpdf com 4 3 7 4 3 8 4 4 4 5 4 6 XML Stream to PDF Stream Data in String public void generate System IO Stream templateStream System IO Stream pdfStream String data templateStream is a stream which contains the XML template pdfStream is the name of the stream where the PDF file will be written The PDF is written to the stream at its current position The stream is not closed data is a string containing the XML data elements to be merged into the template XML Use this method to generate a PDF document to a stream reading the template XML from another stream while merging data from a string The output stream can be valid stream including a MemoryStream or Response OutputStream This method allows you to create the template XML in memory and not have to save it to file first Retrieving count of pages created public int getPagesCreated This method returns the number of physical pages created in the PDF document
50. ample of this element This element has no attributes 26 11 lt data gt This element is a container for data to be merged in the data XML used in the merging process It is the outermost element in the data XML and should appear only in data XML and not in document template XML See Section 22 2 Conditional processing for an example of this element This element has no attributes 26 12 lt define sequence gt www xmlpdf com xmlpdf user manual page 82 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com Summary of attributes Attribute Description format Specifies the format of the sequence When a sequence get element is used to retrieve the current value of the sequence and insert it into the document it can be retrieved as either alphabetic numeric or roman numeral format Sequence formats and the first two values in each format are alpha a b alpha upper A B roman I II roman lower i ii numeric 1 2 name Specifies the name of the sequence This is used in lt sequence get gt elements to retrieve the current value of the sequence and insert it into the document See Section 26 33 lt sequence get gt prefix Specifies a string which is prepended to the sequence number when it is retrieved using the sequence get element The following shows some examples using prefix and suffix suffix a b prefix a b prefix suffix a b suffix Specif
51. an font name zapfdingbats gt amp deg lt span gt lt block gt The degree symbol is xmlpdf user manual page 18 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 10 Units of Measurement www xmlpdf com 10 1 CHAPTER 10 Units of Measurement Units This section describes the format used for defining the size of objects in XMLPDF Within the XML used to define a PDF document elements have attributes which describe the size and format of the object Many attributes are numeric For example the height of a page in the document is defined using the height attribute as shown in this example lt document height 700 width 500 gt lt block gt Hello World lt block gt lt document gt The default unit of measurement for XMLPDF is the point A point is 1 72 inch or 0 3528 mm When defining the size of an area of the document i e any size except a font size values can be expressed with the units immediately after the number with no intervening spaces Format Example Meaning blank height 10 5 10 5 points i e 10 5 72 inches or 10 5 0 3528 mm a heist tosan 10 5 Gantine 7 in height 10 5in 10 5 inches pts height 10 5pts 10 5 points i e the same as 10 5 with no units specified widths 30 70 a percentage of the available width This is used only to define the width of a cell in a table as a proportion of the table width 2 widths 200 rest of available width This is used
52. and page footer elements to define the page header and footer for the table of content pages This allows you to have different headers and footers on the table of contents pages The table of contents pages in this manual have the following elements to create their page headers and footers xmlpdf user manual page 73 of 101 XMLPDF 5 5 7 Programmers Guide www xmlpdf com November 2006 25 Creating a Table of Contents lt toc gt lt page header space after l1cm indent left 2 75cm indent right 1 5cm gt lt row gt lt cell align left font name helvetica font size 8 text color blue gt XMLPDF lt info field version flags independent gt Programmers Guide lt cell gt lt cell align right font name helvetica font size 8 text color blue gt lt info field date flags MMMMM yyyy gt lt info gt lt cell gt lt row gt lt page header gt lt page footer space before 0 5cm indent left 2 75cm indent right 1 5cm gt lt row gt lt cell align middle font name gara font size 10 gt lt link url http www xmlpdf com gt www xmlpdf com lt link gt lt cell gt lt row gt lt page footer gt xmlpdf user manual page 74 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 1 26 2 CHAPTER 26 Reference lt auto sequence get gt Summary of attributes Attribute Description level The level of the hierarchy for which to retriev
53. at point on A page header can be defined for a limited range of page numbers This is done using the first page and last page attributes of the page header element For example to create a page header which did not appear on the first page we would set the first page attribute to 2 like this lt page header first page 2 gt lt row gt lt cell gt Not on page 2 lt cell gt lt row gt lt page header gt Or to define a page header which appeared only one pages 2 3 and 4 we would do this lt page header first page 2 last page 4 gt lt row gt lt cell gt Not on page 2 lt cell gt lt xrow gt lt page header gt 12 6 5 Page footer element The lt page footer gt element is used to set the page footer which will appear in the PDF document from that point on The page footer is conceptually the same as a table in that it has rows and cells The page footer for this document looks like this lt page footer indent left 2 75cm indent right 1 5cm gt lt row gt lt cell align left font name helvetica font size 8 text color blue gt lt link url http www xmlpdf com gt www xmlpdf com lt link gt lt cell gt lt cell border width top 0 01 align right font size 8 font name helvetica gt xmlpdf user manual page lt page number gt of lt forward reference name total pages gt lt cell gt lt row gt lt page footer gt The page footer is automatically repeate
54. attribute is no longer used The image file is read to determine the type of the image file name The full path of the file in which the image resides From version 3 0 this can be a full URL such as http www xmlpdf com images download gif with the image being retrieved from the URL for example file name usr xman clouds jpg file name http www xmlpdf com images download gif image name The name by which the image will be referred to when it is displayed using a lt show image gt element for example image name clouds www xmlpdf com xmlpdf user manual page 49 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 18 Images Attribute Description quality A value which defines the image quality This applies only to JPEG and SVG images This value changes the compression level of the image when it is stored in the PDF file The value ranges from 1 to 100 with 1 giving lowest quality and highest compression and 100 giving the highest quality and largest image size The default is 100 An image is loaded from disk when the lt image gt element is processed by XMLPDE To display the image it must be named in a lt show image gt element as shown in the following example lt document gt lt images gt lt image file name dolphins png image name dol gt lt images gt lt table padding all 2 widths 30 70 gt lt row gt lt cell gt lt show image image name dol gt lt cell gt
55. be used the document must be declared as using the CMYK color space like this lt document color space cmyk A CMYK color is used like this lt block text color cmyk 0 7 0 3 0 3 0 4 gt hello lt block gt This creates a color with C 0 7 M 0 3 Y 0 3 and K 0 4 xmlpdf user manual page 38 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables 16 1 16 2 www xmlpdf com CHAPTER 16 Tables Basics Tables have a similar structure in XML to tables in HTML A lt table gt element contains one or more lt row gt elements and each lt row gt element contains one or more lt cell gt elements In addition a table can contain a lt header gt element which is itself a table and defines a header which is repeated each time a table is split by a page break Tables are automatically paginated Unlike HTML columns widths are not calculated based on the width of cell contents To do this would mean each copy of a form would look different depending on the data in it something which contradicts the design goal of producing the same output under all circumstances A simple table looks like this lt document gt lt table gt lt row gt lt cell gt this is cell 1 lt cell gt lt cell gt this is cell 2 lt cell gt lt row gt lt table gt lt document gt Note that in this case column widths are not specified In the absence of a widths attribute each column will be allocated an even amou
56. borders so that the borders of the nested table are distinct set the padding attribute on the cell which contains the nested table With padding around the nested table the XML looks like this lt table border width all 01 gt lt row gt lt cell gt a lt cell gt lt cell gt b lt cell gt lt row gt lt row gt lt cell gt c lt cell gt lt cell padding all 4 gt lt table border width all 01 gt lt row gt lt cell gt 1 lt cell gt lt cell gt 2 lt cell gt lt cell gt 3 lt cell gt lt row gt lt row gt lt cell gt 4 lt cell gt lt cell gt 5 lt cell gt lt cell gt 6 lt cell gt lt row gt lt table gt lt cell gt lt row gt lt table gt With padding around the nested table the resulting table looks like this a b e 1 2 4 5 6 Row height The height of a row in a table is calculated from the height of the highest cell in that row The following table has one cell with one word and a second cell with several words The cell with several words is higher and the smaller cell is expanded in height to match the height of the higher cell one this cell has many words so is higher than the cell on the left xmlpdf user manual page 43 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables The XML for this is lt table border width all 1 indent left 3cm indent right 3cm padding all 2 gt lt row gt lt cell gt one lt cell gt lt cell gt this cell has many words s
57. centage between 0 and 100 as in background gray 20 Smaller numbers are darker The following nested table shows columns with background gray values of 20 40 and 60 respectively gt i border color all border color inner border color outer border color top border color bottom border color left border color right Sets the color of row borders These colors are inherited by cells in the row If colors are not specified on the row element they will be inherited from the table element containing the row border width all border width inner border width outer border width top border width bottom border width left border width right class Sets the widths of row borders If border widths are not specified on the row element they will be inherited from table element containing the row Specifies the class of this row so that styles which match the class will automatically be applied See Section 19 Styles fill color Specifies background color of the row See Section 15 Colors The following nested table shows columns with fill color values of red and blue respectively font name font size padding all padding inner padding outer padding top padding bottom padding left padding right Specifies the font face of this row See Section 11 Fonts Specifies the font size of this row See Section 11 Fonts Sets cell padding for cells in this row Padding is the amount of s
58. ck For example this block of text has the attribute relative name 101 We can position the image to the left of this block using XML Setting ry 0 means the image will be at the same height on the page as the text and setting rx 72 will positioning the image one inch 72 points to the left of the text The XML for positioning the image looks like this lt show image relative to 101 ry 0 rx 72 image name ferret scale width 50 gt By using relative positioning the image will be located adjacent to the named block regardless of where that block appears in the document Relatively positioned elements are outside the normal flow of the document and so are not paginated You are responsible for making sure they fit on the page www xmlpdf com xmlpdf user manual page 71 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 25 Creating a Table of Contents www xmlpdf com 25 1 CHAPTER 25 Creating a Table of Contents Creating a Table Of Contents A table of contents is created using the lt toc gt element This element creates a set of pages which contain the table of contents A lists of items which will appear in the table of content is created from all the auto sequence get name elements which have outline true specified So any item which appears in the bookmarks will also appear in the table of contents Internally XMLPDF creates a collection of these items and the table of contents is created b
59. ck has both indent left and indent right set to 4cm and is longer so we can see the edge Kerning Kerning is the process of moving some characters closer to each other in order to improve appearance By default kerning is turned on Which characters are moved depends entirely on the font used The following block has kerning on the default AWAWAWA ACACACAA The next block has kern false and so the line displayed is slightly longer than the one above AWAWAWA ACACACAA Keep together When the end of page is reached XMLPDF will attempt to insert as much of the current block of text as fits into the page If you do not want the text or table split set keep together true so that all of the block is moved to the next page If the entire block does not fit on one page it will still be split Keep spaces When XML is entered it typically is formatted to be readable and looks something like this lt document gt lt block gt Hello World lt block gt lt document gt xmlpdf user manual page 34 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 13 Text Formatting www xmlpdf com 13 14 13 15 13 16 13 17 Note the large amount of white space around each line particularly before the word Hello By default this is trimmed off during processing so that only the text Hello World actually appears in the document To retain space at the start of the line use keep spaces true This is in fact done on the
60. cluded in the PDF Data relating to characters not used in the PDF document is discarded This means you can use large font files and still get small PDF documents See Section 11 Fonts for more information Images PNG GIF and JPEG images can be included in files produced using XMLPDF XMLPDF supports scaling images to fit page sizes and scaling to fit inside table cells Images can be positioned anywhere in the document including in headers and footers See Section 18 Images for more information xmlpdf user manual page 2 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 2 Features www xmlpdf com 2 5 2 6 2 7 2 8 2 9 2 10 Pagination Text blocks and tables are automatically split at page boundaries Table headers can be automatically repeated where a table is split Automatic numbering of pages and headings is supported including page X of pas Tables XMLPDEF supports extensive table formatting functionality Tables contain cells which in turn can contain text images graphics or other tables Table headers can be repeated automatically when tables are split by page breaks See Section 16 Tables for more information Merging Data XMLPDF is designed for creating document templates in XML and then merging in data from a database Data is presented to the document generation process as XML so it can originate from databases existing XML files or any other source from which XML can be c
61. cription Example font name The name of the font as used font name arial narrow in this document This name is used in text elements to make the text use that font font file The full path of the file which font file d winntx fonts arial t contains the fonts tf unicode Tells XMLPDF that the font unicode true contains and you want to use characters above U 00FF See unicode fonts for notes on Unicode fonts Each TrueType font is read into memory and cached the first time it is used This means that if XMLPDF is used in a web server or application server only minimal resources are used to hold TrueType fonts and they are read from disk and parsed only once Unicode fonts Unicode TrueType fonts are TrueType fonts which contain glyphs for character codes greater than ASCII 255 or U 00FF These are supported in XMLPDF from release 1 1 To use a Unicode font you must specify the type to be truetype like any other TrueType font and set the unicode attribute on the lt font gt element to true Always remember to set the encoding processing instruction of your XML to the correct one for the actual encoding of the document This is done at the start of the XML like this lt xml version 1 0 encoding UTF 8 gt For more information on encoding check out www unicode org Unicode fonts are always embedded in the document A subset of the font is created which contains only the characters which actually appear in t
62. cument is created using an auto sequence inc element which defines the heading at a given level in the outline hierarchy and increments the current heading number at the level specified After each heading is defined it becomes the current heading for that level until a new heading is defined The auto sequence get and auto sequence get name elements are used to retrieve the current heading number and name xmlpdf user manual page 76 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 4 26 5 For example at the start of the document we might call the first chapter Introduction Because this is a chapter level heading its level attribute will be 1 Below the Introduction we want a second level header called Overview This is done as follows lt auto sequence inc level 1 name Introduction gt lt auto sequence inc level 2 name Overview gt This creates a hierarchy like this 1 Introduction 1 1 Overview lt begin page number group gt Summary of attributes Attribute Description group name unique name for this group This element starts a new group of page numbers This resets the page number to 1 and sets the counter retrieved by the forward reference element to 1 See Section 14 Page Numbering for more information lt boxes gt Summary of attributes Attribute Description box height Height of boxes box width Width of each individual box
63. d at the end of each page after it is defined To change the page footer simply insert another page footer element into the document XML The page footer will be changed from that point on A page footer can be defined for a limited range of page numbers This is done using the first page and last page attributes of the page footer element For example to create a page footer which did not appear on the first page we would set the first page attribute to 2 like this xmlpdf user manual page 30 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 12 Document Structure 12 7 12 8 12 9 www xmlpdf com lt page footer first page 2 gt lt row gt lt cell gt Not on page 2 lt cell gt lt row gt lt page footer gt Or to define a page footer which appeared only one pages 2 3 and 4 we would do this lt page footer first page 2 last page 4 gt lt row gt lt cell gt Not on page 2 lt cell gt lt xrow gt lt page footer gt Formatting elements This section details the elements which are not used to insert content but to define formatting New page element The lt new page gt element is used force a page break in the PDF output Its only attribute which is optional is the next page number attribute which can be used to set the page number of the next page For example to set the page number of the next page to 1 you would do the following lt new page next page number 1 gt If
64. d within a lt block gt or lt cell gt element to change the formatting of text which is within the span element The following example has the word large in 20 point font with a span element This word will be larger and after the end of the span element the previous font size will be restored lt block gt This is in 12 point This is in lt span font size 20 gt 20pt lt span gt back to 12 point lt block gt This produces the following in the PDF document xmlpdf user manual page 35 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 13 Text Formatting This is in 12 point This is in 20pt back to 12 point www xmlpdf com xmlpdf user manual page 36 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 14 Page Numbering 14 1 14 2 14 3 www xmlpdf com CHAPTER 14 Page Numbering Basics Pages are numbered automatically starting from 1 To insert the number of the current page into the document use the lt page number gt element as shown here lt document gt lt block gt Hello World this is page number lt page number gt lt block gt lt document gt The total number of pages in the document is inserted using the lt forward reference gt element like this lt document gt lt block gt page number lt page number gt of lt forward reference name total pages gt lt block gt lt document gt Breaks Use the lt new page gt element to create a page break The page bre
65. default console handler and to the file handler as well so you can see error messages on the console and they are also stored in the file Logging to A Stream XMLPDF can log messages to a stream created by the caller The stream is any object which implements the System IO Stream interface To log messages to a stream create an xmlpdf logging StreamHandler object and then tell the logger to log to this object This example logs to a MemoryStream but any valid stream can be used xmlpdf user manual page 58 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 www xmlpdf com 21 4 21 5 21 Error Handling using System using System IO using xmlpdf using xmlpdf logging public class Create static void Main string args Logger getLogger clearHandlers MemoryStream ms new MemoryStream StreamHandler h new StreamHandler Logger getLogger addHandler h If you omit the clearHandlers call shown in the above example log records will be written to the default console handler and to the stream handler as well Logging to System Diagnostics Trace XMLPDF can log messages to the System Diagnostics Trace object To log messages to the trace object create a xmlpdf logging TraceHandler object and then tell the logger to log to this object using System using xmlpdf using xmlpdf loggging public class Create static void Main string args Logger getLogger clearHandlers
66. der of a cell and the text or image in it How to use the table element is described in detail in Section 16 Tables lt watermark gt The watermark element creates an image which is repeated on every page The lt watermark gt element is a type of lt table gt element and so can have all the attributes of a lt table gt element as listed in Section 26 40 lt table gt The table defined by the lt watermark gt element will be placed on every page following the element The watermark will be placed in the center of the page To move the watermark to a different position use the absolute x and absolute y attributes as described in Section 26 40 lt table gt An example of the watermark is lt watermark gt lt row gt lt cell gt lt show image image name draft priority 100 gt lt cell gt lt xrow gt lt watermark gt xmlpdf user manual page 100 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 42 In the above example the priority attribute is used to make sure the watermark appears behind any content lt xref gt Summary of attributes Attribute Description uid Unique identifier which must match a uid attribute from an auto sequence get name element as described in Section 26 2 lt auto sequence get name gt text Optional value which will appear as the text of the link in the document If this is not specified the outline header
67. e PDF is written to the stream at its current position The stream is not closed Use this method to generate a PDF document to a stream from from an XML template without merging data The stream can be valid stream including a MemoryStream or Response OutputStream XML File to PDF Stream Data in String public void generate String templateFileName System IO Stream pdfStream String data templateFileName is the name of the file on disk which contains the template XML pdfStream is the name of the stream where the PDF file will be written The PDF is written to the stream at its current position The stream is not closed data is a string containing the XML data elements to be merged into the template XML Use this method to generate a PDF document to a stream reading the template from disk and merging data from memory The stream can be valid stream including a MemoryStream or Response OutputStream XML Stream to PDF Stream public void generate System IO Stream templateStream System IO Stream pdfStream templateStream is a stream which contains the XML template pdfStream is the name of the stream where the PDF file will be written The PDF is written to the stream at its current position The stream is not closed Use this method to generate a PDF document to a stream reading the template XML from another stream The output stream can be valid stream including a MemoryStream or Response OutputStream This method
68. e elements are explained in the following sections Processing instructions are elements such as lt style gt lt page header gt lt page footer gt lt sequence gt and lt auto sequence gt elements Each of these elements can appear any number of times in any order These elements are explained in the following sections 12 6 1 Block element The lt block gt element is used to place a block of text in the PDF document The block used to create this sentence looks like this lt block gt The amp l1t block amp gt element is used to place a block of text in the PDF document The block used to create this sentence looks like this lt block gt The following attributes affect the way the text in the block appears These are explain in more detail in Section 13 Text Formatting Attribute Description align Specifies the text alignment to use for this block This specifies the alignment of text within the block not the alignment of the block on the page Alignment of the block on the page is specified using the block align attribute as stated below See Section 13 2 Horizontal alignment block align Specifies how a block which is less than 100 of the page width is aligned on the page This can be left right or center class Specifies the class of this block so that styles which match the class will automatically be applied See Section 19 Styles font name Specifies the font face of
69. e a full URL such as http www xmlpdf com images download gif with the image being retrieved from the URL image name Specifies a logical name which is used to uniquely identify the image within the document This value is used on the show image element to say which image to display image type As of version 1 8 of the XMLPDF library this attribute is no longer used The image file is read to determine the type of the image quality www xmlpdf com A value which defines the image quality This applies only to JPEG and SVG images This value changes the compression level of the image when it is stored in the PDF file The value ranges from 1 to 100 with 1 giving lowest quality and highest compression and 100 giving the highest quality and largest image size The default is 100 xmlpdf user manual page 87 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference The lt image gt element must occur inside an lt images gt element before the image is referenced by a lt show image gt element See Section 18 Images for examples on how to include an image in the document PNG GIF and JPEG formats are supported by XMLPDF Interlaced or transparent versions of these formats are not supported 26 20 lt images gt This element is a container for lt image gt elements and should appear only in document template XML See Section 18 Images for an example of this element This element has no att
70. e running and how it interacts with the printer driver Correct fonts XMLDPF allows you to embed fonts into a document so that the document will print with the fonts specified not the fonts which happen to be installed on the users machine Security PDF documents are much more difficult for a user to alter than HTML or Word documents Precision formatting Using PDF allows you to specify exactly the widths of table columns so the document looks the same on all systems Development Environments The NET version of XMLPDF is developed in C and delivered as a single assembly called xmlpdf dll This can be used as an application specific assembly The Java version of XMLPDF is developed in Java 1 2 and delivered as a single jar called xmlpdf 1 0 jar This can be used with JDK JRE versions 1 2 and 1 3 Do I need to know about the PDF file format No The complexities of the PDF format are completely hidden About this manual This manual was produced using XMLPDF version 5 5 7M Body text is in Times Roman 10 13 headings are Helvetica 12 A subset of Garamond and of Arial is embedded to demonstrate Unicode fonts Acrobat users can press Ctrl Alt F to see a list of all the fonts in this document xmlpdf user manual page 1 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 2 Features www xmlpdf com 2 1 2 2 2 3 2 4 CHAPTER 2 Features Document templates XMLPDF allows you to define the format of a PDF docu
71. e segment in points Lines can be drawn on the page using the lt segment gt element Each segment has an start point defined in by values x1 y1 and and end point defined by x2 y2 These x and y values are absolute coordinates in points with 0 0 being at the bottom left corner of the page For example this page as a crop mark drawn near the bottom left corner This was drawn with the following XML lt graphic gt lt segment width 1 x1 90 x2 110 y1l 100 y2 100 gt lt segment width 1 x1 100 x2 100 y1 110 y2 90 gt lt graphic gt xmlpdf user manual page 93 of 101 XMLPDF 5 5 7 Programmers Guide www xmlpdf com 26 35 lt show image gt November 2006 26 Reference Summary of attributes Attribute align class Description Specifies the text alignment to use for this block See Section 13 2 Horizontal alignment Specifies the class of this block so that styles which match the class will automatically be applied See Section 19 Styles image name Specifies the name of the image to insert at this point in the document indent left Specifies the left indentation of the text Indentation is the amount of space between the margin of the page and the edge of the text image or table The distance from the left edge of the page to the content is the left margin value from the document element plus the indent left value of the block indent right Specifies the r
72. e the number XMLPDF automatically maintains a document outline which is used to number headings and subheadings and to generate the outline which Acrobat displays on the left side of the screen Use of this feature is optional Each heading in the document is created using an auto sequence inc element which a defines the heading for a given level in the outline hierarchy and b increments the current heading number for the level specified The lt auto sequence get gt element retrieves the current heading number not name for the specified level Use the auto sequence get name element to retrieve the heading text for a speficied level For example at the start of the document we might call the first chapter Introduction Because this is a chapter level heading its level attribute will be 1 Below the Introduction we want a second level header called Overview This is done as follows lt auto sequence inc level 1 name Introduction gt lt auto sequence inc level 2 name Overview gt This creates a hierarchy like this 1 Introduction 1 1 Overview Having set the title for the current level of the outline we can retrieve its number and insert it into the document using the auto sequence get element Specifying the level attribute on the element determines which heading number is inserted into document For instance the element lt auto sequence get level 1 gt would insert the string into the document If
73. e thing Text color By default text is black Text color can be changed using the text color attribute The value of the text color attribute is one of the standard colors or a custom hexadecimal value See Section 15 Colors For example to make a block or word appear blue you would set text color blue as in lt block text color blue gt this appears in blue lt block gt which produces this this appears in blue Underline and strikethrough Underline and strikethrough effects are done using the decoration attribute This can be set to the value underline or strikethrough follow the format of the text wittteHew theformatefthetext You can specify more than one decoration by separating values with a space i e decoration underline strikethrough will give both effects ikethis The color of the decoration line is specified using the underline color or strikethrough color attributes This has underline color set to red The underline color and strikethough color values default to the current text color value so the following text has decoration strikethrough and text color blue so the line through the text defaults to the text color of blue Space after This is used to insert blank space after a block of text as in lt document font name helvetica font size 15 18 gt lt block space after 3cm gt Hello World lt block gt lt document gt Space before This is
74. ection 20 Document Security for details The lt document gt element is the outermost element in the document template XML This is the top level element and contains the whole document Attributes of the document element set overall characteristics of the document such as the page size and the page margins xmlpdf user manual page 84 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 14 26 15 26 16 lt forward reference gt Summary of attributes Attribute Description name Curently this must be total pages or group pages To display the total pages in the document in the page footer do this lt page footer indent left 2 75cm indent right 1 5cm gt lt row gt lt cell align left font name helvetica font size 8 text color blue gt lt link url http www xmlpdf com gt www xmlpdf com lt link gt lt cell gt lt cell border width top 0 01 align right font size 8 font name helvetica gt xmlpdf user manual page lt page number gt of lt forward reference name total pages gt lt cell gt lt row gt lt page footer gt This will print Page 1 of n at the bottom of each page where n is the total number of pages in the document If you are using page grouping as described in Section 14 Page Numbering you set the name attribute to group pages to get the total number of pages in the current page group lt font gt Summar
75. element 31 12 9 Dynamic Attributes 31 13 Text Formatting 32 13 1 Basics 32 13 2 Horizontal alignment 32 13 3 Vertical alignment 32 13 4 Textcolor 33 13 5 Underline and strikethrough 33 13 6 Space after 33 13 7 Space before 33 13 8 Forcing space before 34 13 9 Indentleft 34 13 10 Indentright 34 13 11 Kerning 34 13 12 Keep together 34 13 13 Keep spaces 34 13 14 Leading 35 13 15 Rise 35 13 16 Non Breaking Space 35 13 17 Changing Text Formatting 35 14 Page Numbering 37 14 1 Basics 37 14 2 Breaks 37 14 3 Grouping 37 15 Colors 38 15 1 Basics 38 15 2 Predefined Colors 38 15 3 Custom Colors 38 15 4 CMYK Colors 38 16 Tables 39 16 1 Basics 39 16 2 Column widths 39 16 3 Borders 40 wwwxmlpdf com XMLPDF 5 5 7 Programmers Guide November 2006 20 21 22 23 24 25 16 4 Rounded Corners 41 16 5 Line styles 41 16 6 Border colors 42 16 7 Cell padding 42 16 8 Nested tables 42 16 9 Row height 43 16 10 Newspaper layout 44 16 11 Other attributes 46 Lines and Boxes 48 17 1 Drawing Boxes 48 17 2 Drawing Lines 48 Images 49 18 1 Basics 49 18 2 ImageSize 51 18 3 Image Resolution 52 18 4 Merging the file name value 52 18 5 Using Scalable Vector Graphics 52 Styles 55 19 1 Basics 55 Document Security 56 20 1 Passwords 56 20 2 Restrictions 56 20 3 Example 56 Error Handling 58 21 1 Basics 58 21 2 Logging to File 58 21 3 Logging to A Stream 58 21 4 Logging to System Diagn
76. er itr iterator The result of this calculation is converted to a string and inserted into the PDF document The XPath expression is passed to the NET or Java XPath processor so any value XPath expression will work here The final result is orderlist pdf Conditions This requires NET version 3 9 6 or Java version 3 9 XMLPDF lets you use the lt if gt and lt ifnot gt elements in conjuction with XPath expressions to determine at the time the PDF document is created whether or not to include some parts of the template XML The template courseif xml is used in conjuction with coursedata xml It contains this XML to conditionally include some text if the student is aged 30 years or older lt if xpath age gt 30 root student itr gt over 29 lt if gt The expression age gt 30 is evaluated for each student and if the condition is true then the text over 29 is included in the document This creates the PDF file courseif pdf xmlpdf user manual page 65 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data 22 3 8 22 3 9 www xmlpdf com Any valid XPath test can be used in the xpath attribute for example to test if the age attribute is present just use an and the attribute name like this lt if xpath age root student itr gt age is present lt if gt Formatting Merged Values This is currently only in NET version 4 0 3 and above A value merged into the PDF file using a lt
77. f the columns Where only percentage column widths are used the width of the table is the width of the available space less factors such as indentation The width of the last column in a table can be specified using the character This allocates all remaining space to that column The following XML creates a table with one row and two cells in that row The first cell is 200 pts wide the second is all remaining space lt document lt table widths 225 border width all 0 01 border color all blue gt lt row gt lt cell gt this is cell 1 lt cell gt lt cell gt this is cell 2 lt cell gt lt row gt lt table gt lt document gt This produces a table looking like this this is cell 1 this is cell 2 16 3 Borders By default tables have no borders A border is defined by using one of the following elements border width all border width inner border width outer border width top border width bottom border width left border width right The value of the border width XXX element defines the width of the border in points for example border width outer 1 will put a 1 point border around the outside of a table row or cell Note that the resolution of the output device may be as low as 300 dpi so values below 1 300 of a point or 0 03 will produce a line which may not be visible on some devices Each element can be set on the table header row or cell element for example www xmipdf com xmlpdf user manual
78. f the style See below Any other attribute can be specified on a style These attributes are then applied to any element which matches the style A style element is used to define a set of attributes which can then be automatically be applied to elements This means the default formatting of text can be defined in a single place in the document and applied automatically This manual has styles defined for text text in cells code examples and heading This gives the manual a consistent appearance and makes it simple to change the whole document Styles which have a name which is the same as the name of a element i e a name such as block are automatically applied to all elements of that type which follow in the document See Section 19 Styles For example this manual uses the following style lt style name xref text color blue gt to make all cross references created with lt xref gt elements appear block like this one See Section 19 Styles Styles which have a name which begins with a character such as name code are applied to all elements which have class attribute of the matching name without the For example this manual uses the following style xmlpdf user manual page 97 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com lt style name h1l font name helvetica bold font size 14 space before 5cm space after 5cm gt to make all elements with a cla
79. he document This means that the size of the font file does not affect the size of the PDF only the number of distinct glyphs appearing in the PDF does For example if you use the font arialuni ttf which is 24 megabytes in size but only use a few hundred different characters in your document the PDF file will still be less than 100K in size xmlpdf user manual page 24 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 12 Document Structure CHAPTER 12 Document Structure 12 1 Basics This chapter describes the overall structure of an XMLPDF document template A typical document looks like this lt xml version 1 0 encoding UTF 8 gt lt document gt lt fonts gt lt font font name arial font file arial ttf type truetype gt lt fonts gt lt images gt lt image file name dolphins png image name dol gt lt images gt lt table padding all 2 widths 30 70 gt lt row gt lt cell gt lt show image image name dol gt lt cell gt lt cell gt lt show image image name dol gt lt cell gt lt row gt lt table gt lt block font name arial font size 12 gt Hello World lt block gt lt document gt 12 2 XML encoding The first line in the document is the XML processing instruction lt xml version 1 0 encoding UTF 8 gt This is only necessary if the document contains any Unicode characters The encoding specified must match the actual encoding of the docume
80. he amount of white space which appears after the content of the block The space between two blocks is the space after of the first block plus the space before of the second block xmlpdf user manual page 99 of 101 XMLPDF 5 5 7 Programmers Guide 26 41 www xmlpdf com November 2006 26 Reference Attribute Description space required width Sets the amount of space which must be present on the page for the block to be output If that amount of space is not available the whole block is moved to the next page This is useful to prevent headers being output by themselves at the bottom of the page Specifies the width of the table This can be a fixed amount such as 12cm or a percentage of the page width such as 80 If the table is less than 100 of the page width it is aligned using the block align attribute widths Sets the widths of columns border width all border width inner border width outer border width top border width bottom border width left border width right Sets the widths of table row and cell borders border color all border color inner border color outer border color top border color bottom border color left border color right padding all padding inner padding outer padding top padding bottom padding left padding right Sets the color of table row and cell borders See Section 15 Colors Sets cell padding Padding is the amount of space between the bor
81. he contents of the cell Padding can be set on table row and cell elements using any of the attributes padding all padding toppadding bottom padding leftpadding right This example has only the padding left value set to 4 Padding is the space inside a cell between the cell border and the contents of the cell Nested tables A table can be inserted into a cell of another table The following shows a table with two rows each with two cells The bottom right cell contains another table with 3 rows of 3 cells a b c 1 2 3 4 5 6 The XML for this is shown here xmlpdf user manual page 42 of 101 XMLPDF 5 5 7 Programmers Guide 16 9 www xmlpdf com November 2006 lt table border width all 01 gt lt row gt lt cell gt a lt cell gt lt cell gt b lt cell gt lt row gt 16 Tables lt row gt lt cell gt c lt cell gt lt cell auto pad false gt lt table border width all 01 gt lt row gt lt cell gt 1 lt cell gt lt cell gt 2 lt cell gt lt cell gt 3 lt cell gt lt xrow gt lt row gt lt cell gt 4 lt cell gt lt cell gt 5 lt cell gt lt cell gt 6 lt cell gt lt row gt lt table gt lt cell gt lt row gt lt table gt Note the way in which the borders of the nested table are merged with the borders of the cell containing the nested table This is done because the padding between the borders of the nested cell and the table it contains is zero To separate the
82. he document without the owner password See Section 20 Document Security for details deny modify When set to true prevents modifying the document without the owner password See Section 20 Document Security for details info title Sets the PDF document title which is displayed in the document summary dialog box in Adobe Acrobat info author Sets the PDF document author which is displayed in the document summary dialog box in Adobe Acrobat info subject Sets the PDF document subject which is displayed in the document summary dialog box in Adobe Acrobat margin left Sets the left margin for the whole document margin right Sets the right margin for the whole document margin top Sets the top margin for the whole document margin bottom Sets the bottom margin for the whole document orientation Sets the page orientation for the document If specified this must be landscape or portrait The default value is portrait The page orientation can be changed later using the Section 26 27 lt next page gt lt next page gt element owner password Sets the password required to take ownership of the document See Section 20 Document Security for details page size Sets the size of the page for the whole document See Section 10 2 Page sizes for details user password Sets the password required if any to open the document with limited access See S
83. he link is lt link url http www sun com url show border true gt The Sun Site lt link gt lt block gt lt document gt to display the link inside a border like this The link is A link can also refer to a local file To do this set the url attribute to the file name For instance to link to the local file unicode pdf you would do this lt document gt lt block gt The link is lt link url unicode pdf gt unicode pdf lt link gt lt block gt lt document gt www xmlpdf com xmlpdf user manual page 69 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 23 Links 23 2 Merging the URL Value An alternate syntax can be used to provide the value for the url attribute By using a separate nested lt url gt element it becomes possible to merge the value of the url attribute from the data XML The lt url gt element should contain only characters and which will be treated as if they had been specified for the url attribute lt document gt lt block gt The link is lt link gt lt url gt lt merge root invoice itr xpath linkTC gt lt url gt information lt link gt lt block gt lt document gt This example will create a link with the text information and when clicked will go to whatever value is returned from the lt merge gt operation www xmlpdf com xmlpdf user manual page 70 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 24 Positioning Output CHAPTER 24 Positioning Output
84. hould be changed to the location of the license file on your system xmlpdf user manual page 7 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 4 Usage www xmlpdf com Doing this overrides the default file location We suggest that your program load the actual location from a configuration file or the registry to make you application more flexible We have not configured a registry setting because some users will run XMLPDF under the ASPNET account which by default does not have registry access xmlpdf user manual page 8 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 5 C Example www xmlpdf com 5 1 5 2 CHAPTER 5 C Example C Code A simple C program for calling the XMLPDF library to create the PDF file looks like this using System using xmlpdf public class Create public static void main string args PDFDocument doc new PDFDocument doc generate args 0 args 1 This program takes as command line arguments two file names first the name of the XML file and then the name of the PDF file This program is executed with a command such as Create HelloWorld xml HelloWorld pdf Assuming the system is installed correctly this will create the file HelloWorld pdf Step by Step The steps involved in creating the above program are shown here 1 Start Visual Studio NET 2 Create a new project Select File New Project from the menu to bring up the New Project dialog x
85. ial font size 12 gt Hello World lt block gt lt document gt The attributes which affect how text is displayed are listed here with an example for each attribute 13 2 Horizontal alignment Text is aligned horizontally using the align attribute To align a block to the right you use align right as shown here lt document gt lt block align right font size 12 gt Hello World lt block gt lt document gt Possible values of align are left right middle center justified The values center and middle do the same thing 13 3 Vertical alignment Text is vertically aligned using the vertical align attribute This only applies to the content of cells in tables To align a block at the center of the cell you use align middle as shown here lt table border width all 01 indent left 3cm indent right 3cm padding all 2 gt lt row vertical align middle gt lt cell gt one lt cell gt lt cell gt this cell has many words so is higher than the cell on the left lt cell gt lt xrow gt lt table gt And the resulting table looks like this this cell has many words so one is higher than the cell on the left Possible values of vertical align are top bottom middle www xmlpdf com xmlpdf user manual page 32 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 13 Text Formatting 13 4 13 5 13 6 13 7 www xmlpdf com center The values center and middle do the sam
86. ied on the cell element they will be inherited from the row and table elements containing the cell border width all border width inner border width outer border width top border width bottom border width left border width right class Sets the widths of cell borders If widths are not specified on the cell element they will be inherited from the row and table elements containing the cell Specifies the class of this cell so that styles which match the class will automatically be applied See Section 19 Styles colspan Specifies the number of columns in the table this cell is wide This defaults to 1 fill color Specifies background color of the cell See Section 15 Colors The following nested table shows columns with fill color values of red and blue respectively font name font size min height Specifies the font face of this cell See Section 11 Fonts Specifies the font size of this cell See Section 11 Fonts Specifies the minimum height of the cell padding all padding inner padding outer padding top padding bottom padding left padding right Sets cell padding Padding is the amount of space between the border of a cell and the text or image in it rowspan Specifies the number of rows in the table this cell is high This defaults to 1 xmlpdf user manual page 81 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference Attribute Descri
87. ies a string which is appended to the sequence number when it is retrieved using the sequence get element See above for some examples using prefix and suffix A sequence is a source for a list of numbers It provides a simple way of numbering paragraphs in a document or items in a list Using a sequence is a two stage process First a sequence is created using a lt define sequence gt element and then the current value of the sequence can be inserted into the document using a lt sequence get gt element Each time the sequence get element is used the associate value is increments For example to define a sequence of roman numerals and then display the first five values we do this lt define sequence name s1 format roman lower gt lt sequence get name s1 gt lt br gt lt sequence get name s1 gt lt br gt lt sequence get name s1 gt lt br gt lt sequence get name s1 gt lt br gt lt sequence get name s1 gt lt br gt xmlpdf user manual page 83 of 101 XMLPDF 5 5 7 Programmers Guide This produces the following output i 26 13 www xmlpdf com ii iii iv v lt document gt November 2006 26 Reference Summary of attributes Attribute Description deny print When set to true prevents printing of the document without the owner password See Section 20 Document Security for details deny extract When set to true prevents cutting text or graphics from t
88. ight 200 so the image is scaled and the aspect ratio is not preserved www xmlpdf com xmlpdf user manual page 95 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com I vet ur fae ft Ome tk Yen i tp Bu DARASA AR Ele NELDA PAER ORNE T Gm 60002 Aana damne ramena eactrnarks DOTEE 26 36 lt set gt 26 37 26 38 Any attribute which can be applied to text can be used with this element This element is used to change the formatting of text within a block or cell element The change specified is applied to all text which follows the set element until a restore element see Section 26 31 lt restore gt is found which sets the text attributes back to the value they had before the set element Set and restore elements work on stack based approach to multiple set elements can be used and matched with multiple restore elements Given the following XML lt document font name helvetica font size 12 gt lt block gt Hello World this is XMLPDF lt block gt lt document gt We can change the word World to a courier by inserting set and restore elements around the word as shown here lt document font name helvetica font size 12 gt lt block gt Hello lt set font name courier gt World lt restore gt this is XMLPDF lt block gt lt document gt This changes the output from this Hello World this is XMLPDF to this Hello
89. ight indentation of the text Indentation is the amount of space between the margin of the page and the edge of the text image or table The distance from the right edge of the page to the content is the right margin value from the document element plus the indent right value of the block scale width Specifies the width of the image This is optional and is used to change the default size of the image If only one of scale width and scale height are used the aspect ratio of the image is preserved scale height Specifies the height of the image This is optional and is used to change the default size of the image If only one of scale width and scale height are used the aspect ratio of the image is preserved space before Sets the amount of white space which appears before the content of the block space after Sets the amount of white space which appears after the content of the block The space between two blocks is the space after of the first block plus the space before of the second block space required Sets the amount of space which must be present on the page for the block to be output If that amount of space is not available the whole block is moved to the next page This is useful to prevent headers being output by themselves at the bottom of the page Images are included in the document using an image element as described in Section 18 Images and Section 26 19 lt image gt They can
90. it is overwritten Use this method to generate a PDF file from an XML template where both files are disk based and no data is merged XML File to PDF File Data in File public void generate String templateFileName String pdfFileName String dataFileName templateFileName is the name of the file on disk which contains the template XML pdfFileName is the name of the file where the PDF file will be created If this file already exists it is overwritten dataFileName is the name of the file where XML data to be merged into the template is stored Use this method to generate a PDF file from an XML template merging data from a third file where all files are disk based XML Document to PDF Stream public void generate XmIDocument templateDoc Stream pdfStream xmlpdf user manual page 5 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 4 Usage www xmlpdf com 4 3 4 4 3 5 4 3 6 templateDoc is a System Xml XmIDocument object pdfStream is the name of the stream where the PDF file will be written The PDF is written to the stream at its current position The stream is not closed Use this call if you are already creating your XML using an XmlDocument object XML File to PDF Stream public void generate String templateFileName System IO Stream pdfStream templateFileName is the name of the file on disk which contains the template XML pdfStream is the name of the stream where the PDF file will be written Th
91. jects within Visual Studio by right clicking on the project and selecting Add reference or you can install it in the shared assembly area using the appropriate NET utility The examples which follow in the usage section detail how to create references to the DLL xmlpdf user manual page 4 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 4 Usage www xmlpdf com 4 1 4 2 4 3 4 3 1 4 3 2 4 3 3 CHAPTER 4 Usage Introduction This section describes how to use XMLPDF to generate a PDF file Examples are included for generation of a file from Visual Basic C and from an ASP page Hello world XML file The simplest example using XMLPDF is the HelloWorld xml file which contains this lt document gt lt block gt Hello World lt block gt lt document gt This is all the XML necessary to create a PDF file All features of the PDF such as page size font font size etc are set to default values This file is used in all the examples which follow API All documents are created using the generated method of the PDFDocument object Different arguments are used to distinguish the different generate methods as detailed here XML File to PDF File public void generate String templateFileName String pdfFileName templateFileName is the name of the file on disk which contains the template XML pdfFileName is the name of the file where the PDF file will be created If this file already exists
92. lement at the start of the XML document Page header element The lt page header gt element is used to set the page header which will appear in the PDF document from that point on The page header is conceptually the same as a table in that it has rows and cells The page header for this document looks like this lt page header space after lcom indent left 2 75cm indent right 1 5cm gt lt row gt lt cell align left font name helvetica font size 8 text color blue gt XMLPDF lt info field version flags independent gt lt info gt User Manual lt cell gt lt cell align middle font name helvetica font size 8 text color blue gt lt info field date flags MMMMM yyyy gt lt info gt lt cell gt lt cell align right font name helvetica font size 8 text color blue gt lt auto sequence get level 1 gt lt auto sequence get name level 1 gt lt cell gt lt row gt lt page header gt xmlpdf user manual page 29 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 12 Document Structure www xmlpdf com The page header is automatically repeated at the start of each page after it is defined This means that you should place the page header element before a new page element if you want the header to appear on the page after the new page element To change the page header simply insert another page header element into the document XML The page header will be changed from th
93. ment in XML and generate the document dynamically including populating fields in the document template from another source such as a database Text Formatting XMLPDF has powerful text formatting features including Alignment Text can be left aligned right aligned centered and justified Formatting Text can be displayed in bold talic underline superscript Text can be displayed in and subscript Kerning Text is automatically kerned so that where fonts support it the gap between characters changes for each character pair This results in text which looks more professional and is easier to read Pagination Text and tables are automatically split at page boundaries Widow Orphan control is provided so that a single line is never left at the bottom or top of a page Fonts All PDF viewers support 14 standard fonts defined by Adobe These include Helvetica Courier Times ZapfDingbats and Symbol plus bold italic and bold italic versions of Helvetica Courier and Times XMLPDF fully supports these fonts TrueType fonts are also fully supported These fonts are embedded in the document Adobe recommend that TrueType fonts should always be embedded Unicode TrueType fonts are fully supported allowing display of all Unicode characters supported by the font When TrueType font files are embedded in documents XMLPDF creates a subset of the font so that only information from the TrueType font file which is actually needed is in
94. mmers Guide November 2006 17 Lines and Boxes www xmlpdf com 17 1 17 2 CHAPTER 17 Lines and Boxes Drawing Boxes The boxes element is used to display one or more square boxes as typically found on a form which is designed to be completed by a person For example this is produced with this XML lt graphic gt lt boxes box width 12 box height 12 number 8 line width 1 gt lt graphic gt In the NET version of XMLPDF you can insert text into the boxes by placing it in the lt boxes gt element like this lt graphic gt lt boxes box width 12 box height 12 number 22 line width 1 gt THIS IS IN THE BOXES lt boxes gt lt graphic gt This produces this output THIS I S IN THE BOXES Multiple rows of boxes can be created using the number down attribute and filled by using lt br gt elements to split the lines like this lt graphic gt lt boxes box width 12 box height 12 number 30 line width 1 number down 2 gt THIS IS IN LINE ONE lt br gt THIS IS IN LINE TWO lt boxes gt lt graphic gt This produces this output THIS I S THIS I S IN LI IN LI Drawing Lines Lines can be drawn on the page using the lt segment gt element Each segment has an start point defined in by values x1 y1 and and end point defined by x2 y2 These x and y values are absolute coordinates in points with 0 0 being at the bottom left corner of the page For example this page as
95. n 1 0 encoding utf 8 gt lt document gt lt table space before 1cm width 40 block align center border width all 1 widths 20 30 padding all 2 gt lt header widths 20 30 padding all 2 gt lt row background gray 90 gt lt cell gt Store lt cell gt lt cell align center gt Date lt cell gt lt cell align right gt Quantity lt cell gt lt row gt lt header gt lt foreach iterator itr list sales_datatable gt lt row gt lt cell gt lt merge method itr stor_id gt lt cell gt lt cell align center gt lt merge method itr ord_date format dd mm yyyy gt lt cell gt lt cell align right gt lt merge method itr qty format N gt lt cell gt lt row gt lt foreach gt lt table gt lt document gt Key things to note in the template XML are a the lt foreach gt element has a list attribute which has a value equal to the logical name given to the recordset in the call to doc addNamedObject b the lt merge gt element has a method attribute which has a value which is the name of the iterator in this case itr followed by a followed by the field name in the recordset c the format attribute of the lt merge gt element is passed to a call to System Text StringBuilder AppendFormat so any value which is a valid format string for this method can be specified This produces testrecordset pdf showing all the records in the database www xmlpdf
96. nserted to keep the block and the following block or table together space before Sets the amount of white space which appears before the content of the block space after space required Sets the amount of white space which appears after the content of the block The space between two blocks is the space after of the first block plus the space before of the second block Sets the amount of space which must be present on the page for the block to be output If that amount of space is not available the whole block is moved to the next page This is useful to prevent headers being output by themselves at the bottom of the page width 12 6 2 Table element Specifies the width of the block This can be a fixed amount such as 12cm or a percentage of the page width such as 80 If the block is less than 100 of the page width it is aligned using the block align attribute The lt table gt element is used to place a table in the PDF document A table can contain text or images or other tables It may or may not have borders All of the attributes described in the preceding section on the block element can also be applied to the table element The following additional elements affect the way the table appears These are explained in detail in section Section 16 Tables Attribute Description widths Sets the widths of columns border width all border width inner border width outer border
97. nt www xmlpdf com xmlpdf user manual page 25 of 101 XMLPDF 5 5 7 Programmers Guide www xmlpdf com 12 3 12 4 12 5 November 2006 Document element After the XML processing instruction comes the lt document gt element This is the top level element and contains the whole document Attributes of the document element set overall characteristics of the document such as the page 12 Document Structure size and the page margins The following table summarises these attributes Attribute color space Description The defaults to rgb If you set it to emyk you can create a CMYK PDF file suitable for printing by a professional printer This requires that only CMYK images are used in creating the document XMLPDF does not currently support converting images from RGB to CMYK at runtime info title Sets the PDF document title which is displayed in the document summary dialog box in Adobe Acrobat info author Sets the PDF document author which is displayed in the document summary dialog box in Adobe Acrobat info subject Sets the PDF document subject which is displayed in the document summary dialog box in Adobe Acrobat margin left Sets the left margin for the whole document margin right Sets the right margin for the whole document margin top Sets the top margin for the whole document margin bottom Sets the bottom margin for the whole document page mode Controls the
98. nt in the data XML will be substituted into the document XML as if it were in the document XML in place of the lt merge gt element Example Given data XML like this lt data gt lt source element name cust name gt john smith lt source element gt lt source element name cust age gt 123 lt source element gt lt data gt and given document XML like this lt document gt lt block gt The customer s name is lt merge source element name cust name gt lt br gt The customer s age is lt merge source element name cust age gt lt block gt lt document gt This produces the following output in the PDF file The customer s name is john smith The customer s age is 123 There is no limitation to what elements can be merged from the data XML It is common usage to define a lt table gt element in the document XML and then merge multiple rows from a single lt source element gt element in the data XML Conditional processing Within the document XML you can use lt if gt and lt ifnot gt elements to control which parts of the document XML appear in the PDF file This is typically used when you don t know until the PDF is generated how much information you may have For instance if you know the customer name you might print it otherwise you might just print Dear Sir Madam The conditional processing built into XMLPDF lets you defer these decisions until the PDF is generated The values of each
99. nt of space across the table Column widths If column widths are not specified each column gets an even share of the available space Column widths can be specified with the widths attribute on the lt table gt element Column widths can be specified as percentages The following XML creates a table with one row and two cells in that row The first cell is 25 of the width of the table the second cell is 75 lt document lt table widths 25 75 border width all 0 01 border color all blue gt lt row gt lt cell gt this is cell 1 lt cell gt lt cell gt this is cell 2 lt cell gt lt row gt lt table gt lt document gt This produces a table like this this is cell 1 this is cell 2 xmlpdf user manual page 39 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables Column widths can be specified as absolute units such as points inches or centimeters The following XML creates a table with one row and two cells in that row The first cell is 200 points wide the second is 4cm wide lt document lt table widths 200 4cm border width all 0 01 border color all blue gt lt row gt lt cell gt this is cell 1 lt cell gt lt cell gt this is cell 2 lt cell gt lt row gt lt table gt lt document gt This produces a table looking like this this is cell 1 this is cell 2 Where absolute column widths are used the overall width of the table is determined by summing the width o
100. o is higher than the cell on the left lt cell gt lt row gt lt table gt 16 10 Newspaper layout By adding the attribute layout newspaper to the table element you can change the layout to be like a newspaper in that a table with multiple columns fills the left hand column from top to bottom then the next column from top to bottom and so on until all columns are filled A table which has this formatting should have all cells contained in one row element The number of columns in the table is determined from the widths attribute For example if we have a table five cells containing A B C D E and we have two columns when we apply newspaper formatting we get the cells laid out like this A D B E C The same effect works for nested newspaper tables so if we have an outer table with one row holding two cells the first column of the outer table can have a normal layout table in and the second can have a newspaper layout table like this Normal Table Newspaper Table A B A D C D B E E C When a newspaper layout table is split over more than one page the columns cells fill the first page completely then start to fill the second page as shown here Newspaper Layout table split over two pages A D B E C F www xmlpdf com xmlpdf user manual page 44 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables Newspaper Layout table split over two pages G V H W I X J Y K Z L 0 M 1 N 2 O 3 P 4 Q 5 R
101. only to set the width of the last column in a table to the width of the table less the total width of all preceding columns This works only for the last column in a table Note that if cell widths are not specified for tables space will be allocated evenly to all columns Actual width of text and images is not considered This is the opposite of what HTML does but in keeping with making PDF documents maintain the same format when printed with different data Font sizes are always expressed in points with no units This means font size 10 5 will make the font size 10 5 points xmlpdf user manual page 19 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 10 Units of Measurement 10 2 10 3 10 4 10 5 www xmlpdf com Page sizes The size of the page in the PDF document is set using the page size attribute on the lt document gt element Valid values for the page size are Page Size Width mm Height mm Width Height points points A3 420 297 1191 842 A4 210 297 596 842 AS 148 210 420 842 LETTER 216 279 612 792 LEGAL 216 356 612 1008 TABLOID 279 432 790 1224 EXECUTIVE 190 254 539 720 The default page size is A4 Assuming you want a page which is LEGAL size you would do this lt document page size legal gt lt block gt Hello World lt block gt lt document gt Custom page sizes Custom page sizes can be set using the height and width attributes on the lt document gt element To get a page
102. or student itr root course itr xpath students student age gt 30 gt lt block indent left 6cm gt Student Name lt merge root student itr xpath name gt lt block gt lt foreach gt lt foreach gt The XPath expression students student age gt 30 will result in a collection of XML nodes which contains only students with an age attribute greater than or equal to 30 To list all the students 30 or older by course we use the template coursestudents30 xml This produces the a PDF file coursestudents30 pdf containing only older students XPath Functions XMLPDF lets you perform calculations using XPath expressions such as sum item qty to calculate values for insertion into the PDF file The following example uses some data about customers and orders orders xml and the template orderlist xml to produce a list of orders by customer with sub totals for each order and customer The template uses nested lt foreach gt elements to list the items on each order for each customer After the lt foreach gt element which lists the items on each order we have a row in the table which displays totals for that order The total cost of the order is calculated using this element lt merge root order itr xpath sum item qty gt The xpath attribute specifies an XPath expression which invokes the XPath sum function This sums the qty attribute of all item nodes under the current record of the ord
103. ostics Trace 59 21 5 Logging to Multiple Destinations 59 Merging Data 60 22 1 Basics 60 22 2 Conditional processing 60 22 3 Merging Fields from XML using XPath expressions 61 22 4 Integration with ADO NET 67 Links 69 23 1 Basics 69 23 2 Merging the URL Value 70 Positioning Output 71 24 1 Absolute Positioning 71 24 2 Relative Positioning 71 Creating a Table of Contents 72 25 1 Creating a Table Of Contents 72 25 2 Table Of Contents Page Layout 73 wwwxmlpdf com XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference 75 26 1 26 2 26 3 26 4 26 5 26 6 26 7 26 8 26 9 26 10 26 11 26 12 26 13 26 14 26 15 26 16 26 17 26 18 26 19 26 20 26 21 26 22 26 23 26 24 26 25 26 26 26 27 26 28 26 29 26 30 26 31 26 32 26 33 26 34 26 35 26 36 26 37 26 38 26 39 26 40 26 41 26 42 lt auto sequence get gt 75 lt auto sequence get name gt 75 lt auto sequence inc gt 76 lt begin page number group gt 77 lt boxes gt 77 lt block gt 79 lt br gt 80 lt cell gt 81 lt condition gt 82 lt conditions gt 82 lt data gt 82 lt define sequence gt 82 lt document gt 84 lt forward reference gt 85 lt font gt 85 lt fonts gt 85 lt graphic gt 86 lt header gt 86 lt image gt 87 lt images gt 88 lt if gt 88 lt ifnot gt 88 lt info gt 89 lt link gt 89 lt merge gt 89 lt new page gt 90 lt next page gt 90 lt page footer gt 90 lt page header gt
104. pace between the border of a cell and the text or image in it text color Specifies the foreground color of text of cells in the row See Section 15 Colors The following nested table shows columns with fill color values of red and blue and text color white xmlpdf user manual page 92 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 33 26 34 Attribute Description red blue Rows are used in lt table gt lt header gt lt page header gt and lt page footer gt elements Rows contain cells which contain text or images See Section 26 8 lt cell gt Any attribute set on a row will be inherited by the cells in that row unless overridden by an attribute specified on the cell itself lt sequence get gt Summary of attributes Attribute Description name Specifies the name of the sequence to get the value from This element is used to get current value of a sequence defined by a define sequence element as described in Section 26 12 lt define sequence gt This gets the current value of the element and inserts it into the document The sequence value is also incremented lt segment gt Summary of attributes Attribute Description xl x coordinate of start point of line x2 x coordinate of end point of line yl y coordinate of start point of line y2 y coordinate of end point of line width width of the lin
105. page 40 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables www xmlpdf com 16 4 16 5 To print borders on all of the table use the border with all attribute on the table element To print borders on all sides of a single row use the border with all attribute on the row element To print a border on just the bottom of one cell use border width bottom on that cell Rounded Corners A cell not a table or row can have borders with rounded corners This is done by defining corners round on the cell element and specifying the radius of the curve using the corner radius attribute The following example shows a cell with rounded borders which contains a nested table with other text in The XML for this is lt table width 70 block align center gt lt row gt lt ce corners round border width all 0 001 corner radius 6 padding all 4 border color all green fill color eeee33 gt lt table widths 15 80 gt lt row gt lt cell gt Name lt cell gt lt ce border width bottom 01 gt lt cell gt lt xrow gt lt row gt lt cell gt Address lt cell gt lt cell border width bottom 01 gt lt cell gt lt row gt lt table gt lt cell gt lt xrow gt lt table gt Line styles By default border lines are solid The style of a border can be changed using the following attributes border style all border style inner border style outer border style
106. ption text color Specifies the foreground color of text the cell See Section 15 Colors The following nested table shows columns with fill color values of red and blue and text color white red blue A cell can contain text images a graphic or nested table See Section 16 Tables and Section 18 Images for examples of how to place text tables and images inside cells 26 9 lt condition gt Summary of attributes Attribute Description name Specifies the name of the condition Conditions are named so they can be referred to by name in lt if gt elements See Section 22 2 Conditional processing value Specifies the value of the condition This must be true or false See Section 22 2 Conditional processing Conditions are used when merging data XML to include or exclude parts of the document template Conditions are defined in the data XML using condition elements and the template XML uses if and ifnot elements to surround parts of the template XML As the PDF document is created the if and ifnot elements in the template XML are compared with the conditions in the data XML and parts of the document include or excluded as appropriate See Section 22 Merging Data 26 10 lt conditions gt This element is a container for lt condition gt elements It should appear only in data XML and not in document template XML See Section 22 2 Conditional processing for an ex
107. r 2006 6 Visual Basic Example www xmlpdf com Imports System Imports xmlpdf Module Modulel Sub Main Dim doc As New PDFDocument Dim args As String Command Split ToCharArray doc generate args 0 args 1 End Sub End Module 5 Compile Select Build Build Solution from the menu to compile the project 6 Run Either configure the command line arguments using the Project Properties dialog or execute the program from the command line like this vbconsole helloworld xml helloworld pdf This will create the file helloworld pdf xmlpdf user manual page 14 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 7 ASP NET Example www xmlpdf com CHAPTER 7 ASP NET Example The following is the code for a web page which will read the file hello xml and return the PDF file to the browser lt Page Language C gt lt Import NameSpace System I0 gt lt s Import NameSpace System Net gt lt Import NameSpace xmlpdf gt PDFDocument doc new PDFDocument Response Clear Response ContentType application pdf string template d xmlpdf hello xml MemoryStream memory new MemoryStream doc generate template memory Response AddHeader content length System Convert ToString memory Length Response BinaryWrite memory ToArray Response Flush Response End oe gt The following are the key things to note in this code Response
108. reated Any amount of data can be merged from single fields to entire tables See Section 22 Merging Data for more information Styles A style can be defined and then automatically applied to text or images making it simple to provide all the elements of a PDF document with a consistent look It is easy to change the look of an entire document by changing a single style See Section 19 Styles for more information Links HTTP hyperlinks can be placed in the PDF file so that users can click and open a browser window at the linked address Click on the www xmlpdf com to see this in action See Section 23 Links for more information Sequences Numbered sequences can be automatically allocated and displayed with alphabetic numeric or roman numeral formats xmlpdf user manual page 3 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 3 Installation www xmlpdf com CHAPTER 3 Installation This chapter contains instructions on installing the XMLPDF library for the NET development environment The XMLPDF library is distributed as a Windows Installer file Run this installer to install the XMLPDF DLL s and a sample application written in Visual Basic NET The source code for this sample program is included The installation include two DLLs XMLPDF DLL is compiled using the 1 0 Framework SDK XMLPDF11 DLL is compiled using the 1 1 Framework SDK Once you have downloaded the DLL you can either reference it from pro
109. referred to by the uid value will be inserted into the document This is used to create a cross reference to an outline entry The outline entry must have a unique uid value and the xref element then has the uid of the outline entry it refers to This document has an outline entry called tables We can create a cross reference to this entry using this XML See lt xref uid tables gt which gives the following result See Section 16 Tables or we can override the text displayed like this See lt xref uid tables text section on tables gt which gives the following result See section on tables xmlpdf user manual page 101 of 101
110. ributes 26 21 lt if gt Summary of attributes Attribute Description condition Specifies the name of condition which is tested to see if the content of this element should be included in the PDF file The if element is used to control what parts of a document should be included in the PDF file at the time of generation This allows you to include or exclude parts of the document template XML depending on data values specified in the data XML The if element contains other block level elements such as lt table gt lt block gt and other lt if gt elements See Section 22 2 Conditional processing for an example of this element 26 22 lt ifnot gt Summary of attributes Attribute Description condition Specifies the name of condition which is tested to see if the content of this element should be included in the PDF file The ifnot element is used to control what parts of a document should be included in the PDF file at the time of generation This allows you to include or exclude parts of the document template XML depending on data values specified in the data XML The ifnot element contains other block level elements such as lt table gt lt block gt and other lt if gt elements See Section 22 2 Conditional processing for an example of this element www xmlpdf com xmlpdf user manual page 88 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference 26 23 lt info gt www xmlpdf com
111. ror handler writes messages to the console Messages are displayed in various circumstances including when an invalid attribute is found when a reference is made to a font or image file which cannot be found when an formatting error occurs such as defining the widths of columns in table which exceed the available width To change the level of information logged you can set the level on the logging object to one of the values defined in the xmlpdf logging Level object Possible levels of logging which can be set are SEVERE WARNING INFO CONFIG FINE FINER FINEST For example to set the logger to log only messages which are SEVERE or worse do this using System using xmlpdf using xmlpdf logging public class Create static void Main string args PDFDocument doc new PDFDocument Logger getLogger setLevel Level SEVERE Logging to File To log messages to a file create an xmlpdf logging FileHandler object and then tell the logger to log to this object This example logs to the file log txt but any valid file name can be used using System using xmlpdf using xmlpdf logging public class Create static void Main string args Logger getLogger setLevel Level SEVERE clearHandlers addHandler new FileHandler log txt The FileHandler object synchronises access to the log file If you omit the clearHandlers call shown in the above example log records will be written to the
112. s element is a container for lt boxes gt and lt segment gt elements and should appear only in document template XML See Section 26 5 lt boxes gt for an example of this element This element has no attributes lt header gt Summary of attributes Attribute Description widths Sets the widths of columns border width all Sets the widths of the header border border width inner border width outer border width top border width bottom border width left border width right border color all Sets the color of header border See border color inner Section 15 Colors border color outer border color top border color bottom border color left border color right padding all Sets cell padding Padding is the amount of space padding inner between the border of a cell and the text or image in it padding outer padding top padding bottom padding left padding right The header element is used to define a table header It must appear inside a lt table gt element The header element is very similar to a lt table gt element It contains lt row gt elements which in turn contain lt cell gt elements The table header is repeated at each time the table is broken by a page break This is an example of a header element lt table border width all 1 indent left 3cm indent right 3cm padding all 2 gt lt header fill color blue gt lt row gt lt cell gt header one lt cell gt lt cell gt header
113. sers modifying the document set the deny modify attribute to true on the document element To prevent users copying content from the document using cut and paste set the deny extract attribute to true on the document element Example The following example creates a document which cannot be printed by a normal user No user password is specified so anyone can open the document Someone knowing the owner password own can take ownership of the document and remove all restrictions xmlpdf user manual page 56 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 20 Document Security lt document deny print true owner password own gt lt images gt lt image file name dolphins png image name dol gt lt images gt lt table padding all 2 widths 30 70 gt lt row gt lt cell gt lt show image image name dol gt lt cell gt lt cell gt lt show image image name dol gt lt cell gt lt row gt lt table gt lt document gt www xmipdf com xmlpdf user manual page 57 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 21 Error Handling www xmlpdf com 21 1 21 2 21 3 CHAPTER 21 Error Handling Basics The XMLPDF library associates an error handler with the library as a whole Generally this error handler will log a message and not throw an exception The XMLPDF Logger object is a singleton which is retrieved using a call to the xmlpdf logging Logger getLogger method The default er
114. ss h1 appear in 14 point helvetica It is also possible to combine the two notations To create a style which applied to all blocks i e name block which have a class of code i e name code create the style with the name block code Attributes applied by a style are overridden by attributes which are defined on the element the style is being applied to xmlpdf user manual page 98 of 101 XMLPDF 5 5 7 Programmers Guide www xmlpdf com 26 40 lt table gt November 2006 26 Reference Summary of attributes Attribute align Description Specifies the text alignment to use for this table This specifies the default alignment of text within the table not the alignment of the table on the page Alignment of the table on the page is specified using the block align attribute as stated below See Section 13 2 Horizontal alignment block align Specifies how a table which is less than 100 of the page width is aligned on the page This can be left right or center class font name font size indent left Specifies the class of this block so that styles which match the class will automatically be applied See Section 19 Styles Specifies the font face of this block See Section 11 Fonts Specifies the font size in points of this block See Section 11 Fonts Specifies the left indentation of the text Indentation is the amount of space between the margin of the p
115. t t reach gt This creates an iterator which applies to the list of nodes identified by the XPath expression coursedata course b A lt merge gt element to get the value of the lt code gt element within the node list associated with the iterator course itr lt merge root course itr xpath code gt The root attribute tells XMLPDF to apply the XPath expression specified by the xpath attribute to the current node in the course itr list of nodes If this was not specified the XPath expression would be applied from the top node in the data XML XMLPDF applies the XPath expression specified on the lt foreach gt element to get a list of XML nodes from the data XML Then the XPath expression of any lt merge gt elements within the lt foreach gt element are evaluated once for each node in the list This creates courselist pdf Nested Loops XMLPDF can iterate over a group of XML nodes using the lt foreach gt element Within that loop we can specify an inner loop either over an unrelated list of records or over a list which depends on the outer list The coursedata xml file specifies a list of courses and for each course specifies a list of students taking the course like this xmlpdf user manual page 63 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data lt coursedata gt lt course gt lt code gt COMP 101 lt code gt lt name gt Introduction to Computer Science lt name gt lt students gt
116. t like this Dear john smith Merging Fields from XML using XPath expressions This section describes how to merge values contained in the data XML into the document template using XPath expressions iterate over collections of XML elements in the data XML use nested lt foreach gt elements to iterate over XML nodes use XPath expressions to select a subset a collection of XML nodes This articles describes how to use XPath expressions to get values from the data XML merged into the PDF file created based on an XML document template The data XML used in this article is contained in the file coursedata xml Selecting the Value of a Single Node To merge a single value from the data XML use the xpath attribute of the lt merge gt element In this example the XPath expression specified by the xpath attribute is evaluated from the root node of the data XML The expression must return a single value xmlpdf user manual page 61 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 22 Merging Data www xmlpdf com 22 3 2 22 3 3 The coursedata xml file specifies a value for the term start date like this lt coursedata gt lt term start gt 10 August 2003 lt term start gt TR To select this value and merge it into the PDF use the template coursedate xml This template contains a lt merge gt element which defines an XPath expression to merge the required data value like this lt merge xpath coursedata term s
117. t page gt Summary of attributes Attribute Description orientation Specifies the orientation of the next page and all following pages until another lt next page gt element is found This attribute is optional If it appears its value must be portrait or landscape margin left Sets the left margin for the next and following pages margin right Sets the right margin for the next and following pages margin top Sets the top margin for the next and following pages margin bottom Sets the bottom margin for the next and following pages This element sets parameters for the next page It does not cause a page break this is done using the lt new page gt element lt page footer gt The page footer element defines a table which is repeated at the end of each page from the point at which it appears The page footer can be changed at any point by putting another page footer element in the XML The page footer element has the same attributes and contents as a lt table gt element See Section 26 40 lt table gt for more details In addition to the normal table attributes the first page and last page attributes can also be used to limit the range of pages on which this page footer will be displayed lt page header gt The page header element defines a table which is repeated at the start of each page from the point at which it appears xmlpdf user manual page 90 of 101 XMLPDF 5 5 7 Programmers Guide November
118. tart gt XMLPDF applies this XPath expression to the data XML and returns the single value 10 August 2003 which is inserted into the PDF file like coursedate pdf If no node is found which matches the XPath expression an error message will be produced similar to the following No node found which matches XPath expression coursedata term start2 See the previous chapters for information on how to set the error logging level and log errors to file More Complex Expressions Any XPath expression which returns a single node can be used in the xpath attribute of a lt merge gt element XMLPDF for NET passes the expression and the data to the XmlDocument SelectSingleNode method so any XPath expression which is accepted by this method will work XMLPDF for Java passes the expression and the data to the XPathAPI selectNodelterator method so any XPath expression which is accepted by this method will work The coursedata xml file specifies the names of tutors like this lt coursedata gt lt tutor term 1 gt A Stone lt tutor gt lt tutor term 2 gt A Rock lt tutor gt lt coursedata gt We can use an XPath expression to select the name of the tutor for term 1 To select this value and merge it into the PDF use the template coursetutor xml This template contains a lt merge gt element which defines an XPath expression to merge the required data value like this lt merge xpath coursedata tutor term 1 gt
119. the alignment of text within the block not the alignment of the block on the page Alignment of the block on the page is specified using the block align attribute as stated below See horizontal alignment block align Specifies how a block which is less than 100 of the page width wide is aligned on the page This can be left right or center class Specifies the class of this block so that styles which match the class will automatically be applied See Section 19 Styles font name Specifies the font face of this block See Section 11 Fonts font size Specifies the font size of this block See Section 11 Fonts indent left Specifies the left indentation of the text Indentation is the amount of space between the margin of the page and the edge of the text image or table The distance from the left edge of the page to the content is the left margin value from the document element plus the indent left value of the block indent right Specifies the right indentation of the text Indentation is the amount of space between the margin of the page and the edge of the text image or table The distance from the right edge of the page to the content is the right margin value from the document element plus the indent right value of the block keep together keep with next If set to true will prevent the block being split if it appears near the end of a page and will not fit If keep
120. thing like this lt xml version 1 0 encoding UTF 8 gt lt document gt lt image image name butterfly file name butterfly svg gt lt show image image name butterfly gt lt document gt That s all the XML necessary to convert an SVG image into a PDF SVG images are treated the same as any other image in XMLPDF They can be inserted into tables and scaled using the scale width and scale height operators Also like other images the file name attribute specified can be a URL so you can load images directly from the web like this xmlpdf user manual page 53 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 18 Images lt xml version 1 0 encoding UTF 8 gt lt document gt lt image image name skew file name http www croczilla com svg skew01 xml gt lt show image image name skew gt lt document gt www xmlpdf com xmlpdf user manual page 54 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 19 Styles www xmlpdf com 19 1 CHAPTER 19 Styles Basics XMLPDF supports the creation of styles which define attributes to be applied to all elements which match the style name A style defines a set of attributes and their values plus a name which is used to determine which elements the style applies to This is a sample style lt style name block font name times font size 12 space after 25cm align justify indent left 1lcem gt This style is used throughout this document
121. this block See Section 11 Fonts font size Specifies the font size in points of this block See Section 11 Fonts indent left Specifies the left indentation of the text Indentation is the amount of space between the margin of the page and the edge of the text image or table The distance from the left edge of the page to the content is the margin left value from the document element plus the indent left value of the block indent right Specifies the right indentation of the text Indentation is the amount of space between the margin of the page and the edge of the text image or table The distance from the right edge of the page to the content is the margin right value from the document element plus the indent right value of the block www xmlpdf com xmlpdf user manual page 27 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 12 Document Structure Attribute Description keep together If set to true will prevent the block being split if it appears near the end of a page and will not fit If keep together is false the default the block will be split over two pages if it does not fit in the available space at the end of the page If keep together is true the block will not be split and will be moved completely to the start of the next page keep with next If set to true will keep the block on the same page as the next block level element If necessary a page break will be i
122. to place a block of text in the PDF document The block used to create this sentence looks like this lt block gt The amp lt block amp gt element is used to place a block of text in the PDF document The block used to create this sentence looks like this lt block gt lt br gt This element is used within a block element or cell element to create a line break For example to separate to lines in a block use XML like this lt block gt this is line 1l lt br gt lt br gt this is line 2 lt block gt This produces a line break like this this is line 1 this is line 2 There are no attributes on the br element xmlpdf user manual page 80 of 101 XMLPDF 5 5 7 Programmers Guide www xmlpdf com 26 8 lt cell gt November 2006 26 Reference Summary of attributes Attribute align Description Specifies the text alignment for text which appears inside the cell See Section 13 2 Horizontal alignment background gray Specifies gray shading which appears in the background of the cell This is expressed as a percentage between 0 and 100 as in background gray 20 Smaller numbers are darker The following nested table shows columns with background gray values of 20 40 and 60 respectively gt i border color all border color inner border color outer border color top border color bottom border color left border color right Sets the color of cell borders If colors are not specif
123. together is false the default the block will be split over two pages if it does not fit in the available space at the end of the page If keep together is true the block will not be split and will be moved completely to the start of the next page If set to true will keep the block on the same page as the next block level element If necessary a page break will be inserted to keep the block and the following block or table together space before Sets the amount of white space which appears before the content of the block space after Sets the amount of white space which appears after the content of the block The space between two blocks is the space after of the first block plus the space before of the second block space required Sets the amount of space which must be present on the page for the block to be output If that amount of space is not available the whole block is moved to the next page This is useful to prevent headers being output by themselves at the bottom of the page xmlpdf user manual page 79 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 7 Attribute Description width Specifies the width of the block This can be a fixed amount such as 12cm or a percentage of the page width such as 80 If the block is less than 100 of the page width it is aligned using the block align attribute The lt block gt element is used
124. top border style bottom border style left border style right The value of the border style XXX element defines the style to use for that border Valid styles are solid dashed and dotted with solid being the default This table has solid borders solid This table has dotted borders dotted xmlpdf user manual page 41 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 16 Tables www xmlpdf com 16 6 16 7 16 8 This table has dashed borders dashed Dotted and dashed borders can also be curved Here is the example from the previous section using dashed borders Border colors By default border colors are black The color of a border can be changed using the following attributes border color all border color inner border color outer border color top border color bottom border color left border color right The value of the border color XXX element defines the color to use for that border For possible values see Section 15 Colors Cell padding Padding is the space inside a cell between the cell border and the contents of the cell This table has a cell which contains some text There is no padding Padding is the space inside a cell between the cell border and the contents of the cell This table has the attribute padding all 4 so the space between the cell border and its content is greater than in the previous example Padding is the space inside a cell between the cell border and t
125. two lt cell gt lt row gt lt header gt lt row gt lt cell gt one lt cell gt lt cell gt two lt cell gt lt row gt lt table gt xmlpdf user manual page 86 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference This produces the following table two Note that the number of columns in a table header can be different to the number of columns in the table body 26 19 lt image gt Summary of attributes Attribute Description anti aliasing Specifies whether the PDF reader will apply anti aliasing to the image Anti aliasing removes jagged borders and lines especially when the image is viewed at high zoom levels By default anti aliasing is on The following two images are loaded from the same file the one on the left has anti aliasing false the one on the right uses the default setting directory Specifies the name of a directory in which to look for the named file This attribute is optional If it is used then the directory name is prepended to the file name value in order to make a full path to the image file dpi A value which defines the image dots per inch value typically 72 or 300 This applies only to JPEG and SVG images This value changes the size of the image when it is stored in the PDF file The default value is the value stored in the image file file name Specifies the name of the file which contains the image From version 3 0 this can b
126. used to insert blank space before a block of text as in lt document font name helvetica font size 15 18 gt lt block space before 3cm gt Hello World lt block gt lt document gt xmlpdf user manual page 33 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 13 Text Formatting www xmlpdf com 13 8 13 9 13 10 13 11 13 12 13 13 Forcing space before The space before and space after attributes control the amount of blank space before a block of text or table By default the space before attribute is ignored at the start of a page This is because space before is usually used to separate text from the previous item on the page and at the start of a new page there is no previous item If you really want blank space at the start of a page you can force XMLPDF to obey the space before attribute by setting force space before to true This is done for instance on the cover page of this document to insert blank space before the XMLPDF Library header Indent left The indent left attribute is used to change the amount of space between the left margin of the page and the start of the content This block has indent left set to 3cm This block has indent left set to 6cm Indent right The indent right attribute is used to change the amount of space between the right margin of the page and the end of the content This block has indent right set to 6cm and is longer so we can see the edge This blo
127. we change the level to 2 as in lt auto sequence get level 2 gt we would insert the string 1 1 into the document The maximum level is 10 lt auto sequence get name gt Summary of attributes Attribute Description level The level of the hierarchy from which to retrieve the name uid The unique identifier which can then be used to generate a cross reference to this heading by using the Section 26 42 lt xref gt element outline The should be set to true if you want the heading retrieved to appear in the document outline xmlpdf user manual page 75 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 3 XMLPDF automatically maintains a document outline which is used to number headings and subheadings and to generate the outline which Acrobat displays on the left side of the screen Use of this feature is optional Each heading in the document is created using an auto sequence inc element which defines the heading at a given level in the outline hierarchy and increments the current heading number at the level specified The auto sequence get element retrieves the current heading name not number for the specificied level For example at the start of the document we might call the first chapter Introduction Because this is a chapter level heading its level attribute will be 1 Below the Introduction we want a second level header called Overview This is done as
128. y iterating over this collection using a lt foreach gt element For example if we have the following content lt auto sequence inc level 1 name Introduction gt lt auto sequence get name level 1 outline true gt lt block gt the introduction text lt block gt lt auto sequence inc level 1 name Advanced gt lt auto sequence get name level 1 outline true gt lt block gt the advanced text lt block gt This creates two outline entries and two entries in the table of contents collection which is called contents We can then iterate over this collection to output the table of contents in the same way we can iterate over any other collection of objects Each entry in the collection has the following fields number the number of the outline entry which created this table of contents entry such as 1 2 text the text of the outline entry which created this table of contents entry page the page number the outline entry which created this table of contents entry appears on contents the collection of lower level table of contents entries created from outline entries which are children of the current entry xmlpdf user manual page 72 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 25 Creating a Table of Contents www xmlpdf com Given this collection of entries we can use XML like this to iterate over the collection and create the table of contents lt toc gt lt insert some text before the table
129. y of attributes Attribute Description font name The name by which the font will be known in the document This is used when specifying the font to be used on block and other elements which contain text For the standard Adobe fonts this must be one of the values show in the standard font names table For TrueType fonts this can be any value assigned by the writer of the XML directory Specifies the name of a directory in which to look for the named file This attribute is optional If it is used then the directory name is prepended to the font file value in order to make a full path to the font file font file Specifies the path of the font file unicode If the font contains and you want to use characters above U 00FF specify unicode true so that XMLPDF will correctly process the font Characters used from a Unicode fonts are always embedded in the document To use a TrueType font you have to tell XMLPDF about the font before you can use it This is done by placing a lt font gt element into the lt fonts gt element near the start of the document lt fonts gt This element is a container for lt font gt elements and should appear only in document template XML See Section 11 Fonts for an example of this element xmlpdf user manual page 85 of 101 XMLPDF 5 5 7 Programmers Guide November 2006 26 Reference www xmlpdf com 26 17 26 18 This element has no attributes lt graphic gt Thi

Download Pdf Manuals

image

Related Search

Related Contents

Chapter 1 VisionDTV PCI  Fujifilm DVD-RW 8cm 2,8GB  Manual de Instalação do Token  Conexión y operación de PICStart Plus A  N177023 man drill drivers DCD931 Euro.indd  Flex® reagent cartridge DBIL  Citrix Technical Support: Brief Troubleshooting Guide  

Copyright © All rights reserved.
Failed to retrieve file