Package org.apache.fop.apps

Examples of org.apache.fop.apps.FopFactory


     * @return  ByteArrayOutputStream containing the binary representation of a PDF document
     * @throws GeneralException
     */
    public static ByteArrayOutputStream render(Writer writer) throws GeneralException {

        FopFactory fopFactory = ApacheFopFactory.instance();

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        TransformerFactory transFactory = TransformerFactory.newInstance();

        try {
            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
            Transformer transformer = transFactory.newTransformer();

            // set the input source (XSL-FO) and generate the PDF
            Reader reader = new StringReader(writer.toString());
            Source src = new StreamSource(reader);

            // Get handler that is used in the generation process
            Result res = new SAXResult(fop.getDefaultHandler());

            try {
                // Transform the FOP XML source into a PDF, hopefully...
                transformer.transform(src, res);

                // We don't want to cache the images that get loaded by the FOP engine
                fopFactory.getImageFactory().clearCaches();

                return out;

            } catch (TransformerException e) {
                Debug.logError("FOP transform failed:" + e, module );
View Full Code Here


   * @throws MojoExecutionException DOCUMENT ME!
   */
  public void postProcessResult(File result) throws MojoExecutionException {
    super.postProcessResult(result);

    final FopFactory fopFactory = FopFactory.newInstance();
    final FOUserAgent userAgent = fopFactory.newFOUserAgent();
    userAgent.setBaseURL(baseUrl);

    // FOUserAgent can be used to set PDF metadata
    Configuration configuration = loadFOPConfig();
    InputStream in = null;
    OutputStream out = null;

    try {
      in = openFileForInput(result);

      final File outputFile = getOutputFile(result);
      out = openFileForOutput(outputFile);
      fopFactory.setUserConfig(configuration);

      Fop fop = fopFactory.newFop(getMimeType(), userAgent, out);

      // Setup JAXP using identity transformer
      TransformerFactory factory = TransformerFactory.newInstance();
      Transformer transformer = factory.newTransformer(); // identity transformer

View Full Code Here

  /**
   * Use Apache FOP to convert the XML FO to a PDF binary stream
   */
  protected InputStream createPdf(String foString) {
    try {
      FopFactory fopFactory = FopFactory.newInstance();
      ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
      Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, byteBuffer);
      TransformerFactory factory = TransformerFactory.newInstance();
      Transformer transformer = factory.newTransformer();
      Result res = new SAXResult(fop.getDefaultHandler());
      Source source = new StreamSource(new StringReader(foString));
      transformer.transform(source, res);
View Full Code Here

        + getFontResourcePath());
    // fopRenderer.processFo(styleSheet, xmlData, data, new PdfFopOutput(baos));
    // return baos.toByteArray();

    // configure fopFactory as desired
    final FopFactory fopFactory = FopFactory.newInstance();
    // Configuration cfg = fopFactory.getUserConfig();

    try {
      fopFactory.getFontManager().setFontBaseURL(getFontResourcePath());
    } catch (final MalformedURLException ex) {
      log.error(ex.getMessage(), ex);
    }
    /*
     * try { fopFactory.setUserConfig(baseDir + "/fop.config"); } catch (SAXException ex) { log.error(ex.getMessage(), ex); throw new
     * RuntimeException(ex); } catch (IOException ex) { log.error(ex.getMessage(), ex); throw new RuntimeException(ex); }
     */
    final FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
    try {
      foUserAgent.getFactory().getFontManager().setFontBaseURL(getFontResourcePath());
    } catch (final MalformedURLException ex) {
      log.error(ex.getMessage(), ex);
    }
    // configure foUserAgent as desired

    InputStream xsltInputStream = null;
    try {
      // Construct fop with desired output format
      final Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baos);

      // Setup XSLT
      final TransformerFactory factory = TransformerFactory.newInstance();
      Object[] result = configXml.getInputStream(stylesheet);
      xsltInputStream = (InputStream) result[0];
View Full Code Here

            params.add("callout.graphics.path");
            params.add(configPath.resolve("docbook/images/callouts/").toUri().toString());

            InputHandler handler = new InputHandler(bookXml.toFile(), configPath.resolve("docbook-config/fo-pdf.xsl").toFile(), params);

            FopFactory fopFactory = FopFactory.newInstance();

            fopFactory.setUserConfig(configPath.resolve("docbook-config/fop.xconf").toFile());
            try (FileOutputStream outputStream = new FileOutputStream(currentPath.resolve("book.pdf").toFile());) {
                FOUserAgent userAgent = new FOUserAgent(fopFactory);
                handler.renderTo(userAgent, "application/pdf", outputStream);
            } finally {
View Full Code Here

            String tabTextDocbook = tabText.concat(".xml");
            Path articlePath = currentPath.resolve(tabTextDocbook);
            Files.write(articlePath, docBook.getBytes(Charset.forName("UTF-8")), CREATE, TRUNCATE_EXISTING, WRITE);
            InputHandler handler = new InputHandler(articlePath.toFile(), configPath.resolve("docbook-config/fo-pdf.xsl").toFile(), params);

            FopFactory fopFactory = FopFactory.newInstance();

            fopFactory.setUserConfig(configPath.resolve("docbook-config/fop.xconf").toFile());
            try (FileOutputStream outputStream = new FileOutputStream(currentPath.resolve(tabText.concat(".pdf")).toFile());) {
                FOUserAgent userAgent = new FOUserAgent(fopFactory);
                handler.renderTo(userAgent, "application/pdf", outputStream);
            } finally {
View Full Code Here

    private Font[] fonts;

  public void postProcessResult(File result) throws MojoExecutionException {
    super.postProcessResult(result);
   
    final FopFactory fopFactory = FopFactory.newInstance();
    final FOUserAgent userAgent = fopFactory.newFOUserAgent();
    userAgent.setBaseURL(baseUrl);
    // FOUserAgent can be used to set PDF metadata

  Configuration configuration = loadFOPConfig();
    InputStream in = null;
    OutputStream out = null;
   
    try
    {
      in = openFileForInput(result);
      out = openFileForOutput(getOutputFile(result));
      fopFactory.setUserConfig(configuration);
      Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, out);
           
      // Setup JAXP using identity transformer
      TransformerFactory factory = TransformerFactory.newInstance();
      Transformer transformer = factory.newTransformer(); // identity transformer
     
View Full Code Here

    if(processing != null)
      processing.setMinMax(0, 100);
    Transformer transformer = TransformerFactory.newInstance().newTemplates(createXSLStream()).newTransformer();
    if(processing != null)
      processing.setValue(33);
    FopFactory fopFactory = FopFactory.newInstance();
    Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_AWT_PREVIEW);
    if(processing != null)
      processing.setValue(66);
    transformer.transform(createVelocityStream(), new SAXResult(fop.getDefaultHandler()));
    if(processing != null)
      processing.setValue(100);
View Full Code Here

    if(progress != null)
      progress.setValue(20);

    Transformer transformer = TransformerFactory.newInstance().newTemplates(source).newTransformer();
    FopFactory fopFactory = FopFactory.newInstance();
    FOUserAgent agent = fopFactory.newFOUserAgent();
    AWTRenderer renderer = new AWTRenderer();
    agent.setRendererOverride(renderer);
    renderer.setPreviewDialogDisplayed(false);
    renderer.setUserAgent(agent);
    renderer.clearViewportList();
    Fop fop = fopFactory.newFop(agent);

    if(progress != null)
      progress.setValue(50);

    transformer.transform(createVelocityStream(), new SAXResult(fop.getDefaultHandler()));
View Full Code Here

    zoom.setMinorTickSpacing(10);
    zoom.setPaintTicks(true);
    zoom.setPaintLabels(true);


    final FopFactory fopFactory = FopFactory.newInstance();
    final FOUserAgent agent = fopFactory.newFOUserAgent();
    AWTRenderer renderer = new AWTRenderer();
    agent.setRendererOverride(renderer);
    renderer.setPreviewDialogDisplayed(false);
    renderer.setUserAgent(agent);
    renderer.clearViewportList();

    final PreviewPanel previewPanel = new PreviewPanel(agent, null, renderer);

    zoom.addChangeListener(new ChangeListener() {
      @Override
      public void stateChanged(ChangeEvent e) {
        double value = zoom.getValue();
        previewPanel.setScaleFactor(value/100);
      }
    });

    final JProgressBar progress = new JProgressBar(0, 100);

    JDialog dialog = new JDialog(parent);
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(zoom, BorderLayout.NORTH);
    dialog.getContentPane().add(previewPanel, BorderLayout.CENTER);
    dialog.getContentPane().add(progress, BorderLayout.SOUTH);
    dialog.setSize(600, 800);
    dialog.setVisible(true);

    SwingWorker swingWorker = new SwingWorker() {
      @Override
      protected Object doInBackground() throws Exception {
        Source source = createXSLStream();
        progress.setValue(10);

        Transformer transformer = TransformerFactory.newInstance().newTemplates(source).newTransformer();
        Fop fop = fopFactory.newFop(agent);
        StreamSource streamSource = createVelocityStream();
        progress.setValue(50);

        SAXResult saxr = new SAXResult(fop.getDefaultHandler());
        progress.setValue(65);
View Full Code Here

TOP

Related Classes of org.apache.fop.apps.FopFactory

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.