Class PdfExportImpl

  • All Implemented Interfaces:
    PdfExport

    public class PdfExportImpl
    extends Object
    implements PdfExport
    Default implementation for the PDF Export process, which uses XSLT transformations and Apache FOP to convert a Document into PDF, passing through HTML, valid XHTML, styled XHTML, and XSL-FO.
    Version:
    $Id: 9f471406bc61fc62d427e8a7e1e3371b70578a56 $
    • Constructor Detail

      • PdfExportImpl

        public PdfExportImpl()
    • Method Detail

      • export

        public void export​(XWikiDocument doc,
                           OutputStream out,
                           PdfExport.ExportType type,
                           XWikiContext context)
                    throws XWikiException
        Description copied from interface: PdfExport
        Export a wiki Document into PDF or RTF. The content of the document is rendered into HTML using the pdf.vm template, the resulting HTML is cleaned up into valid XHTML, and custom CSS is applied to it. The XHTML document is transformed into an XSL-FO document, which is finally processed using Apache FOP.
        Specified by:
        export in interface PdfExport
        Parameters:
        doc - the document to export
        out - where to write the resulting document
        type - the type of the output: PDF or RTF
        context - the current request context
        Throws:
        XWikiException - if the conversion fails for any reason
      • exportHtml

        public void exportHtml​(String html,
                               OutputStream out,
                               PdfExport.ExportType type,
                               XWikiContext context)
                        throws XWikiException
        Description copied from interface: PdfExport
        Convert an HTML document to PDF. The HTML is cleaned up, and CSS style is applied to it.
        Specified by:
        exportHtml in interface PdfExport
        Parameters:
        html - the source document to transform
        out - where to write the resulting document
        type - the type of the output: PDF or RTF
        context - the current request context
        Throws:
        XWikiException - if the conversion fails for any reason
      • exportXHTML

        protected void exportXHTML​(String xhtml,
                                   OutputStream out,
                                   PdfExport.ExportType type,
                                   XWikiContext context)
                            throws XWikiException
        Convert a valid XHTML document into PDF. No further processing of the XHTML occurs.

        Note: This method is protected just allow other exporters to hook their code and use the PDF export infrastructure. This is just a temporary solution. The PDF export code needs to be redesigned because it has parts than can be reused for other export formats.

        Parameters:
        xhtml - the source document to transform
        out - where to write the resulting document
        type - the type of the output: PDF or RTF
        context - the current request context
        Throws:
        XWikiException - if the conversion fails for any reason
      • applyXSLT

        protected String applyXSLT​(String xml,
                                   InputStream xslt)
                            throws XWikiException
        Applies an XSLT transformation to an XML document.
        Parameters:
        xml - the XML document to convert
        xslt - the XSLT to apply
        Returns:
        the converted document
        Throws:
        XWikiException - if the transformation fails for any reason
      • getXslt

        protected InputStream getXslt​(String propertyName,
                                      String fallbackFile,
                                      XWikiContext context)
        Get an XSLT file.
        Parameters:
        propertyName - the name of the xproperty from which to read the XSLT file. See getPDFTemplateProperty(String, XWikiContext) for details on how this property is resolved. If the property doesn't point to any XSLT file then the fallback file parameter is used instead
        fallbackFile - the name of a resource file to use when no XSLT content was found using the passed propertyName
        context - the current request context
        Returns:
        the content of the XSLT as a byte stream