### Ordered List Example (Decimal) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/list_style/list_style_type/list/list_style_type_list01/list_style_type_list01.html Renders an ordered list with 'decimal' markers. ```html 1. Coffee 2. Tea 3. Coca Cola ``` -------------------------------- ### HTML Pipeline Context Setup Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/doc/example/default-setup.html Demonstrates setting up the HtmlPipelineContext and configuring it with a default HTML tag processor factory for interpreting HTML tags. ```java HtmlPipelineContext htmlContext = new HtmlPipelineContext(); htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory()); ``` -------------------------------- ### Unordered List Example (Circle) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/list_style/list_style_type/list/list_style_type_list01/list_style_type_list01.html Renders an unordered list with 'circle' markers. ```html * Coffee * Tea * Coca Cola ``` -------------------------------- ### Extended HTML/CSS Processing Setup (Java) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/snippets/headers_noroottag_snippet.html This setup provides advanced control over HTML and CSS processing. It allows customization of tag processors, CSS resolution, and other worker configurations before parsing. ```java // Create a TagProcessor DefaultTagProcessorFactory htmlTagProcessorFactory = (DefaultTagProcessorFactory) new Tags().getHtmlTagProcessorFactory(); // if needed override tag that you don't want to parse to DummyTagProcessor htmlTagProcessorFactory.addProcessor("img", new DummyTagProcessor()); htmlTagProcessorFactory.addProcessor("link", new DummyTagProcessor()); // Create a fresh configuration and set needed configuration objects. XMLWorkerConfigurationImpl config = new XMLWorkerConfigurationImpl(); // Attach the default CSS to a new CSSResolver CssFile defaultCSS = new XMLWorkerHelper().getDefaultCSS(); StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(); cssResolver.addCssFile(defaultCSS); // attach more CSS files if needed cssResolver.addCssFile(otherCssFile); // set the TagProcessorFactory config.tagProcessorFactory(htmlTagProcessorFactory).cssResolver(cssResolver) .acceptUnknown(true); // create a document final Document doc = new Document(); doc.setPageSize(PageSize.A4); // create writer PdfWriter writer = PdfWriter.getInstance(doc, outputStream); writer.setPageEvent(new WatermarkEvent()); // set margins for first page float margin = CssUtils.getInstance().parsePxInCmMmPcToPt("8px"); doc.setMargins(margin, margin, margin, margin); // OPEN the document ! doc.open(); config.document(doc).pdfWriter(writer); // create the worker final XMLWorker worker = new XMLWorkerImpl(config); // attach an ElementHandler worker.setDocumentListener(new ElementHandler() { public void addAll(final List arg0) throws DocumentException { for (Element e : arg0) { doc.add(e); } } public void add(final Element e) throws DocumentException { doc.add(e); } }); // Set the worker in the parser and start parsing XMLParser p = new XMLParser(worker); p.parse(new StringReader(content)); writer.close(); ``` -------------------------------- ### Build Asian Font Jars Source: https://github.com/itext/itextpdf/blob/develop/BUILDING.md Execute this command to build the Asian font jars. Maven must be installed. ```bash $ mvn clean install -f itextpdf/itext-asian.pom | tee mvn.log ``` -------------------------------- ### Build iText with All Profiles Source: https://github.com/itext/itextpdf/blob/develop/BUILDING.md Use the 'all' profile to generate source and javadoc jars in addition to the main itextpdf jar. Maven must be installed. ```bash $ mvn clean install -P all -Dmaven.test.skip=true | tee mvn.log ``` -------------------------------- ### Build Hyphenation Jar Source: https://github.com/itext/itextpdf/blob/develop/BUILDING.md Run this command to build the hyphenation jar. Maven must be installed. ```bash $ mvn clean install -f itextpdf/itext-hyph-xml.pom | tee mvn.log ``` -------------------------------- ### Build iText Jar with Maven Source: https://github.com/itext/itextpdf/blob/develop/BUILDING.md Run this command to generate the itextpdf jar without running tests. Maven must be installed. ```bash $ mvn clean install -Dmaven.test.skip=true | tee mvn.log ``` -------------------------------- ### Ordered List Example (Lower Alpha) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/list_style/list_style_type/list/list_style_type_list01/list_style_type_list01.html Renders an ordered list with 'lower-alpha' markers. ```html 3. Coffee 4. Tea 5. Coca Cola ``` -------------------------------- ### ID Selector with Element Type (Another Example) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/selector/css3-modsel-15/css3-modsel-15.html Applies a lime background to list items with the ID 't3'. Similar to the previous example, it shows specificity by combining element and ID selectors. ```css li#t3 { background-color : lime } ``` -------------------------------- ### Ordered List Example (Upper Roman) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/list_style/list_style_type/list/list_style_type_list01/list_style_type_list01.html Renders an ordered list with 'upper-roman' markers. ```html 2. Coffee 3. Tea 4. Coca Cola ``` -------------------------------- ### Run iText Tests with Dependencies Source: https://github.com/itext/itextpdf/blob/develop/BUILDING.md This command runs the tests, requiring Ghostscript and ImageMagick to be installed. Ensure the paths to 'gs' and 'compare' are correctly provided. ```bash $ mvn clean install -Dmaven.test.failure.ignore=false -DgsExec=$(which gs) -DcompareExec=$(which compare) | tee mvn.log ``` -------------------------------- ### Default XMLWorker Setup Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/doc/example/default-setup.html This snippet shows the default configuration for XMLWorker, setting up the HTML context, CSS resolver, and the pipeline for parsing HTML to PDF. ```java HtmlPipelineContext htmlContext = new HtmlPipelineContext(); htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory()); CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true); Pipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer))); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(worker); p.parse(HTMLParsingProcess.class.getResourceAsStream("/html/walden.html")); ``` -------------------------------- ### CSS Font Size with Percentages Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/text_layout/perc002/perc002.html Shows how to set font size using percentages in CSS. This example tests if a 1% font size is correctly rendered relative to its parent. ```css #reference { font: 2px/1em FreeMono; } #parent { font: 200px/5px FreeMono; } #test { font-size: 1%; } ``` -------------------------------- ### Parse HTML to PDF with Default Setup Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/doc/example/xmlworker-helper-001.html This snippet demonstrates the default method for parsing an HTML file into a PDF document using XMLWorkerHelper. It requires the Document, PdfWriter, and FileOutputStream classes. ```Java Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("results/walden1.pdf")); document.open(); XMLWorkerHelper.getInstance().parseXHtml(writer, document, HTMLParsingDefault.class.getResourceAsStream("/html/walden.html"), null); document.close(); ``` -------------------------------- ### Quick HTML to PDF Conversion (Java) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/snippets/index_anchor_snippet.html This snippet demonstrates the basic usage of XMLWorker for converting an HTML file to a PDF document. It requires minimal setup and is suitable for straightforward conversions. ```java // create a document to write to final Document doc = new Document(); PdfWriter.getInstance(doc, new FileOutputStream("out.pdf")); // make sure it's open doc.open(); // read the html from somewhere BufferedInputStream bis = new BufferedInputStream(new FileInputStream("snippet.html")); // parse and listen for elements to add to the document helper.parseXHtml(new ElementHandler() { public void addAll(final List currentContent) throws DocumentException { for (Element e : currentContent) { doc.add(e); } } public void add(final Element e) throws DocumentException { doc.add(e); } }, new InputStreamReader(bis)); doc.close(); ``` -------------------------------- ### Service Cookie Management Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/div/complexDivPagination01/complexDiv_files/sh088.htm Manages service-related cookies, including getting, setting, clearing, and retrieving all key-value pairs. It also provides a way to get all cookies. ```javascript (function(d,e,g){var c,l=d.util,j=4294967295,b=new Date().getTime();function h(){return((b/1000)&j).toString(16)+("00000000"+(Math.floor(Math.random()*(j+1))).toString(16)).slice(-8);}function a(m){return k(m)?(new Date((parseInt(m.substr(0,8),16)*1000))):new Date();}function i(m){var n=a();return((n.getTime()-1000*86400)>(new Date()).getTime());}function f(m,o){var n=a(m);return(((new Date()).getTime()-n.getTime())>o*1000);}function k(m){return m&&m.match(/^%5B0-9a-f%5D{16}$/)&&!i(m);}l.cuid=h;l.ivc=k;l.ioc=f;})(\_7,\_7.api,\_7); ``` -------------------------------- ### Basic Element and Attribute Selector Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/selector/css3-modsel-157/css3-modsel-157.html Applies styles based on element type and attribute presence. The 'p' tag gets a lime background, and any element with the 'test' attribute gets a red background. ```css p { background: lime; } [*=test] { background: red; } ``` -------------------------------- ### Build iText in Vagrant VM Source: https://github.com/itext/itextpdf/blob/develop/BUILDING.md Set up a Vagrant VM with Ubuntu 14.04 LTS and VirtualBox, then build iText inside the VM. This ensures all required software is pre-installed. ```bash $ vagrant box add ubuntu/trusty64 $ vagrant up $ vagrant ssh -- 'cd /vagrant ; mvn clean install -Dmaven.test.skip=true' | tee mvn.log ``` -------------------------------- ### Standard License Notice for Programs Source: https://github.com/itext/itextpdf/blob/develop/gnu-agpl-v3.0.md Include this notice at the beginning of each source file to state the exclusion of warranty and provide licensing information. Ensure it includes copyright details and a pointer to the full license. ```text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . ``` -------------------------------- ### JavaScript Initialization and Event Binding Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/div/complexDiv01/complexDiv_files/sh088.htm Initializes the application, sets up global variables, and binds event listeners for message handling. It configures the environment and prepares for communication. ```javascript var w=window,d=document,h=w.location.hash.slice(1),a=\_7,ua=navigator.userAgent.toLowerCase(),msi=(/msie/.test(ua))&&!(/opera/.test(ua)),ffx=/firefox/.test(ua),\_27d=!!w.postMessage,\_27e={sshs:1,ssc:1,uss:1,dbm:1,loc:1,atgotcode:1},ckv=\_3f(d.cookie,";");a.lng=msi?navigator.userLanguage:navigator.language;a.tmr={xfma:((new Date()).getTime())};for(var k in \_27e){if(ckv\[k\]){a.dat\[k\]=ckv\[k\];}}a.loc=a.dat.loc;a.dat.rdy=1;a.dat.geo=\_7.util.rtoKV(\_7.util.geo.dec(a.loc));a.dat.bti=\_7.util.rtoKV(\_7.ad.gbt());a.dat.bts=(\_7.ad.gst());a.dat.vts=(\_7.cookie.view.cla());a.dat.ssc=\_7.util.rtoKV(\_7.cookie.ssc.get());if(\_27d){if(msi){w.attachEvent("onmessage",a.pmh);}else{w.addEventListener("message",a.pmh,false);}}if(h.length){\_7.rec(h);}if(!a.xxl){if(ffx&&\_27d){w.parent.postMessage("rdy=1","*");}else{a.cookie.uid.update();a.cookie.view.update();if(h.length){a.xtp();}}}if(h.length){a.xtp();} ``` -------------------------------- ### Pipeline Construction Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/doc/example/default-setup.html Illustrates how to construct a pipeline for parsing XHTML and CSS to PDF, chaining CssResolverPipeline, HtmlPipeline, and PdfWriterPipeline. ```java Pipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer))); ``` -------------------------------- ### Adjacent Sibling Combinator (+) Example Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/selector/css3-modsel-87/css3-modsel-87.html Styles a 'div' element that immediately follows a 'blockquote' element. This selector targets only the direct sibling. ```css blockquote + div { color: red; } ``` -------------------------------- ### CSS Font Size with Points Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/text_layout/tinyBox002/tinyBox002.html Demonstrates setting font size using points. Ensure the font is available for rendering. ```css div { font-family: FreeMono; font-size: 1pt; } ``` -------------------------------- ### Basic Class Selector Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/selector/css3-modsel-14c/css3-modsel-14c.html Applies red background and yellow text to all 'p' elements. This is a foundational example of a simple class selector. ```css p { background: red; color: yellow; } ``` -------------------------------- ### Facebook Initialization and Login Logic Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/div/complexDivPagination01/complexDiv_files/sh088.htm Initializes the Facebook SDK and handles user login status. It subscribes to session changes and attempts to retrieve user information, falling back to a login prompt if necessary. ```javascript 2gether:"www2.select2gether.com",shaveh:"shaveh.co.il",shetoldme:"",shirintar:"shir.intar.in",simpy:"",sinaweibo:"v.t.sina.com.cn",slashdot:"slashdot.org",smiru:"smi2.ru",sodahead:"",sonico:"",speedtile:"speedtile.net",sphinn:"",spinsnap:"",spokentoyou:"",sportpost:"",yiid:"spread.ly",springpad:"springpadit.com",squidoo:"",startaid:"",startlap:"startlap.hu",storyfollower:"",studivz:"studivz.net",stuffpit:"",stumpedia:"",stylehive:"",svejo:"svejo.net",symbaloo:"",taaza:"",tagmarksde:"tagmarks.de",tagvn:"",tagza:"",tarpipe:"",tellmypolitician:"",thewebblend:"",thinkfinity:"community.thinkfinity.org",thisnext:"",throwpile:"",tipd:"",topsitelernet:"ekle.topsiteler.net",transferr:"",tuenti:"",tulinq:"",tusul:"",tvinx:"",tweetmeme:"api.tweetmeme.com",twitthis:"",typepad:"",upnews:"upnews.it",urlaubswerkde:"urlaubswerk.de",urlcapt:"",viadeo:"",virb:"",visitezmonsite:"",vk:"vkontakte.ru",vkrugudruzei:"vkrugudruzei.ru",voxopolis:"",vybralisme:"vybrali.sme.sk",vyoom:"",webnews:"webnews.de",domaintoolswhois:"domaintools.com",windows:"api.addthis.com",windycitizen:"",wirefan:"",wordpress:"",worio:"",wykop:"wykop.pl",xanga:"",xing:"",yahoobkm:"bookmarks.yahoo.com",yammer:"",yardbarker:"",yemle:"",yigg:"yigg.de",yoolink:"go.yoolink.to",yorumcuyum:"",youblr:"",youbookmarks:"",youmob:"",yuuby:"",zakladoknet:"zakladok.net",zanatic:"",ziczac:"ziczac.it",zingme:"link.apps.zing.vn",zootool:""};})(_7,_7.api,_7);(function(b,e,d){var f=255986367772510,h=false;function g(){window.fbAsyncInit=function(){FB.init({appId:f,status:true,cookie:true,xfbml:true,oauth:true});FB.Event.subscribe("auth.sessionChange",function(j){if(j.session){var k=FB.getSession();fbtoken=k.access_token;fbuserid=k.uid;}});c();};if(!document.getElementById("fb-root")){var i=document.createElement("div");i.id="fb-root";document.body.appendChild(i);}_7.ajs("http://connect.facebook.net/en_US/all.js",1);}function c(){FB.getLoginStatus(function i(k){if(k.authResponse){var j=_3f(_7.og);FB.api("/me/_addthis:read?"+j.type+"="+j.url,"post",function(l){if(!l||l.error){if((l.error.message||"200").search(/200/)!=-1&&!h){a();h=true;}}else{h=false;}});}else{_7.fbLogin();}});}}function a(){FB.login(function(i){if(i.authResponse){FB.api("/me",function(j){c();});}},{scope:"publish_actions"});}b.util=b.util||{};b.util.fbt=g;})( _7,_7.api,_7); ``` -------------------------------- ### Styling Address Elements with CSS Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/selector/css3-modsel-2/css3-modsel-2.html Applies a lime background color to all 'address' elements on the page. This is a basic example of a type element selector. ```css Type element selectors address { background-color: lime } ``` -------------------------------- ### Set Font Size in Millimeters Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/text_layout/mm001/mm001.html Demonstrates setting font size using millimeters. Ensure the font is available for rendering. ```css div { font-family: FreeMono; font-size: 1mm; } ``` -------------------------------- ### Direct Adjacent Sibling Combinator Example Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/selector/css3-modsel-90b/css3-modsel-90b.html Targets all 'p' elements that are direct children of the body or another block-level element. This is a basic selector for styling paragraphs. ```css p { color: green ! important; } ``` -------------------------------- ### Set Table Border Spacing with CSS Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/border/border_spacing/cell/border_spacing_cell01/border_spacing_cell01.html Apply CSS to a table element to define the spacing between its borders and cells. This example sets horizontal and vertical spacing. ```css table { border-spacing:10px 40px; } ``` -------------------------------- ### JavaScript Browser Fingerprinting Utilities Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/div/complexDivPagination01/complexDiv_files/sh088.htm Generates a unique fingerprint for the browser based on user agent, system settings, and installed plugins. Used for tracking and analytics. ```javascript function e(){var k=a(navigator.userAgent,16),f=((new Date()).getTimezoneOffset())+ "" +navigator.javaEnabled()+(navigator.userLanguage||navigator.language),h=window.screen.colorDepth+""+window.screen.width+window.screen.height+window.screen.availWidth+window.screen.availHeight,g=navigator.plugins,l=g.length;if(l>0){for(var j=0;j-1){return a.split("#").shift();}else{x=a.split("#").slice(1).join("#").split(";").shift();if(x.split(".").length==3){x=x.split(".").slice(0,-1).join(".");}if(x.length==12&&x.substr(0,1)=="."&&(/\\[a-zA-Z0-9\\-\\_\\]{11}/).test(x.substr(1))){return a.split("#").shift();}}return a;},l=function(a){return h(a,function(y,B){var x=y.indexOf(";jsessionid"),C=\[\] ,z,A;if(x>-1){y=y.substr(0,x);}if(B){for(z in B){if(typeof(B[z])=="string"){A=(B[z]||"").split("=");if(A.length==2){if(A[0].indexOf("utm_")===0||A[0]=="gclid"||A[0]=="sms_ss"||A[0]=="at_xt"||A[0]=="fb_ref"||A[0]=="fb_source"){continue;}}if(B[z]){C.push(B[z]);}}}y+=(C.length?(("?"+C.join("&")):""));}return y;});},b=function(){var ``` -------------------------------- ### User ID Management (JavaScript) Source: https://github.com/itext/itextpdf/blob/develop/xmlworker/src/test/resources/com/itextpdf/tool/xml/examples/css/div/complexDiv01/complexDiv_files/sh088.htm Manages user IDs, including updating, setting, getting, and checking their validity. It handles anonymous users and ensures ID consistency. ```javascript (function(f,g,k){var e,m=f,o=f.util,d="0000000000000000",h=0;function j(a){if(a==="anonymous"){return true;}return o.ivc(a);}function l(){var q=m.cookie.rck("uid"),r=!!_atc.xck,a,p=m.cookie.cww();if(!h){if(q&&j(q)){m.uf=0;if(q==="anonymous"){q=d;m.uf=2;}if(p){if(q==d){a=new Date();a.setYear(a.getFullYear()+10);}m.cookie.sck("uid",q,0,0,a);}else{q="x";}}else{if(q||q===""){m.uf=2;}else{m.uf=1;}if(p){q=o.cuid();m.cookie.sck("uid",q);}else{q="x";}}h=1;}m.uid=q;if(q){m.dat.uid=q;}}function i(a){try{var q=((m.bro.ie8||m.bro.ie9)&&window.external&&window.external.InPrivateFilteringEnabled()===true);}catch(p){}if(q||m.uid==="anonymous"||m.uid==="0000000000000000"||(navigator.doNotTrack&&navigator.doNotTrack!="unspecified"&&navigator.doNotTrack!="no")){ _atc.xck=1; m.uid="0000000000000000"; return 1; } return 0; } function n(a){m.uid=a;i();} function b(){var a=m.uid; return a&&j(a)?"&uid="+_euc(m.uid):"";} function c(){var a=m.uid; return a&&j(a)?a:"x";} if(!f.cookie){f.cookie={};} f.cookie.uid={update:l,set:n,get:c,toKV:b,isValid:j,check:i}; })(window,window.api,window); ```