Package org.xhtmlrenderer.pdf

Examples of org.xhtmlrenderer.pdf.ITextRenderer$NullUserInterface


                // alter paths of link/img tags so itext can use them properly
                patchLinks(doc, request);

                // structure pdf document
                ITextRenderer renderer = new ITextRenderer();
                renderer.setDocument(doc, "");
                renderer.layout();

                // create the pdf
                ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
                renderer.createPDF(pdfStream);

                // concatenate with other docs
                final Person person = (Person) request.getAttribute("person");
                final StudentCandidacy candidacy = getCandidacy(request);
                ByteArrayOutputStream finalPdfStream = concatenateDocs(pdfStream.toByteArray(), person);
View Full Code Here


*/
public class Html2PdfConverter implements Converter<String, byte[]> {
    @Override
    public byte[] convert(String input) throws ConversionException {
        try {
            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocumentFromString(new String(input.getBytes()));
            renderer.layout();
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            renderer.createPDF(outputStream);
            byte[] bytes = outputStream.toByteArray();
            return bytes;
        } catch (DocumentException e) {
            e.printStackTrace();
            throw ConversionException.HTML_TO_PDF_EXCEPTION;
View Full Code Here

    try
    {
      OutputStream os = new FileOutputStream(outputFile);
      try
      {
        ITextRenderer renderer = new ITextRenderer();
        MissingResourceLoggingUserAgent uac = new MissingResourceLoggingUserAgent(renderer.getSharedContext().getUserAgentCallback());
        renderer.getSharedContext().setUserAgentCallback(uac);
       
        if (title != null)
          renderer.getOutputDevice().setMetadata("title", title);
        if (author != null)
          renderer.getOutputDevice().setMetadata("author", author);
        if (subject != null)
          renderer.getOutputDevice().setMetadata("subject", subject);
        if (keywords != null)
          renderer.getOutputDevice().setMetadata("keywords", keywords);
       
        if (htmlFiles == null || htmlFiles.isEmpty())
          htmlFiles = toFileList(htmlFileSets);
        if (htmlFiles.isEmpty())
          throw new MojoExecutionException("No HTML files found");
       
        boolean initial = true;
        for (File htmlFile : htmlFiles)
        {
          getLog().info("Converting HTML " + htmlFile.getAbsolutePath());
         
          Document doc = readInputFileAsDocument(htmlFile);
         
          renderer.setDocument(doc, htmlFile.toURI().toString());
          renderer.layout();
         
          if (initial)
          {
            renderer.createPDF(os, false);
            initial = false;
          }
          else
            renderer.writeNextDocument();
        }
       
        renderer.finishPDF();
       
        for (RelativeUri missingImageUri : uac.getMissingImageUris())
        {
          getLog().warn("Missing image: " + missingImageUri.getUri() + " (from " + missingImageUri.getBase() + ")");
        }
View Full Code Here

           setStatus( "Exporting to " + path + "..." );
           OutputStream os = null;
           try {
               os = new FileOutputStream(path);
               try {
               ITextRenderer renderer = new ITextRenderer();

               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
               DocumentBuilder db = dbf.newDocumentBuilder();
               Document doc =  db.parse(manager.getBaseURL());

               PDFCreationListener pdfCreationListener = new XHtmlMetaToPdfInfoAdapter( doc );
               renderer.setListener( pdfCreationListener );
                             
               renderer.setDocument(manager.getBaseURL());
               renderer.layout();

               renderer.createPDF(os);
               setStatus( "Done export." );
            } catch (Exception e) {
                XRLog.general(Level.SEVERE, "Could not export PDF.", e);
                e.printStackTrace();
                setStatus( "Error exporting to PDF." );
View Full Code Here

        } catch (IOException e) {
            //
            JOptionPane.showMessageDialog(frame, "Can't create temp file for PDF output, err: " + e.getMessage());
            return;
        }
        final ITextRenderer renderer = new ITextRenderer();
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(f);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            renderer.setDocument(doc, null, new XhtmlNamespaceHandler());
            ITextFontResolver resolver = renderer.getFontResolver();
            // TODO: encoding is hard-coded as IDENTITY_H; maybe give user option to override
            resolver.addFont(
                    fontPathTF.getText(),
                    BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED
            );
            renderer.layout();
            renderer.createPDF(bos);

            msgToUser = "Rendered PDF: " + f.getCanonicalPath();
        } catch (FileNotFoundException e) {
            msgToUser = "Can't create PDF, err: " + e.getMessage();
        } catch (DocumentException e) {
View Full Code Here

     *                           while building the Document.
     */
    public static void renderToPDF(String url, String pdf, Character pdfVersion)
            throws IOException, DocumentException {

        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(url);
        if (pdfVersion != null) renderer.setPDFVersion(pdfVersion.charValue());
        doRenderToPDF(renderer, pdf);
    }
View Full Code Here

     *                           while building the Document.
     */
    public static void renderToPDF(File file, String pdf, Character pdfVersion)
            throws IOException, DocumentException {

        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(file);
        if (pdfVersion != null) renderer.setPDFVersion(pdfVersion.charValue());
        doRenderToPDF(renderer, pdf);
    }
View Full Code Here

        }

        try {
            xhtmlPanel.setDocumentFromString(content, null, new XhtmlNamespaceHandler());
            ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
            ITextRenderer renderer = new ITextRenderer();

            renderer.setDocumentFromString(content);
            renderer.layout();

            renderer.createPDF(os);
            os.flush();


            ByteBuffer buf = ByteBuffer.wrap(os.toByteArray());
            PDFFile pdffile = new PDFFile(buf);
View Full Code Here

            };

            final File outputFile = File.createTempFile("FlyingSacuer.PDFRenderToMultiplePages", ".pdf");
            os = new FileOutputStream(outputFile);

            ITextRenderer renderer = new ITextRenderer();

            // we need to create the target PDF
            // we'll create one page per input string, but we call layout for the first
            renderer.setDocumentFromString(inputs[0]);
            renderer.layout();
            renderer.createPDF(os, false);

            // each page after the first we add using layout() followed by writeNextDocument()
            for (int i = 1; i < inputs.length; i++) {
                renderer.setDocumentFromString(inputs[i]);
                renderer.layout();
                renderer.writeNextDocument();
            }

            // complete the PDF
            renderer.finishPDF();

            System.out.println("Sample file with " + inputs.length + " documents rendered as PDF to " + outputFile);
        }
        finally {
            if (os != null) {
View Full Code Here

            renderer.setDocument(url);
            renderer.layout();
            renderer.createPDF(os);
            */

            ITextRenderer renderer = new ITextRenderer();
            ResourceLoaderUserAgent callback = new ResourceLoaderUserAgent(renderer.getOutputDevice());
            callback.setSharedContext(renderer.getSharedContext());
            renderer.getSharedContext ().setUserAgentCallback(callback);

            Document doc = XMLResource.load(new InputSource(url)).getDocument();

            renderer.setDocument(doc, url);
            renderer.layout();
            renderer.createPDF(os);

            os.close();
            os = null;
        } finally {
            if (os != null) {
View Full Code Here

TOP

Related Classes of org.xhtmlrenderer.pdf.ITextRenderer$NullUserInterface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.