Package org.xhtmlrenderer.util

Examples of org.xhtmlrenderer.util.FSImageWriter


            BufferedImage img = j2d.getImage();

            // write it out, full size, PNG
            // FSImageWriter instance can be reused for different ../images,
            // defaults to PNG
            FSImageWriter imageWriter = new FSImageWriter();
            final File outputFile = new File(reference, page.getName() + ".png");
            outputFile.delete();
            String fileName = outputFile.getPath();
            imageWriter.write(img, fileName);
        } catch (Exception e) {
            System.err.println("Could not render input file to image, skipping: " + page + " err: " + e.getMessage());
            return;
        }
    }
View Full Code Here


            BufferedImage img = j2d.getImage();

            // write it out, full size, PNG
            // FSImageWriter instance can be reused for different ../images,
            // defaults to PNG
            FSImageWriter imageWriter = new FSImageWriter();
            final File outputFile = new File(outputDir, page.getName() + ".png");
            if (outputFile.exists() && !outputFile.delete()) {
                throw new RuntimeException(
                        "On rendering image, could not delete new output file (.delete failed) " +
                                outputFile.getAbsolutePath()
                );
            }
            String fileName = outputFile.getPath();
            imageWriter.write(img, fileName);
        } catch (Exception e) {
            System.err.println("Could not render input file to image, skipping: " + page + " err: " + e.getMessage());
        }
    }
View Full Code Here

            BufferedImage img = j2d.getImage();

            // write it out, full size, PNG
            // FSImageWriter instance can be reused for different ../images,
            // defaults to PNG
            FSImageWriter imageWriter = new FSImageWriter();
            final File outputFile = new File(outputDir, page.getName() + ".png");
            if (outputFile.exists() && !outputFile.delete()) {
                throw new RuntimeException(
                        "On rendering image, could not delete new output file (.delete failed) " +
                                outputFile.getAbsolutePath()
                );
            }
            String fileName = outputFile.getPath();
            imageWriter.write(img, fileName);
        } catch (Exception e) {
            System.err.println("Could not render input file to image, skipping: " + page + " err: " + e.getMessage());
        }
    }
View Full Code Here

    File[] pngs = dir.listFiles(new FileFilter() {
      public boolean accept(File file) {
        return file.getName().endsWith(".png") && file.getName().indexOf("thumb") == - 1;
      }
    });
    FSImageWriter writer = new FSImageWriter("png");
    int width = 141;
    int height = 113;
    for (int i = 0; i < pngs.length; i++) {
      File png = pngs[i];
      try {
        String path = png.getAbsolutePath();
        String tpath = path.substring(0, path.indexOf(".png")) + "-thumb.png";
        BufferedImage bi = ImageIO.read(png);
        Image img = bi.getScaledInstance(width, height, Image.SCALE_FAST);
        bi = ImageUtil.convertToBufferedImage(img, BufferedImage.TYPE_4BYTE_ABGR);
        Graphics g = bi.getGraphics();
        writer.write(bi, tpath);
        System.out.println("Wrote: " + tpath);
      } catch (IOException e) {
        System.err.println("Can't read file, skipping: " + png.getName() + ", " + e.getMessage());
        continue;
      }
View Full Code Here

   * @param width Width in pixels to which the document should be constrained.
   *
   * @throws java.io.IOException if the input URL, or output path location is invalid
   */
  public static BufferedImage renderToImage(String url, String path, int width) throws IOException {
    return renderImageToOutput(url, new FSImageWriter(), path, width);
  }
View Full Code Here

   * @param height Height in pixels to which the document should be constrained.
   *
   * @throws java.io.IOException if the input URL, or output path location is invalid
   */
  public static BufferedImage renderToImage(String url, String path, int width, int height) throws IOException {
    return renderImageToOutput(url, new FSImageWriter(), path, width);
  }
View Full Code Here

      if (f.exists()) {
        Java2DRenderer renderer = new Java2DRenderer(f, 1024);
        renderer.setBufferedImageType(BufferedImage.TYPE_INT_RGB);
        BufferedImage image = renderer.getImage();

        FSImageWriter imageWriter = new FSImageWriter();
        String path = f.getAbsolutePath();
        path = path.substring(0, path.lastIndexOf("."));
        imageWriter.write(image, path + ".png");

        // compare to old
        BufferedImage img = Graphics2DRenderer.renderToImageAutoSize(f.toURI().toURL().toExternalForm(), 1024, BufferedImage.TYPE_INT_ARGB);
        ImageIO.write(img, "png", new File(path + "-G2DR.png"));
View Full Code Here

      }
      renderer.getSharedContext().setUserAgentCallback(agent);

      // Render the page to an image
      BufferedImage img = renderer.getImage();
      FSImageWriter imageWriter = new FSImageWriter(PREVIEW_FORMAT);
      imageFos = new FileOutputStream(imageFile);
      imageWriter.write(img, imageFos);

    } catch (IOException e) {
      logger.error("Error creating temporary copy of file content at " + xhtmlFile, e);
      throw e;
    } catch (XRRuntimeException e) {
View Full Code Here

TOP

Related Classes of org.xhtmlrenderer.util.FSImageWriter

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.