Convert TEXT to PDF file using Java. A sample java code for Connection Pooling for JDBC connection. Application convert's html link into PDF file format. Convert HTML to PDF in C# and VB.NET. How to convert HTML to PDF using iText. This is my code to convert HTML to PDF.
Transforming XML Data with XSLTThe Extensible Stylesheet Language Transformations (XSLT) APIs can be used for many purposes. For example, with a sufficiently intelligent stylesheet, you could generate PDF or Post. Script output from the XML data.
But generally, XSLT is used to generate formatted HTML output, or to create an alternative XML representation of the data. In this section, an XSLT transform is used to translate XML input data to HTML output. Note - The. XSLT specification is large and complex, so this tutorial can only scratch the surface.
It will give you a little background so you can understand simple XSLT processing tasks, but it does not examine in detail how to write an XSLT transform, rather concentrating on how to use JAXP's XSLT transform API. For a more thorough grounding in XSLT, consult a good reference manual, such as Michael Kay's XSLT 2. XPath 2. 0: Programmer's Reference (Wrox, 2. Defining a Simple Document Type. Start by defining a very simple document type that can be used for writing articles. Our article documents will contain these structure tags: < TITLE> : The title of the article< SECT> : A section, consisting of a heading and a body< PARA> : A paragraph< LIST> : A list< ITEM> : An entry in a list< NOTE> : An aside, that is offset from the main text.
- How to convert html file into pdf. Indeed Java script code for converting html file into pdf.
- Java code to convert HTML to PDF. The Pdfcrowd API is an online tool that lets you easily save web pages and raw HTML code to PDF in your Java applications.
PDF” Source Code @ GitHub. Convert HTML to PDF Using Java ” Rajesh. Reliable and secure HTML to PDF convertor. We've just added a Java example! Java PDF library - ConvertPagesToImages.java. Java PDF API to create PDF documents from scratch. Read, edit and convert PDF, XPS, EPUB, HTML, MHT, PCL, SVG, XSLFO, TEX. Source Code; Forums; Blogs; Downloads. Convert HTML to PDF using PHP quick. Take a look at the piece of code bellow: Converting HTML to PDF.
The slightly unusual aspect of this structure is that we will not create a separate element tag for a section heading. Such elements are commonly created to distinguish the heading text (and any tags it contains) from the body of the section (that is, any structure elements underneath the heading). Instead, we will allow the heading to merge seamlessly into the body of a section. That arrangement adds some complexity to the stylesheet, but it will give us a chance to explore XSLT's template- selection mechanisms.
It also matches our intuitive expectations about document structure, where the text of a heading is followed directly by structure elements, an arrangement that can simplify outline- oriented editing. Note - This kind of structure is not easily validated, because XML's mixed- content model allows text anywhere in a section, whereas we want to confine text and inline elements so that they appear only before the first structure element in the body of the section. The assertion- based validator can do it, but most other schema mechanisms cannot. So we will dispense with defining a DTD for the document type.
In this structure, sections can be nested. The depth of the nesting will determine what kind of HTML formatting to use for the section heading (for example, h. Using a plain SECT tag (instead of numbered sections) is also useful with outline- oriented editing, because it lets you move sections around at will without having to worry about changing the numbering for any of the affected sections.
For lists, we will use a type attribute to specify whether the list entries are unordered (bulleted), alpha (enumerated with lowercase letters), ALPHA (enumerated with uppercase letters), or numbered. We will also allow for some inline tags that change the appearance of the text.< B> : Bold< I> : Italics< U> : Underline< DEF> : Definition< LINK> : Link to a URLNote - An inline tag does not generate a line break, so a style change caused by an inline tag does not affect the flow of text on the page (although it will affect the appearance of that text). A structure tag, on the other hand, demarcates a new segment of text, so at a minimum it always generates a line break in addition to other format changes. The < DEF> tag will be used for terms that are defined in the text. Such terms will be displayed in italics, the way they ordinarily are in a document.
But using a special tag in the XML will allow an index program to find such definitions and add them to an index, along with keywords in headings. In the preceding Note, for example, the definitions of inline tags and structure tags could have been marked with < DEF> tags for future indexing. Finally, the LINK tag serves two purposes. First, it will let us create a link to a URL without having to put the URL in twice; so we can code < link> http//..< /link> instead of < a href=. Of course, we will also want to allow a form that looks like < link target=.
That leads to the second reason for the < link> tag. It will give us an opportunity to play with conditional expressions in XSLT.
Note - Although the article structure is exceedingly simple (consisting of only eleven tags), it raises enough interesting problems to give us a good view of XSLT's basic capabilities. But we will still leave large areas of the specification untouched. In What Else Can XSLT Do?, we will point out the major features we skipped.
Creating a Test Document. Here, you will create a simple test document using nested < SECT> elements, a few < PARA> elements, a < NOTE> element, a < LINK> , and a < LIST type=. The idea is to create a document with one of everything so that we can explore the more interesting translation mechanisms. Note - The code discussed in this section is in article. XSLT examples into the install- dir/jaxp- 1. The result is an outline structure that is harder to edit in plain text form, like this, but is much easier to edit with an outline- oriented editor.
Someday, given a tree- oriented XML editor that understands inline tags such as < B> and < I> , it should be possible to edit an article of this kind in outline form, without requiring a complicated stylesheet. In such an editor, the article fragment would look something like this. ARTICLE>. < TITLE> A Sample Article. SECT> The First Major Section. PARA> This section will. For now, note that if you want to output anything other than well- formed XML, then you will need an < xsl: output> tag like the one shown, specifying either text or html.
The specification looks like this: < xsl: output method=. You will also process the PARA element defined in the test document.
Note - If on first reading you skipped the section that discusses the XPath addressing mechanisms. How XPath Works, now is a good time to go back and review that section. Begin by adding the main instruction that processes the root element: < xsl: template match=. The instruction < xsl: apply- templates> processes the children of the current node. In this case, the current node is the root node. Despite its simplicity, this example illustrates a number of important ideas, so it is worth understanding thoroughly. The first concept is that a stylesheet contains a number of templates, defined with the < xsl: template> tag.
Each template contains a match attribute, which uses the XPath addressing mechanisms described in. How XPath Works to select the elements that the template will be applied to. Within the template, tags that do not start with the xsl: namespace prefix are simply copied.
The newlines and whitespace that follow them are also copied, and that helps to make the resulting output readable. Note - When a newline is not present, whitespace is generally ignored.
To include whitespace in the output in such cases, or to include other text, you can use the < xsl: text> tag. Basically, an XSLT stylesheet expects to process tags.
So everything it sees needs to be either an < xsl.> tag, some other tag, or whitespace. In this case, the non- XSL tags are HTML tags. So when the root tag is matched, XSLT outputs the HTML start tags, processes any templates that apply to children of the root, and then outputs the HTML end tags. Process the < TITLE> Element. Next, add a template to process the article title: < xsl: template match=.
In this case, the apply- templates tag ensures that if the title contains any inline tags such as italics, links, or underlining, they also will be processed. More importantly, the apply- templates instruction causes the text of the title to be processed. Like the DOM data model, the XSLT data model is based on the concept of text nodes contained in element nodes (which, in turn, can be contained in other element nodes, and so on).
That hierarchical structure constitutes the source tree. There is also a result tree, which contains the output. XSLT works by transforming the source tree into the result tree.
To visualize the result of XSLT operations, it is helpful to understand the structure of those trees, and their contents. But this time, you apply templates in two stages using the select attribute. For the first stage, you select text nodes, as well as inline tags such as bold and italics, using the XPath text() function. In the second stage, you select the other structure elements contained in the file, for sections, paragraphs, lists, and notes. Using the select attribute lets you put the text and inline elements between the < h.
In other words, you make sure that the nesting of the headings in the XML document is not reflected in the HTML formatting, a distinction that is important for HTML output. In general, using the select clause lets you apply all templates to a subset of the information available in the current context. As another example, this template selects all attributes of the current node. For this example, you will stop at two levels of section headings.
But if the XML input happens to contain a third level, you will want to deliver an error message to the user. This section shows you how to do that. Note - We could continue processing SECT elements that are further down, by selecting them with the expression /SECT/SECT//SECT. The // selects any SECT elements, at any depth, as defined by the XPath addressing mechanism. But instead we will take the opportunity to play with messaging. Add the following template to generate an error when a section is encountered that is nested too deep: < xsl: template match=.
Without it, processing could still go on, with everything in that section being ignored.