List of usage examples for com.itextpdf.text Document addCreationDate
public boolean addCreationDate()
From source file:com.dexter.fms.mbean.ReportsMBean.java
@SuppressWarnings("unchecked") public void createPDF(int type, String filename, int pageType) { try {// w w w. ja v a 2s.c o m FacesContext context = FacesContext.getCurrentInstance(); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } switch (pageType) { case 1: document.setPageSize(PageSize.A4); break; case 2: document.setPageSize(PageSize.A4.rotate()); break; } document.addAuthor("FMS"); document.addCreationDate(); document.addCreator("FMS"); document.addSubject("Report"); document.addTitle(getReport_title()); PdfPTable headerTable = new PdfPTable(1); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "satraklogo.jpg"; Hashtable<String, Object> params = new Hashtable<String, Object>(); params.put("partner", dashBean.getUser().getPartner()); GeneralDAO gDAO = new GeneralDAO(); Object pSettingsObj = gDAO.search("PartnerSetting", params); PartnerSetting setting = null; if (pSettingsObj != null) { Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj; for (PartnerSetting e : pSettingsList) { setting = e; } } gDAO.destroy(); PdfPCell c = null; if (setting != null && setting.getLogo() != null) { Image logoImg = Image.getInstance(setting.getLogo()); logoImg.scaleToFit(212, 51); c = new PdfPCell(logoImg); } else c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); Paragraph stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { //font exception } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph(getReport_title(), font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); if (getReport_start_dt() != null && getReport_end_dt() != null) { stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(10); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); new Font(helvetica, 12, Font.NORMAL); Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font); c = new PdfPCell(ch); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); } stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); PdfPTable pdfTable = exportPDFTable(type); if (pdfTable != null) document.add(pdfTable); //Keep modifying your pdf file (add pages and more) document.close(); String fileName = filename + ".pdf"; writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf"); context.responseComplete(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.dexter.fuelcard.mbean.UtilMBean.java
public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType, String chargeAmount, String total) { try {//from w w w. ja va 2s .c om Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } switch (pageType) { case 1: document.setPageSize(PageSize.A4); break; case 2: document.setPageSize(PageSize.A4.rotate()); break; } document.addAuthor("FUELCARD"); document.addCreationDate(); document.addCreator("FUELCARD"); document.addSubject("Invoice"); document.addTitle(title); PdfPTable headerTable = new PdfPTable(1); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "satraklogo.jpg"; PdfPCell c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); Paragraph stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { //font exception } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph(title, font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); if (dateperiod != null) { stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(10); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); new Font(helvetica, 12, Font.NORMAL); Paragraph ch = new Paragraph("For " + dateperiod, font); c = new PdfPCell(ch); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); } stars = new Paragraph(20); stars.add(Chunk.NEWLINE); stars.setSpacingAfter(20); c = new PdfPCell(stars); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); PdfPTable pdfTable = new PdfPTable(4); try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) { pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting } else { pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting } //pdfTable.addCell(new Paragraph("Description", font)); // the pdfTable.addCell(new Paragraph("Amount Due", font)); font = new Font(helvetica, 8, Font.NORMAL); pdfTable.addCell(new Paragraph(chargeType, font)); pdfTable.addCell(new Paragraph(chargeAmount, font)); pdfTable.addCell(new Paragraph(total, font)); pdfTable.addCell(new Paragraph(amount, font)); pdfTable.setWidthPercentage(100); if (pdfTable != null) document.add(pdfTable); //Keep modifying your pdf file (add pages and more) document.close(); return baos.toByteArray(); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public void createPDF(Context context) throws DocumentException, IOException { LicenseKey.loadLicenseFile(context.getAssets().open("itextkey.xml")); this.mContext = context; Map<String, String> pdfParams = new HashMap(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_Hmmss", Locale.US); dateFormat.setTimeZone(TimeZone.getDefault()); this.filename = "txtbook_" + dateFormat.format(new Date()) + ".pdf"; float leftMargin = Txtbook.RIGHT_MARGIN_EVEN; float rightMargin = Txtbook.RIGHT_MARGIN_ODD; if (this.settings.addFrontCover.booleanValue()) { leftMargin = Txtbook.RIGHT_MARGIN_ODD; rightMargin = Txtbook.RIGHT_MARGIN_EVEN; }/*from w w w . ja v a2 s .com*/ Document document = new Document(PageSize.LETTER, leftMargin, rightMargin, Txtbook.TOP_MARGIN, Txtbook.TOP_MARGIN); File file = new File(Environment.getExternalStorageDirectory(), this.filename); if (!(file.exists() && file.canRead())) { file.createNewFile(); } this.writer = PdfWriter.getInstance(document, new FileOutputStream(file)); this.writer.setCompressionLevel(this.settings.compressionLevel); this.writer.setStrictImageSequence(true); FontFactory.register("assets/fonts/DroidSans.ttf"); this.sansFont6Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 6.0f, 0, new BaseColor(152, 152, 152)); this.sansFont9 = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f); this.sansFont9Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f, 0, new BaseColor(103, 103, 103)); this.sansFont11Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 11.0f, 0, new BaseColor(152, 152, 152)); FontFactory.register("assets/fonts/CourierNew.ttf"); this.serifFont8Gray = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 8.0f, 0, new BaseColor(103, 103, 103)); this.serifFont11 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 11.0f); this.serifFont14 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 14.0f); this.serifFont24 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 24.0f); document.open(); document.setMarginMirroring(true); document.addCreationDate(); document.addCreator("Created with txt-book for Android www.txt-book.com"); document.addTitle("txt-book for Android"); if (this.settings.bookStyle == 1) { ConversationHeaderFooter hf = new ConversationHeaderFooter(); hf.footerFont = this.sansFont9; hf.hasFrontCover = this.settings.addFrontCover; this.writer.setPageEvent(hf); } else { StorybookHeaderFooter hf2 = new StorybookHeaderFooter(); hf2.title = this.settings.bookCoverTitle; hf2.headerFont = this.serifFont8Gray; hf2.hasFrontCover = this.settings.addFrontCover; this.writer.setPageEvent(hf2); } if (this.settings.addFrontCover.booleanValue()) { createFrontCoverPage(document, this.settings.bookCoverTitle, this.settings.addFrontCoverImage.booleanValue() ? this.settings.coverPhoto : null); pdfParams.put("PDF Front Cover", "YES"); } else { pdfParams.put("PDF Front Cover", "NO"); } if (this.settings.addFrontCoverImage.booleanValue()) { pdfParams.put("PDF Front Cover Image", "YES"); } else { pdfParams.put("PDF Front Cover Image", "NO"); } if (this.settings.bookStyle == 1) { createContentPagesConversation(document); } else { createContentPagesStorybook(document, this.settings.bookCoverTitle); } int pages = this.writer.getPageNumber(); if (this.settings.bookStyle == 2) { ((StorybookHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true); } else { ((ConversationHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true); } if (this.settings.addBackCover.booleanValue()) { pages++; pdfParams.put("PDF Back Cover", "YES"); if (pages % 2 == 1) { createBlankSpacerPage(document); } createBackCoverPage(document, this.settings.backCoverNote); } else { pdfParams.put("PDF Back Cover", "NO"); if (pages % 2 == 1) { createBlankSpacerPage(document); } } if (this.settings.bookStyle == 2) { pdfParams.put("PDF Style", "Storybook"); } else { pdfParams.put("PDF Style", "Conversation"); } pdfParams.put("PDF Num Pages", Integer.valueOf(this.writer.getPageNumber()).toString()); document.close(); FlurryAgent.logEvent("PDF_CREATED", (Map) pdfParams); }
From source file:com.iox.rms.mbean.UserBean.java
@SuppressWarnings("deprecation") private byte[] generateInvoiceForCustomerPurchase(CustomerProduct cp) { byte[] data = null; if (cp != null) { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from w ww. j a v a2s.c o m*/ PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new HeaderFooter()); writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788)); if (!document.isOpen()) { document.open(); } document.setPageSize(PageSize.A4); document.addAuthor("AutoLife"); document.addCreationDate(); document.addCreator("AutoLife"); document.addSubject("Invoice"); document.addTitle("Purchase Invoice"); PdfPTable headerTable = new PdfPTable(3); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance() .getExternalContext().getContext(); String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "sattrak-logo.png"; PdfPCell c = new PdfPCell(Image.getInstance(logo)); c.setBorder(0); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); headerTable.addCell(c); BaseFont helvetica = null; try { helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); } catch (Exception e) { } Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph("INVOICE", font)); c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); c.setBorder(0); headerTable.addCell(c); font = new Font(helvetica, 10, Font.NORMAL | Font.BOLD); c = new PdfPCell(new Paragraph("TRANSACTION REF. NO.: " + cp.getPurchaseTranRef(), font)); c.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); c.setBorder(0); headerTable.addCell(c); document.add(headerTable); font = new Font(helvetica, 12, Font.NORMAL | Font.BOLD); Paragraph p = new Paragraph("DETAILS", font); p.setAlignment(Paragraph.ALIGN_CENTER); document.add(p); PdfPTable pdfTable = new PdfPTable(3); font = new Font(helvetica, 8, Font.BOLDITALIC); pdfTable.addCell(new Paragraph("INITIATED DATE", font)); pdfTable.addCell(new Paragraph("PRODUCT", font)); pdfTable.addCell(new Paragraph("AMOUNT", font)); font = new Font(helvetica, 8, Font.NORMAL); pdfTable.addCell( new Paragraph(cp.getPurchaseTransaction().getTranInitDate().toLocaleString(), font)); pdfTable.addCell(new Paragraph(cp.getProductBooked().getDetails(), font)); pdfTable.addCell(new Paragraph("" + cp.getPurchasedAmount(), font)); document.add(pdfTable); document.close(); data = baos.toByteArray(); } catch (Exception ex) { ex.printStackTrace(); } } return data; }
From source file:com.khepry.frackhem.fxml.FracKhemGUIController.java
License:Apache License
private void saveTextAsPDF(String content, File file) throws FileNotFoundException, DocumentException, IOException, InterruptedException { Document document = new Document(PageSize.A4.rotate()); PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open();/*w w w . j av a2 s .com*/ document.addAuthor("Author of the Doc"); document.addCreator("Creator of the Doc"); document.addSubject("Subject of the Doc"); document.addCreationDate(); document.addTitle(file.getName()); String html = htmlHeader.concat(markdown4jProcessor.process(content.trim())); // XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new ByteArrayInputStream(html.getBytes("UTF-8")), this.getClass().getResourceAsStream(cssFileFullPath)); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new ByteArrayInputStream(html.getBytes("UTF-8"))); document.close(); pdfWriter.close(); displayFile(file.getAbsolutePath(), sleepMillis); }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public void generatePdf(Author author, String filename, String type) { // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch) // marginLeft, marginRight, marginTop, marginBottom Document document = new Document(PageSize.A4, 50, 50, 80, 50); try {/*from w ww . ja v a 2 s . co m*/ if (m_shopping_basket.size() > 0) { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); writer.setBoxSize("art", new Rectangle(50, 50, 560, 790)); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); PdfContentByte cb = writer.getDirectContent(); document.addAuthor("ywesee GmbH"); document.addCreator("AmiKo for Windows"); document.addCreationDate(); // Logo String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png"); File logoFile = new File(logoImageStr); if (!logoFile.exists()) logoImageStr = Constants.IMG_FOLDER + "empty_logo.png"; Image logo = Image.getInstance(logoImageStr); logo.scalePercent(30); logo.setAlignment(Rectangle.ALIGN_RIGHT); document.add(logo); document.add(Chunk.NEWLINE); // Bestelladresse // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); String bestellAdrStr = getAddressAsString(BestellAdresseID); Paragraph p = new Paragraph(12); // p.setIndentationLeft(60); p.add(new Chunk(bestellAdrStr, font_norm_10)); document.add(p); document.add(Chunk.NEWLINE); // Title p = new Paragraph(m_rb.getString("order"), font_bold_16); document.add(p); // Date DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); Date date = new Date(); p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10); p.setSpacingAfter(20); document.add(p); // document.add(Chunk.NEWLINE); // Add addresses (Lieferadresse + Rechnungsadresse) /* --> OLD String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2")); String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3")); */ // --> NEW String lieferAdrStr = getAddressAsString(LieferAdresseID); String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID); PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 }); addressTable.setWidthPercentage(100f); addressTable.getDefaultCell().setPadding(5); addressTable.setSpacingAfter(5f); addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); document.add(addressTable); document.add(Chunk.NEWLINE); // Add shopping basket if (type.equals("specific")) document.add(getShoppingBasketForAuthor(author, cb)); else if (type.equals("all")) document.add(getFullShoppingBasket(cb, "all")); else if (type.equals("rest")) document.add(getFullShoppingBasket(cb, "rest")); LineSeparator separator = new LineSeparator(); document.add(separator); } } catch (IOException e) { } catch (DocumentException e) { } document.close(); // System.out.println("Saved PDF to " + filename); }
From source file:com.mycompany.mavenproject1.Createpdf.java
public void createPDF(String pdfFilename) { Document doc = new Document(); PdfWriter docWriter = null;// w w w . ja va 2s . com initializeFonts(); try { String path = "C:\\Users\\Thaskioglu\\Downloads\\" + pdfFilename; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); doc.addAuthor("FabulousCar"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("FabulousCar"); doc.addTitle("Invoice"); doc.setPageSize(PageSize.LETTER); doc.open(); PdfContentByte cb = docWriter.getDirectContent(); boolean beginPage = true; int y = 0; for (int i = 0; i < 100; i++) { if (beginPage) { beginPage = false; generateLayout(doc, cb); generateHeader(doc, cb); y = 615; } generateDetail(doc, cb, i, y); y = y - 15; if (y < 50) { printPageNumber(cb); doc.newPage(); beginPage = true; } } printPageNumber(cb); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } finally { if (doc != null) { doc.close(); } if (docWriter != null) { docWriter.close(); } } }
From source file:com.propelics.pdfcreator.PdfcreatorModule.java
License:Open Source License
/** * @method generatePDFWithHTML/*from w w w. ja v a 2 s . co m*/ * Generates a PDF with the given file name, based on a HTML file * @param {String} filename Name of the PDF file * @param {String} html String with the HTML * @param {String} [author] Author for metadata * Fires a "complete" event when the PDF is generated * Fires a "error" event when a error is presented */ @Kroll.method(runOnUiThread = true) public void generatePDFWithHTML(final HashMap args) { Log.d(PROXY_NAME, "generatePDFWithHTML()"); String html = ""; String author = ""; String filename = ""; final float marginPt = 28.35f;//1cm == 28.35pt try { if (args.containsKey("filename")) { filename = (String) args.get("filename"); Log.d(PROXY_NAME, "filename: " + filename); } else return; if (args.containsKey("html")) { html = (String) args.get("html"); Log.d(PROXY_NAME, "html: " + html); } else return; if (args.containsKey("author")) { author = (String) args.get("author"); Log.d(PROXY_NAME, "author: " + author); } //create a new document Document document = new Document(PageSize.LETTER, marginPt, marginPt, marginPt, 0); TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true); // Parse to XHTML StringWriter xhtmlWriter = new StringWriter(); Tidy tidy = new Tidy(); // tidy.setXHTML(true); tidy.setXmlOut(true); tidy.parse(new StringReader(html), xhtmlWriter); String xhtml = xhtmlWriter.toString(); //get Instance of the PDFWriter PdfWriter pdfWriter = PdfWriter.getInstance(document, file.getOutputStream()); //document header attributes document.addAuthor(author); document.addCreationDate(); document.setPageSize(PageSize.LETTER); //open document document.open(); // From Stack Overflow lol MyFontFactory fontFactory = new MyFontFactory(); FontFactory.setFontImp(fontFactory); // HtmlPipelineContext htmlContext = new HtmlPipelineContext(new CssAppliersImpl(fontFactory)); HtmlPipelineContext htmlContext = new HtmlPipelineContext(null); htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory()); CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true); Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, pdfWriter))); XMLWorker worker = new XMLWorker(pipeline, true); XMLParser p = new XMLParser(worker); p.parse(new StringReader(xhtml)); // Finish SO c&P // Older code /* // Font Provider creation MyFontFactory fontProvider = new MyFontFactory(); // fontProvider.register("/DroidSans.ttf"); //get the XMLWorkerHelper Instance XMLWorkerHelper worker = XMLWorkerHelper.getInstance(); //convert to PDF worker.parseXHtml(pdfWriter, document, new ByteArrayInputStream(xhtml.getBytes("UTF-8")), null, fontProvider); //Load xhtml */ //close the document document.close(); //close the writer pdfWriter.close(); sendCompleteEvent(filename); } catch (Exception e) { sendErrorEvent(e); } }
From source file:com.softwaremagico.tm.pdf.complete.PdfDocument.java
License:Open Source License
protected Document addMetaData(Document document) { document.addTitle("Fading Suns Character Sheet"); document.addAuthor("Software Magico"); document.addCreator("Think Machine"); document.addSubject("RPG"); document.addKeywords("RPG, Fading Suns, FS, " + language); document.addCreationDate(); return document; }
From source file:com.solidmaps.webapp.report.EnableCompanyRequerimentFederalPDF.java
private String createDocument(Document doc, PdfWriter docWriter, LicensePFEntity license) throws FileNotFoundException, DocumentException { String fileName = "Requerimento de Habilitao de PJ - Cnpj: " + license.getCompany().getCnpj() + ".pdf"; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(filePath + fileName)); // document header attributes doc.addAuthor("EnforceMaps"); doc.addCreationDate(); doc.addProducer();/* w w w . java 2 s .c o m*/ doc.addCreator("EnforceMaps"); doc.addTitle("Requerimento de Habilitao de PJ"); doc.setPageSize(PageSize.A4); // open document doc.open(); return fileName; }