var pdf = new PDFObject({ url: "https://something.com/HTC_One_XL_User_Guide.pdf", id: "pdfRendered", pdfOpenParams: { view: "FitH" } }).embed("pdfRenderer");
File file = new File("test.pdf"); RandomAccessFile raf = new RandomAccessFile(file, "r"); FileChannel channel = raf.getChannel(); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); PDFFile pdffile = new PDFFile(buf); // draw the first page to an image PDFPage page = pdffile.getPage(0); //get the width and height for the doc at the default zoom Rectangle rect = new Rectangle(0,0, (int)page.getBBox().getWidth(), (int)page.getBBox().getHeight()); //generate the image Image img = page.getImage( rect.width, rect.height, //width & height rect, // clip rect null, // null for the ImageObserver true, // fill background with white true // block until drawing is done );
PDFFile pdf = new PDFFile(bb); PDFPage PDFpage = pdf.getPage(1, true); for(int i = 2; i <= pdf.getNumPages(); i++) PDFpage = pdf.getPage(i, true); page = PDFpage.getImage((int)(PDFpage.getWidth() * scale), (int)(PDFpage.getHeight() * scale), null, true, true); page.compress(Bitmap.CompressFormat.PNG, 100, stream);
/** * Start this watchable and run for the given amount of time, or until * finished or stopped. * * @param millis the number of milliseconds to run for */ public synchronized void go(long millis) { gate = new Gate(); gate.setStopTime(millis); execute(false); }
/** * set the stroke width * @param w the width of the stroke */ public void addStrokeWidth(float w) { PDFChangeStrokeCmd sc = new PDFChangeStrokeCmd(); // if (w == 0) { // w = 0.1f; // } sc.setWidth(w); addCommand(sc); }
/** * set the dash style * @param dashary the array of on-off lengths * @param phase offset of the array at the start of the line drawing */ public void addDash(float[] dashary, float phase) { PDFChangeStrokeCmd sc = new PDFChangeStrokeCmd(); sc.setDash(dashary, phase); addCommand(sc); }
/** * set the miter limit */ public void addMiterLimit(float limit) { PDFChangeStrokeCmd sc = new PDFChangeStrokeCmd(); sc.setMiterLimit(limit); addCommand(sc); }
/** * set the current path * @param path the path * @param style the style: PDFShapeCmd.STROKE, PDFShapeCmd.FILL, * PDFShapeCmd.BOTH, PDFShapeCmd.CLIP, or some combination. */ public void addPath(GeneralPath path, int style) { addCommand(new PDFShapeCmd(path, style)); }
/** * Parse image data into a Java BufferedImage and add the image * command to the page. * @param obj contains the image data, and a dictionary describing * the width, height and color space of the image. */ private void doImage(PDFObject obj) throws IOException { cmds.addImage(PDFImage.createImage(obj, resources)); }
/** * set the fill paint */ public void addFillPaint(PDFPaint p) { addCommand(new PDFFillPaintCmd(p)); }
/** * set the fill alpha */ public void addFillAlpha(float a) { addCommand(new PDFFillAlphaCmd(a)); }
/** * Get the value as a text string; i.e., a string encoded in UTF-16BE * or PDFDocEncoding. Simple latin alpha-numeric characters are preserved in * both these encodings. * @return the text string value * @throws IOException */ public String getTextStringValue() throws IOException { return PDFStringUtil.asTextString(getStringValue()); }
/** * draw an image * @param image the image to draw */ public void addImage(PDFImage image) { addCommand(new PDFImageCmd(image)); }
File pdfFile = new File("/path/to/pdf.pdf"); RandomAccessFile raf = new RandomAccessFile(pdfFile, "r"); FileChannel channel = raf.getChannel(); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); PDFFile pdf = new PDFFile(buf); PDFPage page = pdf.getPage(0); // create the image Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight()); BufferedImage bufferedImage = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB); Image image = page.getImage(rect.width, rect.height, // width & height rect, // clip rect null, // null for the ImageObserver true, // fill background with white true // block until drawing is done ); Graphics2D bufImageGraphics = bufferedImage.createGraphics(); bufImageGraphics.drawImage(image, 0, 0, null); ImageIO.write(bufferedImage, format, new File( "/path/to/image.jpg" ));
/** * Start this watchable and run for the given amount of time, or until * finished or stopped. * * @param millis the number of milliseconds to run for */ public synchronized void go(long millis) { gate = new Gate(); gate.setStopTime(millis); execute(false); }
/** * set the stroke width * @param w the width of the stroke */ public void addStrokeWidth(float w) { PDFChangeStrokeCmd sc = new PDFChangeStrokeCmd(); // if (w == 0) { // w = 0.1f; // } sc.setWidth(w); addCommand(sc); }
/** * set the current path * @param path the path * @param style the style: PDFShapeCmd.STROKE, PDFShapeCmd.FILL, * PDFShapeCmd.BOTH, PDFShapeCmd.CLIP, or some combination. */ public void addPath(GeneralPath path, int style) { addCommand(new PDFShapeCmd(path, style)); }
/** * Parse image data into a Java BufferedImage and add the image * command to the page. * @param obj contains the image data, and a dictionary describing * the width, height and color space of the image. */ private void doImage(PDFObject obj) throws IOException { cmds.addImage(PDFImage.createImage(obj, resources)); }
FileChannel channel = raf.getChannel(); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); PDFFile pdffile = new PDFFile(buf); int numPgs = pdffile.getNumPages(); for (int i = 0; i < numPgs; i++) { PDFPage page = pdffile.getPage(i); Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight()); Image img = page.getImage(rect.width, rect.height, // width & height
/** * Start this watchable and run for the given amount of time, or until * finished or stopped. * * @param millis the number of milliseconds to run for */ public synchronized void go(long millis) { gate = new Gate(); gate.setStopTime(millis); execute(false); }