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" ));
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 );
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++) {
PDFFile pdf = new PDFFile(bb);
File f = new File(Environment.getExternalStorageDirectory().getPath()+"manual.pdf"); long len = f.length(); RandomAccessFile raf = new RandomAccessFile(f, "r"); FileChannel channel = raf.getChannel(); ByteBuffer bb = ByteBuffer.NEW(channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size())); PDFFile mPdfFile = new PDFFile(bb);
public static int countPages(final byte[] pdfBytes) { final ByteBuffer buf = ByteBuffer.wrap(pdfBytes); PDFFile pdffile; try { pdffile = new PDFFile(buf); return pdffile.getNumPages(); } catch (final IOException e) { log.error("Unable ro read pdf file.", e); } return 0; }
File file = new File("C:\\mmmmm\\nnnnn\\nnn\\tutorial.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); // show the first page PDFPage page = pdffile.getPage(0); panel.setClip(null); panel.useZoomTool(false); panel.showPage(page);
PDFFile pdfFile = new PDFFile(new File(file)); PdfReader pdfReader = pdfFile.getPdfReader(); try { ... } finally { pdfReader.close(); }
byte[] bytes; try { File file = new File("/storage/extSdCard/Test.pdf"); FileInputStream is = new FileInputStream(file); // Get the size of the file long length = file.length(); bytes = new byte[(int) length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) { offset += numRead; } ByteBuffer buffer = ByteBuffer.NEW(bytes); String data = Base64.encodeToString(bytes, Base64.DEFAULT); PDFFile pdf_file = new PDFFile(buffer); PDFPage page = pdf_file.getPage(2, true); RectF rect = new RectF(0, 0, (int) page.getBBox().width(), (int) page.getBBox().height()); Bitmap image = page.getImage((int)rect.width(), (int)rect.height(), rect); FileOutputStream os = new FileOutputStream("/storage/extSdCard/pdf.jpg"); image.compress(Bitmap.CompressFormat.JPEG, 80, os); //((ImageView) findViewById(R.id.testView)).setImageBitmap(image); } catch (Exception e) { e.printStackTrace(); }
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 );
private void initialize(String fileName) throws IOException { jf.setTitle("PDFRenderer Font Toy - " + fileName); try { inputFile = new File(fileName); FileInputStream istr = new FileInputStream(inputFile); byte [] buf = new byte[(int) inputFile.length()]; int read = 0; int offset = 0; while (read >= 0) { read = istr.read(buf, offset, buf.length-offset); } istr.close(); ByteBuffer byteBuf = ByteBuffer.allocate(buf.length); byteBuf.put(buf); pdf = new PDFFile(byteBuf); } catch (Exception ex) { ex.printStackTrace(); } PDFObject root = pdf.getRoot(); PDFObject pagesObj = (PDFObject) root.getDictRef("Pages"); fonts = findFonts(pagesObj, new HashMap<String,PDFObject>()); gfont = new Font("Sans-serif", Font.PLAIN, 10); Object[] fontObjs = getFonts().toArray(); comboBox.setModel(new DefaultComboBoxModel(fontObjs)); fontSelected((PDFFont) fontObjs[0]); this.validate(); }
return new PDFFile(bb);
FileChannel channel = raf.getChannel(); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); PDFFile pdf = new PDFFile(buf);
raf.close(); PDFFile pdf = new PDFFile(bb);
curFile = new PDFFile(bb); // Create PDF Print Page pages = new PDFPrintPage(curFile); PrinterJob pjob = PrinterJob.getPrinterJob();
final PDFFile pdffile = new PDFFile(buf); final int numPgs = pdffile.getNumPages(); if (pageNo > numPgs || pageNo < 1) {
public static void printPdf (String filePath, String jobName) throws IOException, PrinterException { FileInputStream fileInputStream = new FileInputStream(filePath); byte[] pdfContent = new byte[fileInputStream.available()]; fileInputStream.read(pdfContent, 0, fileInputStream.available()); ByteBuffer buffer = ByteBuffer.wrap(pdfContent); final PDFFile pdfFile1 = new PDFFile(buffer); pdf_print_engine pages1 = new pdf_print_engine(pdfFile1); PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pfDefault = PrinterJob.getPrinterJob().defaultPage(); Paper defaultPaper = new Paper(); defaultPaper.setImageableArea(0, 0, defaultPaper.getWidth(), defaultPaper.getHeight()); pfDefault.setPaper(defaultPaper); pjob.setJobName("Test"); if (pjob.printDialog()) { // validate the page against the chosen printer to correct // paper settings and margins pfDefault = pjob.validatePage(pfDefault); Book book = new Book(); book.append(pages1, pfDefault, pdfFile1.getNumPages()); pjob.setPageable(book); try { pjob.print(); } catch (PrinterException exc) { System.out.println(exc); } }
pf.setPaper(paper); PDFFile pdfFile = new PDFFile(bb); PDFPrintPage pages = new PDFPrintPage(pdfFile); pjob.setJobName(f.getName());
ByteBuffer buffer = ByteBuffer.wrap(pdfContent); final PDFFile pdfFile = new PDFFile(buffer); PDFPrintPage pages = new PDFPrintPage(pdfFile); PrinterJob printJob = PrinterJob.getPrinterJob();
FileChannel fc = fis.getChannel(); ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page