public void close() throws IOException { this.pdfDocument.close(); }
PDDocument document = new PDDocument(); InputStream in = new FileInputStream(someImage); BufferedImage bimg = ImageIO.read(in); float width = bimg.getWidth(); float height = bimg.getHeight(); PDPage page = new PDPage(new PDRectangle(width, height)); document.addPage(page); PDXObjectImage img = new PDJpeg(document, new FileInputStream(someImage)); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.drawImage(img, 0, 0); contentStream.close(); in.close(); document.save("test.pdf"); document.close();
/** * Gets PDF Page Count. * * @param inputPdfFile input file * @return number of pages */ public static int getPdfPageCount(File inputPdfFile) { PDDocument document = null; try { document = PDDocument.load(inputPdfFile); return document.getNumberOfPages(); } catch (IOException ioe) { logger.error("Error counting PDF pages => " + ioe); return - 1; } finally { if (document != null) { try { document.close(); } catch (Exception e) { } } } }
private void exitMenuItemActionPerformed(ActionEvent ignored) { if( document != null ) { try { document.close(); if (!currentFilePath.startsWith("http")) { recentFiles.addFile(currentFilePath); } recentFiles.close(); } catch( IOException e ) { throw new RuntimeException(e); } } performApplicationExit(); }
cosDoc.close(); if (pdDoc != null) pdDoc.close(); } catch (Exception e1) { e.printStackTrace();
public static BufferedImage pageConvertToImage(PDPage page, int dpi, ImageType imageType) throws IOException { try (PDDocument document = new PDDocument()) { document.addPage(page); PDFRenderer renderer = new PDFRenderer(document); document.close(); return renderer.renderImageWithDPI(0, dpi, imageType); } }
//Using PDFBox library available from http://pdfbox.apache.org/ //Writes pdf document of specific pages as a new pdf file //Reads in pdf document PDDocument pdDoc = PDDocument.load(file); //Creates a new pdf document PDDocument document = null; //Adds specific page "i" where "i" is the page number and then saves the new pdf document try { document = new PDDocument(); document.addPage((PDPage) pdDoc.getDocumentCatalog().getAllPages().get(i)); document.save("file path"+"new document title"+".pdf"); document.close(); }catch(Exception e){}
pdf.close();
document.close();
private void setField(String[] args) throws IOException { PDDocument pdf = null; try { if (args.length != 3) { usage(); } else { SetField example = new SetField(); pdf = PDDocument.load(new File(args[0])); example.setField(pdf, args[1], args[2]); pdf.save(args[0]); } } finally { if (pdf != null) { pdf.close(); } } }
document.close(); if (!currentFilePath.startsWith("http"))
document.close(); if (!currentFilePath.startsWith("http"))
try { if (pdfDocument != null) { pdfDocument.close();
} finally { if (pdfDocument != null) { pdfDocument.close();
doc.close();