XMLMill - convert xml to pdf with java. Generate PDF from xml/xsl.

XMLMill for Domino: UseCases

Version: 2.80 Date: November 4th, 2006
This tutorial is opened in a separate window in order to maximize the legibility of this tutorial.
To return to XMLMill, close this browser window

This page as PDFPrinter friendly pageThis guide (!) as PDF

Use case 5: Include rich text (via a web rich text editor) in the PDF-document

Introduction

Many customers and prospects asked us to be able to include rich text content in the PDF. Currently we have started supporting rich text content resulting from a rich text editor on the web, producing xhtml-tags in the background. In the xsl-stylesheet template_rt_xhtml.xsl the translation from the editor's xhtml to xmlmill-tags is performed.

Limitations

For the current use case the templates in the template_rt_xhtml.xsl stylesheet are based on the xhtml code generated by the TinyMCE editor (http://tinymce.moxiecode.com), a platform independent web based Javascript HTML WYSIWYG editor control released as Open Source under LPGL by Moxiecode Systems AB.

The template_rt_xhtml.xsl is limited to basic xhtml-xmlmill translations, which should also be applicable in other web rich text editors. Translations of styles specific for this editor were not included, since these cannot be used by other web rich text editors. However, you can modify the template_rt_xhtml.xsl so that it includes the specific styles your web rich text editor supports.

  • Some translations were omitted from the template_rt_xhtml.xsl because xhtml generated by the rich text editor didn't contain enough information eg. a table whithout definition of the column widths.

In order to be able to convert XHTML elements to ml: elements and to succesfully generate PDF documents some conditions must be met:

  1. The stylesheet should contain (one - or more) <richtext> element(s) containing the XHTML elements.
  2. Limit the content of the <richtext> element so it only contains the elements defined in the template_rt_xhtml.xsl stylesheet or...
  3. Extend the template_rt_xhtml.xsl stylesheet so it can convert other XHTML elements to the correct ml: elements.
  4. Be sure to reference in the config.xml file all fonts that are referenced in the XHTML elements.

Be aware that in the current version of XMLMill:

  • Nested tables are not supported.
  • Nested list-bullets or list-numbers are not supported.

Native Notes rich text content?

What about using rich text content directly in Notes and not via the web? We did some testing with this and if we'll support it in the future, it will work via the Notes dxl-exporter native to Domino, which generates an xml-representation of an entire Notes-document.

Again a translation between this xml-representation and the ml: elements must be done in a translation stylesheet.

The problem encountered is that the xml-representation of the generated Domino document isn't always valid xml, wich is a blocking factor.

Currently we are in the process of trying to solve this problem.

A closer look at Use Case 5.

As this use case is an extension of Use Case 1, please read first Use Case 1, since we will only mark the modifications we made for the rich text field in this Use Case 5.

The content of the 2 rich text fields (AD1 and AD2) will be added to the PDF document are shown below: We first present you the content shown in the notes document and then the content viewed by a browser:

Content in Notes:

images/rt_innotes.jpg
Select to enlarge

Content on the web:

images/rt_onweb.jpg
Select to enlarge

  • Remember that the content was created via a web rich-text editor.

In order to try out this use case you need following building blocks:

  1. A trial or licensed version of XMLMill for Domino
  2. The Domino Database "XMLMill Domino Usecases" (UseCases.nsf), which can be found in the download of XMLMill for Domino.
  3. The XMLMILLR6-servlet installed and configured on a Domino R6/R7-server.
  4. The Notes-agents (GenerateQuote_rthtml) which can be found in the UseCases.nsf
  5. The XSLT-stylesheets template_rt_xhtml.xsl and quote_rt_xhtml.xsl

The result of this use case will be a PDF containing the same introduction page and 5 producttables on the next 2 pages as in Use Case 1.

At the bottom of the document 2 additional RT-fields will be printed. These 2 fields (AD1 and AD2) can be found in the section Additional texts in the QuoteRT-document.

We only show this section in the picture below:

images/rt_pdf.jpg
Select to enlarge

A trial or licensed version of XMLMill for Domino

To install XMLMill for Domino, please go to the download page of the XMLMill website and choose the appropriate download distribution (.zip or .tar.gz format)

Since this is a use case that explains the use of XMLMIll in a Domino R6/R7-environment, you should follow the installation and configuration instructions that are explained in the installation_guide_r6.pdf in order to be able to try out this use case. Refer to the subdirectory domino in the download to find the installation_guide_r6.pdf.

  • Note however this RT-technique can also be used when creating the PDF via the batch-procedure in a R5/R6/R7 environment, so the rich text technique described in this Use Case also works in R5.

The Domino Database XMLMill Domino Usecases

Please refer to the subdirectory domino in the download to find the database Usecases.nsf. Make sure you install this database on your Domino R6/R7-server if you want to try out this use case and that you have carried out all installation and configuration instructions that are described in the installation_guide_r6.pdf.

  • Note that you have to modify the formula behind the View PDF with RT in html-buttons on the QuoteRT-form. You should alter the name of the server and if necessary the portnumber.

The XMLMILLR6-servlet installed and configured on a Domino R6/R7-server.

Please refer to the installation_guide_r6.pdf in the download for a full explanation about the installation of the servlet in your Domino R6/R7-environment.

To try this Use Case, goto the view Quotes/RT-support. When you open the QuoteRT-document and click on the View PDF with RT in html-button the PDF-generation process is started by invoking the XMLMILLR6-servlet. The link contains following formula:

[001] 
[002] db:=@ReplaceSubstring(@Subset(@DbName;-1);"\\";"/");
[003] docid:=@Text(@DocumentUniqueID);
[004] agid:="(GenerateQuote_rthtml)";
[005] @URLOpen("http://192.168.0.10/servlet/xmlmillr6?dbid="+db+"&docid="+docid 
      + "&agid="+agid + 
      "&actionid=1")

Apart from specifying your server address, you should note that there is a new agent (GenerateQuote_rthtml) which is a small modification of the (GenerateQuote)-agent we explained in Use Case 1. In the next section we will only comment on the modifications in the new agent. A full explanation of the other parts can be read in Use Case 1.

The agent modifications in the (GenerateQuote_rthtml)

You can find the agent (GenerateQuote_rthtml) in the Domino-database Usecases.nsf . Note that this agent will run as webuser. As we mentioned before the agent (GenerateQuote_rthtml) is a Lotus Script agent that modifies the (GenerateQuote)-agent of Use Case 1.

The agent modifications are:

Initialization of different variables and objects

2 new variables are initialized (for fields AD1 and AD2).

[001] Sub Initialize
[002] 	'1) Initializing
[003] 	
[004] 	.....
[005] 	Dim htmlitem1 As notesrichtextitem
[006] 	Dim htmlitem2 As notesrichtextitem
[007] 	

Defining the name of the XSLT-file in the XML-document created by the servlet

In the xsl-field in the XML-document, we write the name of the XSLT-stylesheet, which must be used for the quotation-PDF. The servlet will capture this name later on and search for this XSLT-file on the filesystem of the Domino-server. In this agent we are referring to another stylesheet: quote_rt_xhtml.xslRefer to the installation_guide_r6.pdf to learn where the XSLT-stylesheet should be placed on the Domino-server-filesystem.

  • Note that in the quote_rt_xhtml.xsl the general xhtml-xmlmill translation stylesheet template_rt_xhtml.xsl is imported.
[001] '2) defining the name of the XSLT-stylesheet to find the correct XSLT-file 
      later on 
[003] 	
[004]    xmldoc.xsl="quote_rt_xhtml.xsl"
[005] 
[006] 	

Start creating the XML-structure

Part 3 of the agent generates the XML-structure based on the quotesRT-document. The XML-structure will be written to the Richtext-item "XML". Then the XML-header element is defined, followed by the opening elements <quotes> <quote>.

Heading of the xml-file

In the heading of the xml-file it is necessary to make sure to escape the necessary characters. Below we provide the example for the nbsp. If you don't escape these characters, the xml-file is not well-formed and this will cause errors.

[001] 
[002] 
[003] 	' 3a) heading and general quote information 
[004] 	
[005] 	Call rtitem.AppendText( "<?xml version=""1.0"" encoding=""windows-1252"" 
       standalone=""no""?>" )
[007] 	Call rtitem.AddNewLine( 1 )
[008] 	
[009] 	Call rtitem.appendtext("<!DOCTYPE quotes [<!ENTITY nbsp ' '>]>")
[010] 	Call rtitem.AddNewLine( 1 )
[011] 

Rich text info

The <richtext> element contains the xhtml-content in the rich text fields AD1 and AD2. It is very important in your future applications that you name the rich text element tags in your xml-structure as follows: <richtext name='Notesfieldname'> . The elementname richtext is mandatory, followed by the name attribute which contains the Notes-name of your rich text field.

[001]  
[002] 	
[003] 		'3e getting information from rich text item
[004] 	Set htmlitem1=doc.getfirstitem("AD1")
[005] 	Set htmlitem2=doc.getfirstitem("AD2")
[006] 	
[007] 	
[008] 	rtitem.AppendText("    <richtext name='AD1'>")
[009] 	Call rtitem.AddNewLine( 1 )
[010] 	rtitem.AppendText(htmlitem1.GetFormattedText(True,2048)) 	
[011] 	Call rtitem.AddNewLine( 1 )
[012] 	rtitem.AppendText("    </richtext>")
[013] 	Call rtitem.AddNewLine( 1 )
[014] 	rtitem.AppendText("    <richtext name='AD2'>")
[015] 	Call rtitem.AddNewLine( 1 )
[016] 	
[017] 	rtitem.AppendText(htmlitem2.GetFormattedText(True,2048) )
[018] 	Call rtitem.AddNewLine( 1 )
[019] 	rtitem.AppendText("    </richtext>")
[020] 	Call rtitem.AddNewLine( 1 )
[021] 	
[022] 	

The XSL-stylesheet

In this Use Case 2 stylesheets are involved:

  • quote_rt_xhtml.xsl
  • template_rt_xhtml.xsl

quote_rt_xhtml.xsl

The quote_rt_xhtml.xsl is fully based on the duquotesdemo.xsl we explained in Use Case 1. It defines the layout of the PDF with ml-elements. Furthermore it imports the template_rt_xhtml.xsl so that the xhtml-code of the richt text elements can be translated to ml-elements too.

The import statement:

[001] <xsl:import 
      href="template_rt_xhtml.xsl"/>

The modifications for the RT-field

[001] <xsl:apply-templates select="/quotes/quote/richtext[@name='AD1']"/>
[002] <ml:p/>
[003] <xsl:apply-templates 
      select="/quotes/quote/richtext[@name='AD2']"/>		
  • Note that the template for the rich text fields can be found in the imported stylesheet template_rt_xhtml

template_rt_xhtml

The template_rt_xhtml.xsl is imported in the quote_rt_xhtml.xsl and contains the translation of basic xhtml-code to ml-elements. This stylesheet can be extended if your web rich text editor supports other styles or elements as long as there is an equivalent ml-element.

Copyright © 2001 - 2012. All rights reserved. XMLMill and XMLMill logo are trademarks of Pecunia Data Systems, bvba.
Powered by Apache CocoonPowered by XMLMill