List of usage examples for com.itextpdf.text Document open
boolean open
To view the source code for com.itextpdf.text Document open.
Click Source Link
From source file:com.github.ossdevs.jhocr.converter.HocrToPdf.java
License:Open Source License
/** * @param pdfXConformance determines into which format the PDF-X will be converted. * @return true if the conversion was successful. *//*from w w w . ja v a 2s .co m*/ private boolean convertToPDFX(int pdfXConformance) { boolean result = false; Document document = new Document(); try { PdfWriter writer = PdfWriter.getInstance(document, getOutputStream()); writer.setPDFXConformance(pdfXConformance); document.open(); document.addHeader(KEY_JHOCR_INFO, KEY_JHOCR_INFO_VALUE); document.setMargins(0, 0, 0, 0); /** * TODO add documentation */ for (HocrDocumentItem item : getItems()) { HocrParser parser = new HocrParser(item.getHocrInputStream()); HocrDocument hocrDocument = parser.parse(); /** * TODO add documentation * TODO add multipage image support */ if (hocrDocument.getPages().size() > 1) { throw new UnsupportedOperationException( "Multipage tif are not yet implemented, please report: http://code.google.com/p/jhocr/issues/list"); } /** * TODO add documentation */ for (HocrPage hocrPage : hocrDocument.getPages()) { HocrPageProcessor pageProcessor = new HocrPageProcessor(hocrPage, item.getImageInputStream(), isUseImageDpi()); if (pageProcessor.isInitialized()) { pageProcessor.process(document, writer); } } } if (!outlines.isEmpty()) { writer.setOutlines(outlines); } /** * Closing the document body stream. */ document.close(); getOutputStream().close(); result = true; } catch (UnsupportedOperationException e) { document.close(); logger.error("This operation is not yet implemented.", e); result = false; } catch (DocumentException e) { document.close(); logger.error("exception while genrating the PDF.", e); result = false; } catch (IOException e) { document.close(); logger.error("FileSystem I/O Exception, please check the log and file system persmissions.", e); result = false; } return result; }
From source file:com.github.ossdevs.jhocr.converter.HocrToPdf.java
License:Open Source License
/** * @param pdfConformanceLevel determines into which format the PDF-A&/B will be converted. * @return true if the conversion was successful. *//*from w ww . j a v a 2s . c o m*/ private boolean convertToPDFA(PdfAConformanceLevel pdfConformanceLevel) { boolean result = false; Document document = new Document(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = Class.class.getClassLoader(); } try { PdfAWriter writer = PdfAWriter.getInstance(document, getOutputStream(), pdfConformanceLevel); writer.createXmpMetadata(); document.open(); document.addHeader(KEY_JHOCR_INFO, KEY_JHOCR_INFO_VALUE); document.setMargins(0, 0, 0, 0); /** * TODO add documentation */ for (HocrDocumentItem item : getItems()) { HocrParser parser = new HocrParser(item.getHocrInputStream()); HocrDocument hocrDocument = parser.parse(); /** * TODO add documentation * TODO add multipage image support */ if (hocrDocument.getPages().size() > 1) { throw new UnsupportedOperationException( "Multipage tif are not yet implemented, please report: http://code.google.com/p/jhocr/issues/list"); } /** * TODO add documentation */ for (HocrPage hocrPage : hocrDocument.getPages()) { HocrPageProcessor pageProcessor = new HocrPageProcessor(hocrPage, item.getImageInputStream(), isUseImageDpi()); if (pageProcessor.isInitialized()) { pageProcessor.process(document, writer); } } } if (!outlines.isEmpty()) { writer.setOutlines(outlines); } InputStream is = this.getClass().getResourceAsStream("/sRGB.profile"); ICC_Profile icc = ICC_Profile.getInstance(is); writer.setOutputIntents(KEY_JHOCR_INFO, KEY_JHOCR_INFO_VALUE, "http://www.color.org", "sRGB IEC61966-2.1", icc); /** * Closing the document body stream. */ document.close(); getOutputStream().close(); result = true; } catch (UnsupportedOperationException e) { document.close(); logger.error("This operation is not yet implemented.", e); result = false; } catch (DocumentException e) { document.close(); logger.error("exception while genrating the PDF.", e); result = false; } catch (IOException e) { document.close(); logger.error("FileSystem I/O Exception, please check the log and file system persmissions.", e); result = false; } return result; }
From source file:com.github.sgelb.sldownloader.model.Pdf.java
License:Open Source License
public void mergePdfs() throws DocumentException, IOException { String title = book.getPdfTitle() + ".pdf"; File saveFile = new File(saveFolder, title); int count = 1; while (saveFile.exists()) { title = book.getPdfTitle() + "_" + count++ + ".pdf"; saveFile = new File(saveFolder, title); }//www . j av a 2 s . c om book.setInfo("saveFile", saveFile.toString()); Document document = new Document(); PdfCopy destPdf = new PdfCopy(document, new FileOutputStream(saveFile)); document.open(); PdfReader reader; int page_offset = 0; int n; ArrayList<HashMap<String, Object>> bookmarks = new ArrayList<HashMap<String, Object>>(); List<HashMap<String, Object>> tmp; count = 1; System.out.println("Start mergin\u2026"); for (File srcPdf : src) { if (Thread.interrupted()) { return; } System.out.print(":: " + count++ + "/" + src.size()); reader = new PdfReader(srcPdf.toString()); tmp = SimpleBookmark.getBookmark(reader); if (tmp != null) { SimpleBookmark.shiftPageNumbers(tmp, page_offset, null); bookmarks.addAll(tmp); } n = reader.getNumberOfPages(); page_offset += n; for (int page = 0; page < n;) { destPdf.addPage(destPdf.getImportedPage(reader, ++page)); } destPdf.freeReader(reader); reader.close(); System.out.println(" succeed."); } if (!bookmarks.isEmpty()) { destPdf.setOutlines(bookmarks); } if (book.getInfo("author") != null) document.addAuthor(book.getInfo("author")); if (book.getInfo("title") != null) document.addTitle(book.getInfo("title")); if (book.getInfo("subtitle") != null) document.addSubject(book.getInfo("subtitle")); document.close(); System.out.println("Merge complete. Saved to " + saveFile); }
From source file:com.github.ukase.bulk.BulkRenderTask.java
License:Open Source License
private void mergeSubTasksPdfs() { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, baos); document.open(); PdfContentByte cb = writer.getDirectContent(); appendPdfs(document, writer, cb); document.close();/*from w w w . ja va2 s. com*/ pdf = baos.toByteArray(); } catch (IOException | DocumentException e) { log.warn("Cannot bulk pdfs", e); } finally { registerResult(); } }
From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java
License:Open Source License
public void createPDF(String outputFile, ArrayList<Question> qlist, boolean showCorrectAnswer, PageCounter pagecounter, int maximumPageNumber, String inputFolder) throws DocumentException, IOException { _inputFolder = inputFolder;//from w w w . j a v a 2 s . co m Document document = new Document(PageSize.A4, 50, 50, 70, 50); PdfWriter pdfwriter = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); pdfwriter.setBoxSize("art", new Rectangle(36, 54, 559, 788)); pdfwriter.setPageEvent(new HeaderFooter(maximumPageNumber)); if (pagecounter != null) { pdfwriter.setPageEvent(pagecounter); } document.open(); Paragraph p = new Paragraph(); // p.setSpacingBefore(SPACING); p.setSpacingAfter(SPACING); p.setIndentationLeft(INDENTATION); writeQuestions(p, document, showCorrectAnswer, qlist); document.close(); }
From source file:com.gp.cong.logisoft.reports.LclExportVoyageNotificationPdf.java
public void createPdf(String realPath, String outputFileName, Long notificationId, String companyName, LclFileNumber fileNumber) throws DocumentException, IOException, Exception { LclExportNotiFicationForm lclExportNotiFicationForm = new LclExportsVoyageNotificationDAO() .getNotificationDetail(notificationId); LclSsDetail lclSsDetail = null;/* w w w . j ava 2s . co m*/ String pod = "", finalDest = ""; String voyageHeading = "Voyage Notification"; if (lclExportNotiFicationForm != null) { lclSsDetail = new LclSsDetailDAO().findByTransMode(lclExportNotiFicationForm.getHeaderId(), "V"); if (lclSsDetail != null) { pod = new LclUtils().getConcatenatedOriginByUnlocation(lclSsDetail.getArrival()); finalDest = new LclUtils() .getConcatenatedOriginByUnlocation(lclSsDetail.getLclSsHeader().getDestination()); } } companyCode = new SystemRulesDAO().getSystemRules("CompanyCode"); String path = LoadLogisoftProperties.getProperty( companyCode.equalsIgnoreCase("03") ? "application.image.logo" : "application.image.econo.logo"); Document document = new Document(PageSize.A4); PdfWriter.getInstance(document, new FileOutputStream(outputFileName)); document.open(); document.add(imageBlock(realPath, path)); document.add(headerPage(voyageHeading)); document.add(informationBlock(companyName, pod, finalDest)); document.add(changesBlock(lclSsDetail, lclExportNotiFicationForm)); document.add(containerBlock(companyName, finalDest, fileNumber, lclExportNotiFicationForm)); document.add(reasonBlock(lclExportNotiFicationForm)); document.add(footerBlock()); document.close(); }
From source file:com.grant.report.BillPdf.java
public void printBill(PrintDetails printDetails) { try {/*from w w w . j a va 2 s. c o m*/ String newInvo = printDetails.getInvoiceNo().replaceAll("\\|", "_"); FILE = "E:/" + newInvo + ".pdf"; invoNo = printDetails.getInvoiceNo(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document, printDetails); //addContent(document); document.close(); } catch (FileNotFoundException | DocumentException e) { e.printStackTrace(); } }
From source file:com.groupecom2015.entitieManager.MessageFacade.java
public void sendBuyingConfirmationEmail(List<ArticlePanier> listArt, CompteUser cu) { Date d = new Date(System.currentTimeMillis()); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD); Font font_2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL); Font font_3 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); double total = 0.0; String resume = ""; try {//from ww w. jav a 2 s. c o m // new File( System.getProperty( "user.home" ) +"/"+ cu.getIdCompte()).mkdirs(); //String FILE = System.getProperty("user.home") +"/"+ cu.getIdCompte()+"/commandeRecu.pdf"; new File("/home/umar/webapp_photo/uploads/" + cu.getIdCompte()).mkdirs(); String FILE = "/home/umar/webapp_photo/uploads/" + cu.getIdCompte() + "/commandRecu.pdf"; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); Paragraph para = new Paragraph(); para.add(new Paragraph(d + "")); para.add(new Paragraph("")); para.add(new Paragraph("Bonjour, " + cu.getNom(), font)); para.add(new Paragraph("Veuillez trouvez ci-dessous votre le rsum de vos achat", font)); para.add(new Paragraph("")); for (ArticlePanier l : listArt) { para.add(new Paragraph( "" + l.getArticle().getNomArticle() + " " + l.getArticle().getPrixVenteArticle(), font_2)); total += l.getArticle().getPrixVenteArticle(); resume = resume + "\n" + l.getArticle().getNomArticle() + " " + l.getArticle().getPrixVenteArticle() + "\n"; } para.add(new Paragraph("Total : " + total, font_3)); para.add(new Paragraph("")); para.add(new Paragraph("Nous vous remercions pour votre achat", font_2)); document.add(para); document.close(); } catch (Exception e) { e.printStackTrace(); } //sending email with the pdf attached --> dropped final String from = "ecomgroup2015@gmail.com"; //ecomgroup2015@gmail.com final String to = "" + cu.getEmail(); final String fileUpload = "/uploads/" + cu.getIdCompte() + "/commandRecu.pdf"; try { Properties properties = new Properties(); properties.put("mail.smtp.host", "smtp.gmail.com"); properties.put("mail.smtp.port", "587"); //587 properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); Session session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, "groupeecom"); } }); javax.mail.Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipients(javax.mail.Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject("Votre recipiss d'achat"); message.setText("Bonjour " + cu.getNom() + "\n Veuillez trouvez ci-joint votre rsum d'achat\n" + "\n " + resume + " \n" + total); /*BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("Cher(e) "+cu.getNom()+"\n veuillez trouver ci-joint votre recipiss d'achat"); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); String filename = "/uploads/"+cu.getIdCompte()+"/commandRecu.pdf"; DataSource source = new FileDataSource(FILE); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(FILE); multipart.addBodyPart(messageBodyPart); // Send the complete message parts message.setContent(multipart);*/ Transport.send(message); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.handpoint.headstart.client.ui.ReceiptActivity.java
License:Apache License
private File createPdfFromReceipt(String html, String fileNamePrefix) { //We cannot trust that the html is well formed org.jsoup.nodes.Document doc = Jsoup.parse(html); html = doc.toString();/* ww w .jav a 2 s . com*/ File file = null; try { Document document = new Document(PageSize.LETTER); file = getOutputMediaFile(fileNamePrefix); PdfWriter instance = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); InputStream is = new ByteArrayInputStream(html.getBytes()); XMLWorkerHelper worker = XMLWorkerHelper.getInstance(); worker.parseXHtml(instance, document, is); document.close(); } catch (Exception e) { logger.log(Level.SEVERE, TAG + " :Failed to create .pdf document from receipt.", e); Toast.makeText(ReceiptActivity.this, getString(R.string.create_pdf), Toast.LENGTH_LONG).show(); } return file; }
From source file:com.havoc.hotel.util.BookingPdf.java
public static String generateBookingPDF(Booking booking) throws DocumentException, FileNotFoundException, IOException { Document document = new Document(PageSize.A4); String bookingname = booking.getFirstName() + " " + booking.getLastName(); document.addHeader("HOTEL HAVOC", "Hotel havoc Booking confirmation"); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE + "Booking" + "" + booking.getCustomer().getFirstName() + ".pdf ")); writer.setViewerPreferences(PdfWriter.PageModeUseOC); writer.setPdfVersion(PdfWriter.VERSION_1_7); document.open(); String html = htmlTemplate(booking); List unorderedList = new List(List.UNORDERED); unorderedList.add(new ListItem("Name :" + booking.getFirstName() + " " + booking.getLastName())); // unorderedList.add(new ListItem("Room Price :" + booking.getRoom().getRoomPrice())); unorderedList.add(new ListItem("Total Price :" + booking.getTotalPrice())); unorderedList.add(new ListItem("check in :" + booking.getCheckinDate())); unorderedList.add(new ListItem("Total Nights:" + booking.getTotalNights())); unorderedList.add(new ListItem("check out :" + booking.getCheckoutDate())); unorderedList.add(new ListItem("Booked By :" + booking.getCustomer().getUsername())); document.add(unorderedList);//from w w w . ja va2s .co m document.close(); return bookingname; }