List of usage examples for com.lowagie.text Paragraph setAlignment
public void setAlignment(String alignment)
From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private void writeFrontpage(String name, Document document, List<PdfSolution> solutions) throws DocumentException { document.open();// ww w.jav a2 s. c om Paragraph p = new Paragraph(name); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(20f); p.setSpacingAfter(20f); document.add(p); PdfPTable table = new PdfPTable(17); table.setWidthPercentage(100); int[] width = { 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; table.setWidths(width); PdfPCell cell; table.addCell(buildHeaderCell("Name", 90, true, false)); table.addCell(buildHeaderCell("Schwierigkeitsgrad", 90, false, false)); table.addCell(buildHeaderCell("Besetzte Zellen", 90, false, false)); table.addCell(buildHeaderCell("Simple", 90, false, false)); table.addCell(buildHeaderCell("Hidden Single", 90, false, false)); table.addCell(buildHeaderCell("Naked Pair", 90, false, false)); table.addCell(buildHeaderCell("Naked Triple", 90, false, false)); table.addCell(buildHeaderCell("Naked Quad", 90, false, false)); table.addCell(buildHeaderCell("Hidden Pair", 90, false, false)); table.addCell(buildHeaderCell("Hidden Triple", 90, false, false)); table.addCell(buildHeaderCell("Hidden Quad", 90, false, false)); table.addCell(buildHeaderCell("Intersection Removal", 90, false, false)); table.addCell(buildHeaderCell("Y-Wing", 90, false, false)); table.addCell(buildHeaderCell("X-Wing", 90, false, false)); table.addCell(buildHeaderCell("Jellyfish", 90, false, false)); table.addCell(buildHeaderCell("Swordfish", 90, false, false)); table.addCell(buildHeaderCell("Backtracking", 90, false, true)); boolean even = false; for (PdfSolution solution : solutions) { table.addCell(buildBodyNumberCell(solution.getId(), even, true, false)); table.addCell(buildBodyTextCell(solution.getLevel().toString(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getFixed(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategySimple(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenSingle(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyNakedPair(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyNakedTriple(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyNakedQuad(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenPair(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenTriple(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyHiddenQuad(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyIntersectionRemoval(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyYwing(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyXwing(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyJellyfish(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategySwordfish(), even, false, false)); table.addCell(buildBodyNumberCell(solution.getStrategyBacktracking(), even, false, true)); even = (even ? false : true); } document.add(table); document.close(); }
From source file:de.xirp.report.ReportGenerator.java
License:Open Source License
/** * Returns a default formatted/*from w w w . j av a 2s .co m*/ * {@link com.lowagie.text.Paragraph paragraph}. * * @param text * The text for the paragraph. * @param font * The font to use. * @param align * The text alignment. * @return The default formatted paragraph. * @see com.lowagie.text.Paragraph */ private static Paragraph getParagraph(String text, Font font, int align) { Paragraph para = new Paragraph(text, font); para.setFirstLineIndent(0); para.setAlignment(align); return para; }
From source file:desktopbugtracker.export.Pdf.java
License:Open Source License
public void addParagraph(String s, Font f, PdfAlign align) { Paragraph paragraph = new Paragraph(s, f); paragraph.setAlignment(align.toITextElement()); addParagraph(paragraph);/*from w w w. java 2 s .co m*/ }
From source file:dinamica.AbstractPDFOutput.java
License:LGPL
/** * Receives a byte buffer that should be filled with resulting PDF. * @param data Data module that provides recordsets to this output module * @param buf Buffer to print PDF, then used to send to browser * @throws Throwable/*from w w w. j av a 2 s.c om*/ */ protected void createPDF(GenericTransaction data, ByteArrayOutputStream buf) throws Throwable { //pdf objects Document doc = new Document(); PdfWriter docWriter = PdfWriter.getInstance(doc, buf); //header HeaderFooter header = new HeaderFooter(new Phrase(getHeader()), false); header.setBorder(Rectangle.BOTTOM); header.setAlignment(Rectangle.ALIGN_CENTER); doc.setHeader(header); //footer HeaderFooter footer = new HeaderFooter(new Phrase(getFooter()), true); footer.setBorder(Rectangle.TOP); footer.setAlignment(Rectangle.ALIGN_RIGHT); doc.setFooter(footer); //pagesize doc.setPageSize(PageSize.LETTER); doc.open(); //title Paragraph t = new Paragraph(getReportTitle(), new Font(Font.HELVETICA, 18f)); t.setAlignment(Rectangle.ALIGN_CENTER); doc.add(t); //paragraph Paragraph p = new Paragraph("Hello World"); p.setAlignment(Rectangle.ALIGN_CENTER); doc.add(p); doc.close(); docWriter.close(); }
From source file:domain.reports.menu.PDFReportMenu.java
License:LGPL
@Override protected void createPDF(GenericTransaction data, ByteArrayOutputStream buf) throws Throwable { //inicializar documento: tamano de pagina, orientacion, margenes Document doc = new Document(); PdfWriter docWriter = PdfWriter.getInstance(doc, buf); doc.setPageSize(PageSize.LETTER.rotate()); doc.setMargins(30, 30, 30, 40);//ww w . j a va2 s . c om doc.open(); //crear fonts por defecto tblHeaderFont = new Font(Font.HELVETICA, 10f, Font.BOLD); tblBodyFont = new Font(Font.HELVETICA, 10f, Font.NORMAL); //definir pie de pagina del lado izquierdo String footerText = this.getFooter(); //read it from config.xml or web.xml String reportDate = StringUtil.formatDate(new java.util.Date(), "dd-MM-yyyy HH:mm"); //crear template (objeto interno de IText) y manejador de evento //para imprimir el pie de pagina bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb = docWriter.getDirectContent(); tpl = cb.createTemplate(20, 14); docWriter.setPageEvent(new PDFPageEvents(footerText, pageXofY, tpl, bf, cb, reportDate)); //titulo - lo lee de config.xml por defecto reportTitle = getReportTitle(); Paragraph t = new Paragraph(reportTitle, new Font(Font.HELVETICA, 14f, Font.BOLD)); t.setAlignment(Rectangle.ALIGN_RIGHT); doc.add(t); //logo img = Image.getInstance(getImage(this.getServerBaseURL() + logoPath, false)); img.scalePercent(100); float imgY = doc.top() - img.getHeight(); float imgX = doc.left(); img.setAbsolutePosition(imgX, imgY); doc.add(img); //blank line doc.add(new Paragraph(" ")); //blank line doc.add(new Paragraph(" ")); //blank line doc.add(new Paragraph(" ")); //for each master record print a master/detail section MasterDetailReader dataobj = (MasterDetailReader) data; Recordset master = dataobj.getRecordset("master"); master.top(); while (master.next()) { //blank line doc.add(new Paragraph(" ")); //print master section doc.add(getGroupMaster(master)); //print detail section doc.add(getGroupDetail(master, dataobj.getDetail(master))); } //print grand total doc.add(new Paragraph(" ")); doc.close(); docWriter.close(); }
From source file:domain.reports.menu.PDFReportMenu.java
License:LGPL
/** * Return group header (master)//from ww w.jav a2 s .co m * @param master Recordset containing master records * @return * @throws Throwable */ Paragraph getGroupMaster(Recordset master) throws Throwable { String text = "Aplicacin: " + master.getString("aplication") + "\n"; text = text + "Men: " + master.getString("title"); Paragraph t = new Paragraph(text, new Font(Font.HELVETICA, 12f, Font.BOLD)); t.setAlignment(Rectangle.ALIGN_LEFT); return t; }
From source file:domain.reports.role.PDFReportRole.java
License:LGPL
/** * Return group header (master)//from ww w. java 2s . c o m * @param master Recordset containing master records * @return * @throws Throwable */ Paragraph getGroupMaster(Recordset master) throws Throwable { String text = "Aplicacin: " + master.getString("aplication") + "\n"; text = text + "Rol: " + master.getString("rolename") + "\n" + "Descripcin: " + master.getString("description"); Paragraph t = new Paragraph(text, new Font(Font.HELVETICA, 12f, Font.BOLD)); t.setAlignment(Rectangle.ALIGN_LEFT); return t; }
From source file:EplanPrinter.RTFWrite.java
License:Open Source License
public String openDoc(String name, String title) throws FileNotFoundException, DocumentException { document = new Document(); RtfWriter2.getInstance(document, new FileOutputStream(name + ".rtf")); document.open();// w w w. j ava 2 s .c om Paragraph p = new Paragraph("Permit " + title); p.setAlignment(Element.ALIGN_CENTER); document.add(p); return ""; }
From source file:eu.europa.ec.markt.dss.report.Tsl2PdfExporter.java
License:Open Source License
/** * Produce a human readable export of the given tsl to the given file. * //from w ww. j a v a 2 s.c o m * @param tsl * the TrustServiceList to export * @param pdfFile * the file to generate * @return * @throws IOException */ public void humanReadableExport(final TrustServiceList tsl, final File pdfFile) { Document document = new Document(); OutputStream outputStream; try { outputStream = new FileOutputStream(pdfFile); } catch (FileNotFoundException e) { throw new RuntimeException("file not found: " + pdfFile.getAbsolutePath(), e); } try { final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setPDFXConformance(PdfWriter.PDFA1B); // title final EUCountry country = EUCountry.valueOf(tsl.getSchemeTerritory()); final String title = country.getShortSrcLangName() + " (" + country.getShortEnglishName() + "): Trusted List"; Phrase footerPhrase = new Phrase("PDF document generated on " + new Date().toString() + ", page ", headerFooterFont); HeaderFooter footer = new HeaderFooter(footerPhrase, true); document.setFooter(footer); Phrase headerPhrase = new Phrase(title, headerFooterFont); HeaderFooter header = new HeaderFooter(headerPhrase, false); document.setHeader(header); document.open(); addTitle(title, title0Font, Paragraph.ALIGN_CENTER, 0, 20, document); addLongItem("Scheme name", tsl.getSchemeName(), document); addLongItem("Legal Notice", tsl.getLegalNotice(), document); // information table PdfPTable informationTable = createInfoTable(); addItemRow("Scheme territory", tsl.getSchemeTerritory(), informationTable); addItemRow("Scheme status determination approach", substringAfter(tsl.getStatusDeterminationApproach(), "StatusDetn/"), informationTable); final List<String> schemeTypes = new ArrayList<String>(); for (final String schemeType : tsl.getSchemeTypes()) { schemeTypes.add(schemeType); } addItemRow("Scheme type community rules", schemeTypes, informationTable); addItemRow("Issue date", tsl.getListIssueDateTime().toString(), informationTable); addItemRow("Next update", tsl.getNextUpdate().toString(), informationTable); addItemRow("Historical information period", tsl.getHistoricalInformationPeriod().toString() + " days", informationTable); addItemRow("Sequence number", tsl.getSequenceNumber().toString(), informationTable); addItemRow("Scheme information URIs", tsl.getSchemeInformationUris(), informationTable); document.add(informationTable); addTitle("Scheme Operator", title1Font, Paragraph.ALIGN_CENTER, 0, 10, document); informationTable = createInfoTable(); addItemRow("Scheme operator name", tsl.getSchemeOperatorName(), informationTable); PostalAddressType schemeOperatorPostalAddress = tsl.getSchemeOperatorPostalAddress(Locale.ENGLISH); addItemRow("Scheme operator street address", schemeOperatorPostalAddress.getStreetAddress(), informationTable); addItemRow("Scheme operator postal code", schemeOperatorPostalAddress.getPostalCode(), informationTable); addItemRow("Scheme operator locality", schemeOperatorPostalAddress.getLocality(), informationTable); addItemRow("Scheme operator state", schemeOperatorPostalAddress.getStateOrProvince(), informationTable); addItemRow("Scheme operator country", schemeOperatorPostalAddress.getCountryName(), informationTable); List<String> schemeOperatorElectronicAddressess = tsl.getSchemeOperatorElectronicAddresses(); addItemRow("Scheme operator contact", schemeOperatorElectronicAddressess, informationTable); document.add(informationTable); addTitle("Trust Service Providers", title1Font, Paragraph.ALIGN_CENTER, 10, 2, document); List<TrustServiceProvider> trustServiceProviders = tsl.getTrustServiceProviders(); for (TrustServiceProvider trustServiceProvider : trustServiceProviders) { addTitle(trustServiceProvider.getName(), title1Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable providerTable = createInfoTable(); addItemRow("Service provider trade name", trustServiceProvider.getTradeName(), providerTable); addItemRow("Information URI", trustServiceProvider.getInformationUris(), providerTable); PostalAddressType postalAddress = trustServiceProvider.getPostalAddress(); addItemRow("Service provider street address", postalAddress.getStreetAddress(), providerTable); addItemRow("Service provider postal code", postalAddress.getPostalCode(), providerTable); addItemRow("Service provider locality", postalAddress.getLocality(), providerTable); addItemRow("Service provider state", postalAddress.getStateOrProvince(), providerTable); addItemRow("Service provider country", postalAddress.getCountryName(), providerTable); document.add(providerTable); List<TrustService> trustServices = trustServiceProvider.getTrustServices(); for (TrustService trustService : trustServices) { addTitle(trustService.getName(), title2Font, Paragraph.ALIGN_LEFT, 10, 2, document); PdfPTable serviceTable = createInfoTable(); addItemRow("Type", substringAfter(trustService.getType(), "Svctype/"), serviceTable); addItemRow("Status", substringAfter(trustService.getStatus(), "Svcstatus/"), serviceTable); addItemRow("Status starting time", trustService.getStatusStartingTime().toString(), serviceTable); document.add(serviceTable); addTitle("Service digital identity (X509)", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document); final X509Certificate certificate = trustService.getServiceDigitalIdentity(); final PdfPTable serviceIdentityTable = createInfoTable(); addItemRow("Version", Integer.toString(certificate.getVersion()), serviceIdentityTable); addItemRow("Serial number", certificate.getSerialNumber().toString(), serviceIdentityTable); addItemRow("Signature algorithm", certificate.getSigAlgName(), serviceIdentityTable); addItemRow("Issuer", certificate.getIssuerX500Principal().toString(), serviceIdentityTable); addItemRow("Valid from", certificate.getNotBefore().toString(), serviceIdentityTable); addItemRow("Valid to", certificate.getNotAfter().toString(), serviceIdentityTable); addItemRow("Subject", certificate.getSubjectX500Principal().toString(), serviceIdentityTable); addItemRow("Public key", certificate.getPublicKey().toString(), serviceIdentityTable); // TODO certificate policies addItemRow("Subject key identifier", toHex(getSKId(certificate)), serviceIdentityTable); addItemRow("CRL distribution points", getCrlDistributionPoints(certificate), serviceIdentityTable); addItemRow("Authority key identifier", toHex(getAKId(certificate)), serviceIdentityTable); addItemRow("Key usage", getKeyUsage(certificate), serviceIdentityTable); addItemRow("Basic constraints", getBasicConstraints(certificate), serviceIdentityTable); byte[] encodedCertificate; try { encodedCertificate = certificate.getEncoded(); } catch (CertificateEncodingException e) { throw new RuntimeException("cert: " + e.getMessage(), e); } addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedCertificate), serviceIdentityTable); addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedCertificate), serviceIdentityTable); document.add(serviceIdentityTable); List<ExtensionType> extensions = trustService.getExtensions(); for (ExtensionType extension : extensions) { printExtension(extension, document); } addLongMonoItem("The decoded certificate:", certificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(certificate), document); } } X509Certificate signerCertificate = tsl.verifySignature(); if (null != signerCertificate) { Paragraph tslSignerTitle = new Paragraph("Trusted List Signer", title1Font); tslSignerTitle.setAlignment(Paragraph.ALIGN_CENTER); document.add(tslSignerTitle); final PdfPTable signerTable = createInfoTable(); addItemRow("Subject", signerCertificate.getSubjectX500Principal().toString(), signerTable); addItemRow("Issuer", signerCertificate.getIssuerX500Principal().toString(), signerTable); addItemRow("Not before", signerCertificate.getNotBefore().toString(), signerTable); addItemRow("Not after", signerCertificate.getNotAfter().toString(), signerTable); addItemRow("Serial number", signerCertificate.getSerialNumber().toString(), signerTable); addItemRow("Version", Integer.toString(signerCertificate.getVersion()), signerTable); byte[] encodedPublicKey = signerCertificate.getPublicKey().getEncoded(); addItemRow("Public key SHA1 Thumbprint", DigestUtils.shaHex(encodedPublicKey), signerTable); addItemRow("Public key SHA256 Thumbprint", DigestUtils.sha256Hex(encodedPublicKey), signerTable); document.add(signerTable); addLongMonoItem("The decoded certificate:", signerCertificate.toString(), document); addLongMonoItem("The certificate in PEM format:", toPem(signerCertificate), document); addLongMonoItem("The public key in PEM format:", toPem(signerCertificate.getPublicKey()), document); } document.close(); } catch (DocumentException e) { throw new RuntimeException("PDF document error: " + e.getMessage(), e); } catch (Exception e) { throw new RuntimeException("Exception: " + e.getMessage(), e); } }
From source file:fr.aliasource.webmail.server.export.ConversationExporter.java
License:GNU General Public License
@SuppressWarnings("unchecked") private void exportMessage(Set<ClientMessage> cm, Document d, boolean isForward) throws DocumentException { LineSeparator hr = new LineSeparator(); StyleSheet styles = new StyleSheet(); Font fnormal = new Font(Font.HELVETICA, 9, Font.NORMAL); Font fbold = new Font(Font.HELVETICA, 9, Font.BOLD); Iterator<ClientMessage> it = cm.iterator(); Cell c = null;//from w ww . j ava 2 s . c o m while (it.hasNext()) { ClientMessage fwdCm = it.next(); if (isForward) { c = new Cell(); } // Subject (only if isForward) if (isForward) { String subjectText = fwdCm.getSubject(); String dateText = formatDate(fwdCm.getDate()); Chunk subject = new Chunk(subjectText, fbold); Chunk date = new Chunk(dateText, fbold); Paragraph subjectPar = new Paragraph(subject + ", " + date); subjectPar.setIndentationLeft(5.0f); c.add(subjectPar); c.add(Chunk.NEWLINE); } else { String dateText = formatDate(fwdCm.getDate()); Chunk date = new Chunk(dateText, fbold); Paragraph datePar = new Paragraph(date); datePar.setAlignment(Element.ALIGN_RIGHT); d.add(datePar); } // Sender String senderText = formatAddress(fwdCm.getSender()); Chunk sender = new Chunk(senderText, fbold); sender.setTextRise(10.0f); Paragraph senderPar = new Paragraph(sender); if (isForward) { senderPar.setIndentationLeft(5.0f); c.add(senderPar); } else { d.add(senderPar); } appendRecipients(d, c, isForward, "To:", fwdCm.getTo()); appendRecipients(d, c, isForward, "Cc:", fwdCm.getCc()); appendRecipients(d, c, isForward, "Bcc:", fwdCm.getBcc()); if (isForward) { c.add(Chunk.NEWLINE); } // Body String bodyText = fwdCm.getBody().getCleanHtml(); Paragraph bodyPar = new Paragraph(); bodyPar.setFont(fnormal); if (bodyText != null && !bodyText.isEmpty()) { try { List<Element> objects = HTMLWorker.parseToList(new StringReader(bodyText), styles); for (Iterator<Element> iterator = objects.iterator(); iterator.hasNext();) { Element el = iterator.next(); if (!(el instanceof Image)) { // bodyPar.add(el); if (isForward) { c.add(el); } else { bodyPar.add(el); } } } } catch (Exception e) { logger.warn("Cannot generate pdf from html body use plain text instead", e); // bodyPar.add(fwdCm.getBody().getPlain()); if (isForward) { Chunk t = new Chunk(fwdCm.getBody().getPlain()); t.setFont(fnormal); c.add(t); } else { bodyPar.add(fwdCm.getBody().getPlain()); } } } else { if (isForward) { Chunk t = new Chunk(fwdCm.getBody().getPlain()); t.setFont(fnormal); c.add(t); } else { bodyPar.add(fwdCm.getBody().getPlain()); } } if (isForward) { // c.add(bodyPar); Table t = new Table(1); t.setPadding(5); t.setBackgroundColor(new Color(242, 242, 242)); t.addCell(c); d.add(t); } else { bodyPar.setIndentationLeft(15.0f); d.add(bodyPar); } if (fwdCm.getFwdMessages() != null) { this.exportMessage(fwdCm.getFwdMessages(), d, true); } d.add(hr); } }