Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







If you are familiar with XML and XSLT, then you also know that transformed XML documents can be displayed inside a web browser just like a web page.


Well, it does not stop with transformed XML. A lot of people have been asking us about exporting XML to PDF and other formats. And, here is our solution.
Our solution uses an old Delphi component called THTMLViewer. THTMLViewer is no longer under development by its original authors. The last update from them was for Delphi 2006. However, the authors had made the project open source. There is a Delphi 2009 update for the component from the good folks at www.songbeamer.com/delphi/.
Before you try our solution, you need to install the new THTMLViewer and then recompile eDocEngine's export interface component for THTMLViewer - TgtHtmlViewInterface. The test XML and XSL files used in our example code are named gnostice_nl.xsl and placed in the project folder. (You can use any XML and XSL file so long as the THTMLViewer can display it without problem.) Here are the steps for creating the Delphi application.

procedure TForm1.Button1Click(Sender: TObject);
var
XMLDocument1: TXMLDocument;
XSLPageProducer1: TXSLPageProducer;
begin
XMLDocument1 := TXMLDocument.Create(self);
XSLPageProducer1 := TXSLPageProducer.Create(self);
try
// Transform XML and place HTML in memo
XMLDocument1.Active := False;
XSLPageProducer1.FileName := 'Input_Docs\gnostice_nl.xsl';
XMLDocument1.FileName := 'Input_Docs\gnostice_nl.xml';
XSLPageProducer1.XMLData := XMLDocument1;
XMLDocument1.Active := True;
Memo1.Text := XSLPageProducer1.Content;
XMLDocument1.Active := False;
// Display HTML from memo
HTMLViewer1.LoadFromString(Memo1.Text);
// Export displayed HTML to PDF
gtHtmlViewInterface1.Engine := gtPDFEngine1;
gtPDFEngine1.Preferences.ShowSetupDialog := false;
gtPDFEngine1.FileName := 'Output_Docs\gnostice_nl.pdf';
gtHtmlViewInterface1.RenderDocument(HTMLViewer1);
except on E: Exception do
Memo1.Text := E.Message
end;
end;

Here is the final output.

---o0O0o---
| Our Developer Tools | |
|---|---|
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).