Introduction
The Tridion PDFCreator module converts Tridion Components into PDF documents. It uses 2 open source projects to perform this, namely html2fo and Apache FOP. In its simplest use case, PDFCreator will create a new Multimedia Component in the same folder as the source component containing a PDF.
Prerequisites
Platform requirements:
- Tridion Content Manager 5.2
- Java SDK 1.4
- HTML2FO
- Apache FOP (Formatting Objects Processor)
This How-To will guide you in installing the Apache FOP, HTML2FO and in installing, configuring and using the PDFCreator itself.
You can download the PDFCreator DLL here .
1. Installing HTML2FO
- Open a browser and go to http://html2fo.sourceforge.net
- Locate and click on the "official releases" link in that page
- Download the Win32 version of html2fo
- Create a folder on the Content Manager server and name it html2fo (for instance "d:\tridion\html2fo")
- Copy the html2fo.exe file into that folder
PDFCreator has been developed and tested with version 0.4.2, but any version should work.
Testing HTML2FO
Using the provided renderedOutput.html file, open a command prompt and run the following command:
D:\Tridion\html2fo\html2fo.exe renderedOutput.html renderedOutput.fo
The resulting file (renderedOutput.fo) should be a standard XSL:FO stylesheet. You can try opening this file in XMLSpy or Internet Explorer to validate it.
2. Installing Apache FOP
- Open a browser and go to http://xmlgraphics.apache.org/fop
- Go to the download page and download the Binary version
- Create a folder on the Content Manager server and name it FOP (for instance "d:\tridion\fop")
- Copy the whole FOP download into that folder
PDFCreator has been developed and tested with version 0.20.5, but any other version should work correctly.
Testing Apache FOP
You can try creating a PDF file from the XSL:FO resulting from html2fo's test. To do this, run the following command:
D:\Tridion\FOP\fop-020-5\fop.bat -fo d:\Tridion\html2fo\renderedOutput.fo pdf renderedOutput.pdf
3. Installing PDFCreator
Depending on how you're planning to use PDFCreator, you might have to perform different actions.
PDFCreator can be used from the command line, from the Tridion Event System or from a Tridion Template. Each type of usage requires a different configuration level.
Install PDFCreator dlls
- Copy the TridionExtensions.dll and PDFCreator.dll into the [Tridion Install]\bin folder;
- Copy the tcm2pdf.xml file into [Tridion Install]\config;
The following steps are optional, and are only required if you plan to call PDFCreator from Tridion Templates.
- Register the PDFCreator assembly using regasm TridionPDFcreator.dll)
- Create a Tridion Script Extension by using the "Tridion.PDFCreator" ProgID
Testing PDFCreator
You can use the provided PDFCreator.exe to test the functionalities, but before you can do that you must have at least one component in your system. Then, note down the URIs to:
- The component to use for the test
- The Tridion Default Component Template
Run the following command:
D:\Tridion\bin\PDFCreator <ComponentUri> <DefaultCTUri>
E.g. D:\Tridion\bin\PDFCreator tcm:10-280 tcm:10-20-32
If it is successful, you will see a message stating that the PDF has been created and stored in <tcm:x-x>. Use this URI to retrieve the created multimedia component. If anything goes wrong during the process you will find information in the Windows Event log.
4. Configuring the PDFCreator
Use any XML or Text editor to configure the tcm2pdf.xml file that you have just put in the config directory. The following are the possible values for each xml node:
TempFolder:
The folder to use as root for temporary files. This folder must exist. PDFCreator will create temporary folders within this folder and delete them (if so instructed).
PathToHtml2Fo:
The path to the html2fo executable. It must include the exe file and it must exist. This may also be a TCM URI pointing to a XSLT-FO Template Building Block, in which case the html2fo will be skipped and this XSLT-FO will be used to convert to PDF instead.
PathToFop:
The path to the fop.bat file provided by Apache FOP. It must exist.
CleanUp:
Instructs the system to remove the temporary files when finished if set to "true" (case sensitive). If set to any other value the temporary files will not be removed (can be useful for debugging).
Storage:
Where to store the generated PDF. The default value of "TCM" instructs PDFCreator to store the PDF in a multimedia component in the same folder as the source component.
You can set it also to a physical folder location on the server's file system or to a Folder URI, in which case PDFCreator will use those locations instead.
MMSchema:
The URI to the multimedia schema to use when creating new components. PDFCreator does not support multimedia schemas with mandatory metadata.
5. Calling the PDFCreator from a .NET Event System
An example piece of code used to trigger the creation of pdfs automatically, when a component has been created or changed:
Note that the parameters pdfSchemaName , sourceFolderName and XLSTemplateID are globally defined.
These parameters can also, if desired, be set as metadata for a folder in Tridion, and can be read dynamically.
const string XLSTemplateID = "tcm:34-154-32"; //the CT to use for the PDF creation
const string pdfSchemaName = "General Content"; //The schema name the component should be based on
const string sourceFolderName = "company"; //Components created in this folder will be converted to PDF.
public virtual void OnComponentSavePost(Component component, bool doneEditing)
{
//If the component is a multimedia component, we do nothing, otherwise...if (!component.IsMultimediaComponent)
{//If we want to check on schema.
if (pdfSchemaName != string .Empty && component.Schema.Title == pdfSchemaName)
{PDFCreator pdf = new PDFCreator();
//This will create the PDF based on the Component Template
string emptystr = pdf.ConvertToPDF(component.ID, XLSTemplateID);
return ;}
//if we want to check on folder name
Folder objFolder = (Folder)component.OrganizationalItem;
if (sourceFolderName != string .Empty && objFolder.Title == sourceFolderName)
{PDFCreator pdf = new PDFCreator();
string emptystr = pdf.ConvertToPDF(component.ID, XLSTemplateID);
return ;}
}
}
Notes
There is another article on Devworld regarding creating PDF Files from the Tridion Content Manager. The method as described in this document has a couple of advantages:
- The PDFs are created in the Tridion Content Manager, which means you can link to them from the Tridion Content Manager (binary links).
- This method is compatible with CWA, whereas the other method is only supported when publishing to a File System.