PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage( page ); PDPageContentStream contentStream = new PDPageContentStream(doc, page); String[][] content = {{"a","b", "1"}, {"c","d", "2"}, {"e","f", "3"}, {"g","h", "4"}, {"i","j", "5"}} ; drawTable(page, contentStream, 700, 100, content); contentStream.close(); doc.save("test.pdf" );
String title = "This is my wonderful title!"; // Or whatever title you want. int marginTop = 30; // Or whatever margin you want. PDDocument document = new PDDocument(); PDPage page = new PDPage() PDPageStreamContent stream = new PDPageContentStream(document, page); PDFont font = PDType1Font.HELVETICA_BOLD; // Or whatever font you want. int fontSize = 16; // Or whatever font size you want. float titleWidth = font.getStringWidth(title) / 1000 * fontSize; float titleHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000 * fontSize; stream.beginText(); stream.setFont(font, fontSize); stream.moveTextPositionByAmount((page.getMediaBox().getWidth() - titleWidth) / 2, page.getMediaBox().getHeight - marginTop - titleheight); stream.drawString(title); stream.endText(); stream.close();
try doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page);
try doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page);
/** * This will write the pdf document. * * @throws IOException If an error occurs while generating the data. * @param doc The document to write. */ public void write(COSDocument doc) throws IOException { PDDocument pdDoc = new PDDocument( doc ); write( pdDoc ); }
/** * Create a PDF document with some text. * * @param text The stream of text data. * * @return The document with the text in it. * * @throws IOException If there is an error writing the data. */ public PDDocument createPDFFromText( Reader text ) throws IOException { PDDocument doc = new PDDocument(); createPDFFromText(doc, text); return doc; }
PDDocument doc=new PDDocument(); PDStream ps=new PDStream(doc); InputStream is=ps.createInputStream();
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" ); }
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){}
/** * This will get the PD document that was parsed. When you are done with * this document you must call close() on it to release resources. * * @return The document at the PD layer. * * @throws IOException If there is an error getting the document. */ public PDDocument getPDDocument() throws IOException { PDDocument doc = new PDDocument(getDocument(), source, getAccessPermission()); doc.setEncryptionDictionary(getEncryption()); return doc; }
PDDocument document = new PDDocument(); document.addPage(page);
String ttfPath = args[2]; try (PDDocument doc = new PDDocument())
String message = args[1]; try (PDDocument doc = new PDDocument())
/** * Create a new document to write the split contents to. * * @return the newly created PDDocument. * @throws IOException If there is an problem creating the new document. */ protected PDDocument createNewDocument() throws IOException { PDDocument document = memoryUsageSetting == null ? new PDDocument() : new PDDocument(memoryUsageSetting); document.getDocument().setVersion(getSourceDocument().getVersion()); document.setDocumentInformation(getSourceDocument().getDocumentInformation()); document.getDocumentCatalog().setViewerPreferences( getSourceDocument().getDocumentCatalog().getViewerPreferences()); return document; }
try (PDDocument doc = new PDDocument())
PDDocument extractedDocument = new PDDocument(); extractedDocument.setDocumentInformation(sourceDocument.getDocumentInformation()); extractedDocument.getDocumentCatalog().setViewerPreferences(