List of usage examples for org.apache.pdfbox.pdmodel PDDocument close
@Override public void close() throws IOException
From source file:pdf.NormativPDF.java
public void createNormativPNG(String path) throws IOException { File file = new File(path); PDDocument doc = PDDocument.load(file); PDFRenderer renderer = new PDFRenderer(doc); BufferedImage image = renderer.renderImage(0); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy."); ImageIO.write(image, "PNG", new File( "pdf_docs\\normativ_picture\\" + product.getName() + "-" + sdf.format(dateNormativ) + ".png")); doc.close(); }
From source file:pdf.NormativPDF.java
public String createNormativ() throws IOException { PDDocument document = PDDocument.load(template); //prva strana PDPage page = document.getPage(0);//from w ww . ja va2 s. c o m contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false); this.insertSupplies(); this.insertProduct(); this.normativInfo(); contentStream.close(); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy."); String path = "pdf_docs\\norms\\" + "norm" + "_" + dateNormativ.getTime() + ".pdf"; document.save(path); //createNormativPNG(path); document.close(); return path; }
From source file:PDF.PDFDateStamp.java
public void generatePDFFile(String pdfFileName) throws IOException, COSVisitorException { PDDocument pdf = PDDocument.load(pdfFileName); List pages = pdf.getDocumentCatalog().getAllPages(); Iterator<PDPage> iter = pages.iterator(); while (iter.hasNext()) { PDPage page = iter.next();/*from w ww.j a va 2 s . c o m*/ PDPageContentStream stream = new PDPageContentStream(pdf, page, true, false); // == date stamp stream.beginText(); stream.setFont(PDType1Font.HELVETICA, GlobalVar.DATE_STAMP_FONT_SIZE); stream.moveTextPositionByAmount(GlobalVar.DATE_STAMP_X_POSITION, GlobalVar.DATE_STAMP_Y_POSITION); stream.drawString(DATE); //date stamp stream.endText(); // end of date stamp stream.close(); } // out put two pdf files: one for audit, the other for reject pdfFileName = pdfFileName.replace(".pdf", "_DateStamped.pdf"); pdf.save(pdfFileName); pdf.close(); }
From source file:PDF.PDFDateStampPartial.java
private void generatePDFFile(String pdfFileName, Boolean[][] statusArray, String date) throws IOException, COSVisitorException { PDDocument pdf = PDDocument.load(pdfFileName); List pages = pdf.getDocumentCatalog().getAllPages(); Iterator<PDPage> iter = pages.iterator(); int pageNum = 0; // 0 based //int sequenceNum = 1; // start from 0001 PDDocument pdfBlank = new PDDocument(); while (iter.hasNext()) { PDPage page = iter.next();//from w w w . j a va 2 s .c o m PDPage pageBlank = new PDPage(); PDPageContentStream stream = new PDPageContentStream(pdf, page, true, false); PDPageContentStream streamBlank = new PDPageContentStream(pdfBlank, pageBlank, true, false); // == seq stamp if (statusArray[GlobalVar.SELECT_BUTTON_INDEX][pageNum]) { pageWrite(stream, date); pageWrite(streamBlank, date); } // == end of seq stamp pdfBlank.addPage(pageBlank); stream.close(); streamBlank.close(); pageNum++; } // out put two pdf files: one is template for printer print hardcopies, the other is digital copy String suffix = "_P dateStamped.pdf"; pdfFileName = pdfFileName.replace(".pdf", suffix); String blankPdfFileName = pdfFileName.replace(".pdf", "BLANK.pdf"); pdf.save(pdfFileName); pdfBlank.save(blankPdfFileName); pdf.close(); pdfBlank.close(); }
From source file:PDF.PDFEditor.java
public void generatePDFFile(String date, String pdfFileName, Boolean[][] statusArray, String cycle) throws IOException, COSVisitorException { PDDocument pdf = PDDocument.load(pdfFileName); PDDocument blanPdf = new PDDocument(); List pages = pdf.getDocumentCatalog().getAllPages(); Iterator<PDPage> iter = pages.iterator(); int pageNum = 0; // 0 based int sequenceNum = 1; // start from 0001 while (iter.hasNext()) { PDPage page = iter.next();/*from w ww . j a v a 2 s . c o m*/ PDPageContentStream stream = new PDPageContentStream(pdf, page, true, false); // == date stamp stream.beginText(); stream.setFont(PDType1Font.HELVETICA, 20); stream.moveTextPositionByAmount(200, 20); stream.drawString(date); //date stamp stream.endText(); // == end of date stamp // // == void stamp // if (statusArray[GlobalVar.VOID_BUTTON_INDEX][pageNum]) { // stream.drawImage(voidMark, 0, 0); // } // == end of void stamp // == seq stamp if (statusArray[GlobalVar.SELECT_BUTTON_INDEX][pageNum]) { stream.beginText(); stream.setFont(PDType1Font.HELVETICA, 24); stream.moveTextPositionByAmount(600, 400); stream.setTextRotation(3.14 / 2, 600, 400); // rotate text 90 degree at x = 600, y = 400 stream.drawString(cycle + "/" + GlobalVar.globalCountGenerator5Digit(sequenceNum)); sequenceNum++; stream.endText(); } // == end of seq stamp stream.close(); pageNum++; } // out put two pdf files: one for audit, the other for reject String rejectPdfFileName = pdfFileName.replace(".pdf", "_forReject.pdf"); String auditPdfFileName = pdfFileName.replace(".pdf", "_forAudit.pdf"); extractGoodBadPdf(pdf, auditPdfFileName, rejectPdfFileName, statusArray); pdf.close(); }
From source file:PDF.PDFEditor.java
private void extractGoodBadPdf(PDDocument pdf, String auditPdfFileName, String rejectPdfFileName, Boolean[][] statusArray) throws COSVisitorException, IOException { PDDocument rejectPdf = new PDDocument(); PDDocument auditPdf = new PDDocument(); int pageNum = pdf.getNumberOfPages(); // add reject page into rejectPdf for (int i = 0; i < pageNum; i++) { PDPage page = (PDPage) pdf.getDocumentCatalog().getAllPages().get(i); if (statusArray[GlobalVar.VOID_BUTTON_INDEX][i]) { rejectPdf.addPage(page);//w w w .j a v a 2 s .c om } else { auditPdf.addPage(page); } } rejectPdf.save(rejectPdfFileName); rejectPdf.close(); auditPdf.save(auditPdfFileName); auditPdf.close(); }
From source file:PDF.PDFNumbering.java
public PDFNumbering(String pdfFileName) throws IOException, COSVisitorException { String cycle = JOptionPane.showInputDialog(null, "Please enter a cycle number"); PDDocument pdf = PDDocument.load(pdfFileName); List pages = pdf.getDocumentCatalog().getAllPages(); PDFTextStripper pdfStripper = new PDFTextStripper(); String res = pdfStripper.getText(pdf); //System.out.println(res); Boolean isPreProcessed = res.contains(GlobalVar.PRE_PROC_KEY_SYMBOL); // check if the file is pre-processed. Boolean isNumbered = res.contains("/0"); Iterator<PDPage> iter = pages.iterator(); int sequenceNum = 1; // start from 0001 if (isPreProcessed && isNumbered) { GlobalVar.updateSeqNum(pdf, cycle); // update the sequence number } else if (isPreProcessed) { // first time int pageNumber = 1; while (iter.hasNext()) { PDPage page = iter.next();//from w ww.ja v a 2 s. c o m pdfStripper.setStartPage(pageNumber); pdfStripper.setEndPage(pageNumber); res = pdfStripper.getText(pdf); // == numbering if (res.contains(GlobalVar.PRE_PROC_KEY_SYMBOL)) { PDPageContentStream stream = new PDPageContentStream(pdf, page, true, false); stream.beginText(); stream.setFont(PDType1Font.HELVETICA, GlobalVar.SEQ_NUM_FONT_SIZE); stream.moveTextPositionByAmount(GlobalVar.SEQ_NUM_TEXT_X_POSITION, GlobalVar.SEQ_NUM_TEXT_Y_POSITION); stream.setTextRotation(3.14 / 2, GlobalVar.SEQ_NUM_TEXT_X_POSITION, GlobalVar.SEQ_NUM_TEXT_Y_POSITION); // rotate text 90 degree at x = 600, y = 400 stream.drawString(cycle + "/" + GlobalVar.globalCountGenerator5Digit(sequenceNum)); sequenceNum++; stream.endText(); stream.close(); } pageNumber++; // end of numbering } } else { //not pre processed while (iter.hasNext()) { PDPage page = iter.next(); PDPageContentStream stream = new PDPageContentStream(pdf, page, true, false); // == numbering stream.beginText(); stream.setFont(PDType1Font.HELVETICA, GlobalVar.SEQ_NUM_FONT_SIZE); stream.moveTextPositionByAmount(GlobalVar.SEQ_NUM_TEXT_X_POSITION, GlobalVar.SEQ_NUM_TEXT_Y_POSITION); stream.setTextRotation(3.14 / 2, GlobalVar.SEQ_NUM_TEXT_X_POSITION, GlobalVar.SEQ_NUM_TEXT_Y_POSITION); // rotate text 90 degree at x = 600, y = 400 stream.drawString(cycle + "/" + GlobalVar.globalCountGenerator5Digit(sequenceNum)); sequenceNum++; stream.endText(); stream.close(); } } // out put two pdf files: one for audit, the other for reject String suffix = "_" + cycle + " Numbered.pdf"; pdfFileName = pdfFileName.replace(".pdf", suffix); pdf.save(pdfFileName); pdf.close(); }
From source file:PDF.PDFNumberingPartial.java
private void generatePDFFile(String pdfFileName, Boolean[][] statusArray, String cycle) throws IOException, COSVisitorException { PDDocument pdf = PDDocument.load(pdfFileName); List pages = pdf.getDocumentCatalog().getAllPages(); Iterator<PDPage> iter = pages.iterator(); PDDocument pdfBlank = new PDDocument(); int pageNum = 0; // 0 based int sequenceNum = 1; // start from 0001 while (iter.hasNext()) { PDPage page = iter.next();/* w ww . ja va 2s . c o m*/ PDPage pageBlank = new PDPage(); PDPageContentStream stream = new PDPageContentStream(pdf, page, true, false); PDPageContentStream streamBlank = new PDPageContentStream(pdfBlank, pageBlank, true, false); if (statusArray[GlobalVar.SELECT_BUTTON_INDEX][pageNum]) { pageWrite(stream, sequenceNum, cycle); pageWrite(streamBlank, sequenceNum, cycle); sequenceNum++; } pdfBlank.addPage(pageBlank); stream.close(); streamBlank.close(); pageNum++; } // out put two pdf files: one is template for printer print hardcopies, the other is digital copy String suffix = "_" + cycle + "_P numbered.pdf"; pdfFileName = pdfFileName.replace(".pdf", suffix); String blankPdfFileName = pdfFileName.replace(".pdf", "BLANK.pdf"); pdf.save(pdfFileName); pdfBlank.save(blankPdfFileName); pdf.close(); pdfBlank.close(); }
From source file:PDF.PDFRemover.java
public void generatePDFFile(String pdfFileName, Boolean[][] statusArray) throws IOException, COSVisitorException { PDDocument pdf = PDDocument.load(pdfFileName); String truncatedPdfFileName = pdfFileName.replace(".pdf", "_Truncated.pdf"); extractGoodPdf(pdf, truncatedPdfFileName, statusArray); pdf.close(); }
From source file:PDF.PDFRemover.java
private void extractGoodPdf(PDDocument pdf, String auditPdfFileName, Boolean[][] statusArray) throws COSVisitorException, IOException { PDDocument auditPdf = new PDDocument(); int pageNum = pdf.getNumberOfPages(); // add reject page into rejectPdf for (int i = 0; i < pageNum; i++) { PDPage page = (PDPage) pdf.getDocumentCatalog().getAllPages().get(i); if (!statusArray[GlobalVar.VOID_BUTTON_INDEX][i]) { auditPdf.addPage(page);/*w w w. j a v a 2 s .c o m*/ } } auditPdf.save(auditPdfFileName); auditPdf.close(); }