doc.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(doc, page);
doc.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(doc, page);
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();
/** * Creates a PDDocument and adds the page parameter to it and keeps this as a template in the * PDF template Structure. * * @param page * @throws IOException */ @Override public void createTemplate(PDPage page) throws IOException { PDDocument template = new PDDocument(); template.addPage(page); pdfStructure.setTemplate(template); }
public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("usage: " + CreateBlankPDF.class.getName() + " <outputfile.pdf>"); System.exit(1); } String filename = args[0]; try (PDDocument doc = new PDDocument()) { // a valid PDF document requires at least one page PDPage blankPage = new PDPage(); doc.addPage(blankPage); doc.save(filename); } } }
public static void main(String[] args) throws IOException, COSVisitorException { PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage( page ); PDPageContentStream contentStream = new PDPageContentStream(doc, page); String[][] content = { {"Name"," Time "}, {"HTC","01:25"}, {"Samsung Tab2","05:30"} } ; drawTable(page, contentStream, 700, 100, content); contentStream.close(); doc.save("h:\\test.pdf" ); }
doc.addPage(page);
//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){}
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); } }
document.addPage(page);
doc.addPage(page);
doc.addPage(page);
doc.addPage(page);
doc.addPage(page);
document.addPage(page);
doc.addPage(page); PDAcroForm acroForm = new PDAcroForm(doc); doc.getDocumentCatalog().setAcroForm(acroForm);
PDStream dest = new PDStream(this, page.getContents(), COSName.FLATE_DECODE); importedPage.setContents(dest); addPage(importedPage); importedPage.setCropBox(page.getCropBox()); importedPage.setMediaBox(page.getMediaBox());
document.addPage(page);
cs.endText(); doc.addPage(page); return new PDFRenderer(doc).renderImage(0);
document.addPage(page);