List of usage examples for org.apache.pdfbox.pdmodel PDDocument save
public void save(OutputStream output) throws IOException
From source file:PDF.RotatePDF.java
public void rotate(double degree) throws IOException, COSVisitorException { if (FILENAME != null) { String destFileName = FILENAME.replace(".PDF", ".pdf"); destFileName = FILENAME.replace(".pdf", "_rotated.pdf"); final PDDocument document = PDDocument.load(FILENAME); final AffineTransform transform = AffineTransform.getRotateInstance(degree);// List<PDPage> pages = document.getDocumentCatalog().getAllPages();// for (PDPage page : pages) { transformPage(document, page, transform); }//w w w.j a va 2 s . com document.save(destFileName); JOptionPane.showMessageDialog(null, "The pdf file is successfully rotated."); } }
From source file:pdf.StockItemsPDF.java
public String createStockItems() throws IOException { PDDocument document = PDDocument.load(template); //prva strana PDPage page = document.getPage(0);// ww w .ja v a 2 s .c o m contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false); this.insertProducts(); this.stockItemsInfo(); contentStream.close(); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy."); String path = "pdf_docs\\stock_items\\" + "stock_item_" + dateOfWriteOff.getTime() + ".pdf"; document.save(path); //createStockItemsPNG(path); document.close(); return path; }
From source file:pdf.SuppliesListPDF.java
public String createSuppliesList() throws IOException { PDDocument document = PDDocument.load(template); //prva strana PDPage page = document.getPage(0);// ww w. j a v a 2s.c o m contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false); this.insertSupplies(); this.suppliesListInfo(); contentStream.close(); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy."); String path = "pdf_docs\\lager_lists\\" + "supplies_list_" + dateSuppliesList.getTime() + ".pdf"; document.save(path); //createDailyReportPNG(path); document.close(); return path; }
From source file:pdf.WorkOrderPDF.java
public void createWorkOrder() throws IOException { PDDocument document = PDDocument.load(template); //prva strana PDPage page = document.getPage(0);/* ww w . j a v a 2 s .c o m*/ contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false); this.insertProducts(); this.insertSupplies(); this.workOrderInfo(); document.save("pdf_docs\\work_orders\\" + "work_order_" + numOfWorkOrder.split("\\/")[0] + "_" + numOfWorkOrder.split("/")[1] + ".pdf"); document.close(); }
From source file:pdf.WriteOffMaterialsPDF.java
public void createWriteOffMaterials() throws IOException { PDDocument document = PDDocument.load(template); //prva strana PDPage page = document.getPage(0);// w w w.j ava 2 s . c o m contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false); this.insertSupplies(); this.writeOffMaterialsInfo(); contentStream.close(); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy."); String path = "pdf_docs\\write_off_materials\\" + "write_off_materials-" + sdf.format(dateOfWriteOff) + ".pdf"; document.save(path); createWriteOffMaterialsPNG(path); document.close(); }
From source file:pdf.WriteOffProductsPDF.java
public void createWriteOffProducts() throws IOException { PDDocument document = PDDocument.load(template); //prva strana PDPage page = document.getPage(0);/*www . j a v a2s .c o m*/ contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false); this.insertProducts(); this.writeOffProductsInfo(); contentStream.close(); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy."); String path = "pdf_docs\\write_off_products\\" + "write_off_products-" + sdf.format(dateOfWriteOff) + ".pdf"; document.save(path); createWriteOffProductsPNG(path); document.close(); }
From source file:pdfbox.PDFA3File.java
License:Apache License
/** * Create a simple PDF/A-3 document./*from w w w. j a v a2 s .c o m*/ * This example is based on HelloWorld example. * As it is a simple case, to conform the PDF/A norm, are added : - the font * used in the document - the sRGB color profile - a light xmp block with only * PDF identification schema (the only mandatory) - an output intent To * conform to A/3 - the mandatory MarkInfo dictionary displays tagged PDF * support - and optional producer and - optional creator info is added * * @param file * The file to write the PDF to. * @param message * The message to write in the file. * @throws Exception * If something bad occurs */ public void doIt(String file, String message) throws Exception { // the document PDDocument doc = null; try { doc = new PDDocument(); // now create the page and add content PDPage page = new PDPage(); doc.addPage(page); InputStream fontStream = PDFA3File.class.getResourceAsStream("/Ubuntu-R.ttf"); PDFont font = PDTrueTypeFont.loadTTF(doc, fontStream); // create a page with the message where needed PDPageContentStream contentStream = new PDPageContentStream(doc, page); contentStream.beginText(); contentStream.setFont(font, 12); contentStream.moveTextPositionByAmount(100, 700); contentStream.drawString(message); contentStream.endText(); contentStream.saveGraphicsState(); contentStream.close(); PDDocumentCatalog cat = makeA3compliant(doc); InputStream colorProfile = PDFA3File.class.getResourceAsStream("/sRGB Color Space Profile.icm"); // create output intent PDOutputIntent oi = new PDOutputIntent(doc, colorProfile); oi.setInfo("sRGB IEC61966-2.1"); oi.setOutputCondition("sRGB IEC61966-2.1"); oi.setOutputConditionIdentifier("sRGB IEC61966-2.1"); oi.setRegistryName("http://www.color.org"); cat.addOutputIntent(oi); doc.save(file); } finally { if (doc != null) { doc.close(); } } }
From source file:pdfbox.PDFA3FileAttachment.java
License:Apache License
/** * Create a simple PDF/A-3 document./*from ww w . j av a 2 s. c o m*/ * This example is based on HelloWorld example. * As it is a simple case, to conform the PDF/A norm, are added : - the font * used in the document - the sRGB color profile - a light xmp block with only * PDF identification schema (the only mandatory) - an output intent To * conform to A/3 - the mandatory MarkInfo dictionary displays tagged PDF * support - and optional producer and - optional creator info is added * * @param file * The file to write the PDF to. * @param message * The message to write in the file. * @throws Exception * If something bad occurs */ public void doIt(String file, String message) throws Exception { // the document PDDocument doc = null; try { doc = new PDDocument(); // now create the page and add content PDPage page = new PDPage(); doc.addPage(page); InputStream fontStream = PDFA3FileAttachment.class.getResourceAsStream("/Ubuntu-R.ttf"); PDFont font = PDTrueTypeFont.loadTTF(doc, fontStream); // create a page with the message where needed PDPageContentStream contentStream = new PDPageContentStream(doc, page); contentStream.beginText(); contentStream.setFont(font, 12); contentStream.moveTextPositionByAmount(100, 700); contentStream.drawString(message); contentStream.endText(); contentStream.saveGraphicsState(); contentStream.close(); PDDocumentCatalog cat = makeA3compliant(doc); attachSampleFile(doc); InputStream colorProfile = PDFA3FileAttachment.class .getResourceAsStream("/sRGB Color Space Profile.icm"); // create output intent PDOutputIntent oi = new PDOutputIntent(doc, colorProfile); oi.setInfo("sRGB IEC61966-2.1"); oi.setOutputCondition("sRGB IEC61966-2.1"); oi.setOutputConditionIdentifier("sRGB IEC61966-2.1"); oi.setRegistryName("http://www.color.org"); cat.addOutputIntent(oi); doc.save(file); } finally { if (doc != null) { doc.close(); } } }
From source file:pdfbox.PDFAFile.java
License:Apache License
/** * Create a simple PDF/A document./* w ww . j a v a2s .co m*/ * This example is based on HelloWorld example. * As it is a simple case, to conform the PDF/A norm, are added : - the font * used in the document - a light xmp block with only PDF identification * schema (the only mandatory) - an output intent * * @param file * The file to write the PDF to. * @param message * The message to write in the file. * @throws Exception * If something bad occurs */ public void doIt(String file, String message) throws Exception { // the document PDDocument doc = null; try { doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); InputStream fontStream = PDFA3File.class.getResourceAsStream("/Ubuntu-R.ttf"); PDFont font = PDTrueTypeFont.loadTTF(doc, fontStream); // create a page with the message where needed PDPageContentStream contentStream = new PDPageContentStream(doc, page); contentStream.beginText(); contentStream.setFont(font, 12); contentStream.moveTextPositionByAmount(100, 700); contentStream.drawString(message); contentStream.endText(); contentStream.saveGraphicsState(); contentStream.close(); PDDocumentCatalog cat = doc.getDocumentCatalog(); PDMetadata metadata = new PDMetadata(doc); cat.setMetadata(metadata); // jempbox version XMPMetadata xmp = new XMPMetadata(); XMPSchemaPDFAId pdfaid = new XMPSchemaPDFAId(xmp); xmp.addSchema(pdfaid); pdfaid.setConformance("B"); pdfaid.setPart(1); pdfaid.setAbout(""); metadata.importXMPMetadata(xmp.asByteArray()); InputStream colorProfile = PDFA3File.class.getResourceAsStream("/sRGB Color Space Profile.icm"); // create output intent PDOutputIntent oi = new PDOutputIntent(doc, colorProfile); oi.setInfo("sRGB IEC61966-2.1"); oi.setOutputCondition("sRGB IEC61966-2.1"); oi.setOutputConditionIdentifier("sRGB IEC61966-2.1"); oi.setRegistryName("http://www.color.org"); cat.addOutputIntent(oi); doc.save(file); } finally { if (doc != null) { doc.close(); } } }
From source file:pdfboxtest.PDFBoxTest.java
/** *///from w w w .ja v a 2 s . c o m public static void main(String[] args) throws Exception { GetFundamentals go = new GetFundamentals(); // Create a document and add a page to it go.ticker = "AAN"; String outputFileName = go.ticker + ".pdf"; PDDocument document = new PDDocument(); PDPage page1 = new PDPage(PDPage.PAGE_SIZE_LETTER); PDPage page2 = new PDPage(PDPage.PAGE_SIZE_LETTER); PDPage page3 = new PDPage(PDPage.PAGE_SIZE_LETTER); PDPage page4 = new PDPage(PDPage.PAGE_SIZE_LETTER); // PDPage.PAGE_SIZE_LETTER is also possible // rect can be used to get the page width and height document.addPage(page1); document.addPage(page2); document.addPage(page3); document.addPage(page4); // Create a new font object selecting one of the PDF base fonts PDFont fontPlain = PDType1Font.HELVETICA_BOLD; // Start a new content stream which will "hold" the to be created content PDPageContentStream cos = new PDPageContentStream(document, page1); // Define a text content stream using the selected font, move the cursor and draw some text setupDefault(cos, fontPlain, document, go); setupP1(cos, fontPlain, document, go.ticker); cos.close(); cos = new PDPageContentStream(document, page2); setupDefault(cos, fontPlain, document, go); setupP2(cos, fontPlain, document); cos.close(); cos = new PDPageContentStream(document, page3); setupDefault(cos, fontPlain, document, go); setupP3(cos, fontPlain, document); cos.close(); cos = new PDPageContentStream(document, page4); setupDefault(cos, fontPlain, document, go); setupP4(cos, fontPlain, document); cos.close(); // Make sure that the content stream is closed: // Save the results and ensure that the document is properly closed: document.save(outputFileName); document.close(); }