List of usage examples for com.itextpdf.text Document Document
public Document(Rectangle pageSize)
Document
-object. 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();/*from w ww . j a v a2 s . co m*/ PdfContentByte cb = writer.getDirectContent(); appendPdfs(document, writer, cb); document.close(); pdf = baos.toByteArray(); } catch (IOException | DocumentException e) { log.warn("Cannot bulk pdfs", e); } finally { registerResult(); } }
From source file:com.gp.cong.logisoft.lcl.report.LclConsolidationMiniManifestPdfCreator.java
public void createReport(String realPath, String reportLocation, String documentName, String fileId) throws FileNotFoundException, DocumentException, Exception { LCLBlDAO lCLBlDAO = new LCLBlDAO(); document = new Document(PageSize.LEGAL.rotate()); pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(reportLocation)); bl = lCLBlDAO.getByProperty("lclFileNumber.id", Long.parseLong(fileId)); lCLBlDAO.getCurrentSession().evict(bl); ruleName = bl.getLclFileNumber().getBusinessUnit(); Long fileid = Long.parseLong(fileId); setValues(bl, fileid);/*from ww w . ja v a2s. co m*/ LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent event = new LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent(); pdfWriter.setPageEvent(event); document.open(); document.add(consigneeTable()); document.add(consolidateTable(fileId)); document.close(); }
From source file:com.gp.cong.logisoft.lcl.report.LclConsolidationMiniManifestPdfCreator.java
public String createEmailReport(String realPath, String outputFileName, ExportVoyageHblBatchForm batchForm) throws Exception { List<Long> actualDrList = new ArrayList<Long>(); boolean isConsolidate = false; if (CommonUtils.isNotEmpty(batchForm.getFileNumberId())) { actualDrList.add(Long.parseLong(batchForm.getFileNumberId())); } else {/*from ww w . j av a 2s . c o m*/ actualDrList = new ExportUnitQueryUtils().getAllPickedCargoBkg(Long.parseLong(batchForm.getHeaderId()), Long.parseLong(batchForm.getUnitSSId())); } if (CommonUtils.isNotEmpty(actualDrList)) { for (Long fileId : actualDrList) { isConsolidate = new LclConsolidateDAO().isConsoildateFile(String.valueOf(fileId)); if (isConsolidate) { LCLBlDAO lCLBlDAO = new LCLBlDAO(); bl = lCLBlDAO.getByProperty("lclFileNumber.id", fileId); lCLBlDAO.getCurrentSession().evict(bl); ruleName = bl.getLclFileNumber().getBusinessUnit(); setValues(bl, fileId); if (!isNew) { document = new Document(PageSize.LEGAL.rotate()); pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(outputFileName)); LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent event = new LclConsolidationMiniManifestPdfCreator.LclConsolidationMiniManifestPageEvent(); pdfWriter.setPageEvent(event); document.open(); } if (!documentOpenFlag) { documentOpenFlag = true; isNew = true; document.add(consigneeTable()); document.add(consolidateTable(String.valueOf(fileId))); } else { document.newPage(); document.add(consigneeTable()); document.add(consolidateTable(String.valueOf(fileId))); } } } } if (documentOpenFlag) { document.close(); } else { outputFileName = null; } return outputFileName; }
From source file:com.gp.cong.logisoft.reports.DeliveryOrderPdfCreator.java
public void initialize(String fileName, FclBl bl) throws FileNotFoundException, DocumentException, Exception { document = new Document(PageSize.A4); document.setMargins(4, 4, 4, 4);/*from w w w . java2s . c o m*/ pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); }
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 ww .jav a 2 s . c o 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.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();//from w ww.ja va 2s .c o m 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();/*from w w w .jav a 2s.c o m*/ 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); document.close(); return bookingname; }
From source file:com.incosyz.sms.other.SendOrderMail.java
public void savePdf(GETOrderModel gETOrderModel, String savePath) throws IOException, DocumentException { String html = getHTML(gETOrderModel); File file = new File("./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".html"); // file.createNewFile(); FileWriter fileWriter = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fileWriter); bw.write(html);// w ww. j av a2 s . c o m bw.close(); Document d = new Document(PageSize.A4); String filePath = savePath + ".pdf"; FileOutputStream fileOutputStream = new FileOutputStream(filePath); PdfWriter pdfWriter = PdfWriter.getInstance(d, fileOutputStream); d.addAuthor("Incosyz"); d.addTitle("Sale Detail"); d.addTitle("Sale Detail"); d.open(); FileInputStream fileInputStream = new FileInputStream(file); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, d, fileInputStream); d.close(); fileOutputStream.close(); if (file.isFile()) { file.delete(); } }
From source file:com.incosyz.sms.other.SendOrderMail.java
public void sendOrder(GETOrderModel gETOrderModel, String txt) throws IOException, MessagingException { try {//from w w w.j a va2 s . com String html = getHTML(gETOrderModel); File file = new File( "./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".html"); // file.createNewFile(); FileWriter fileWriter = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fileWriter); bw.write(html); bw.close(); Document d = new Document(PageSize.A4); String filePath = "./src/com/incosyz/sms/temp/" + gETOrderModel.getOrderModel().getOrderId() + ".pdf"; FileOutputStream fileOutputStream = new FileOutputStream(filePath); PdfWriter pdfWriter = PdfWriter.getInstance(d, fileOutputStream); d.addAuthor("Incosyz"); d.addTitle("Sale Detail"); d.addTitle("Sale Detail"); d.open(); FileInputStream fileInputStream = new FileInputStream(file); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, d, fileInputStream); d.close(); fileOutputStream.close(); MailSender mailSender = new MailSender(); MimeBodyPart body = (MimeBodyPart) mailSender.getBody(); body.setText(""); mailSender.setSubject(txt + " Sale Detail Round No : " + gETOrderModel.getOrderModel().getRoundNo() + " | Order Amount : Rs " + CurrancyFormat.getCurrancyFormat(gETOrderModel.getOrderModel().getOrderAmount())); mailSender.setAttachmentPath(filePath); mailSender.sendMail(); if (file.isFile()) { File f = new File(filePath); f.delete(); file.delete(); } } catch (DocumentException ex) { Logger.getLogger(SendOrderMail.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.incosyz.sms.pdfcontroller.ChequePDF.java
public void sendPdf(ArrayList<CheckModel> checkModels, String chequeDescription) throws DocumentException, MessagingException { try {//www . j a v a2s. c o m String html = getHTML(checkModels, chequeDescription); Document document = new Document(PageSize.A4.rotate()); String path = "./src/com/incosyz/sms/temp/tmporders.pdf"; File f = new File(path); FileOutputStream fileOutputStream = new FileOutputStream(f); PdfWriter pdfWriter = PdfWriter.getInstance(document, fileOutputStream); document.open(); StringReader fileReader = new StringReader(html); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, fileReader); document.close(); fileOutputStream.close(); MailSender mailSender = new MailSender(); MimeBodyPart body = (MimeBodyPart) mailSender.getBody(); body.setText(html, "utf-8", "html"); mailSender.setAttachmentPath(path); mailSender.setSubject(chequeDescription); mailSender.sendMail(); } catch (IOException ex) { Logger.getLogger(ChequePDF.class.getName()).log(Level.SEVERE, null, ex); } }