List of usage examples for com.lowagie.text.pdf BaseFont createFont
public static BaseFont createFont(String name, String encoding, boolean embedded) throws DocumentException, IOException
From source file:io.vertigo.quarto.plugins.export.pdf.PDFAdvancedPageNumberEvents.java
License:Apache License
/** {@inheritDoc} */ @Override/*from w ww .jav a 2 s .co m*/ public void onOpenDocument(final PdfWriter writer, final Document document) { try { bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb = writer.getDirectContent(); template = cb.createTemplate(50, 50); } catch (final DocumentException | IOException e) { throw WrappedException.wrap(e); } }
From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java
License:Open Source License
private PdfTemplate createPasswordLetterTemplate(PdfWriter writer) throws Exception { IWBundle iwb = getIWApplicationContext().getIWMainApplication() .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER); PdfContentByte cb = writer.getDirectContent(); float tempLength = 511f; float tempHeight = getPointsFromMM(40); PdfTemplate template = cb.createTemplate(tempLength, tempHeight); if (addTemplateHeader()) { BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); String mail_zip = iwb.getProperty("commune.mail_zip"); String mail_name = iwb.getProperty("commune.mail_name"); float convLengt = 100f; float convHeight = 60f; template.rectangle(0f, 0f, convLengt, convHeight); template.moveTo(0f, 0f);//from ww w .j a v a 2 s. co m template.lineTo(convLengt, convHeight); template.moveTo(convLengt, 0f); template.lineTo(0f, convHeight); template.stroke(); template.beginText(); template.setFontAndSize(bf, 11f); template.setTextMatrix(5f, 40f); template.showText(mail_name); template.endText(); template.beginText(); template.setFontAndSize(bf, 11f); template.setTextMatrix(5f, 25f); template.showText(mail_zip); template.endText(); Image porto = Image.getInstance(iwb.getResourcesRealPath() + "/shared/porto_betalt.jpg"); porto.scaleAbsolute(60f, 60f); // Image portoA =Image.getInstance(iwb.getResourcesRealPath()+ // "/shared/porto_a_logo.jpg"); // float Awidth = 2.3f*60f; // portoA.scaleToFit(Awidth,60f); float portoXPos = tempLength - 90f; // float portoAXPos = portoXPos-Awidth-5f; template.addImage(porto, 60f, 0f, 0f, 60f, portoXPos, 0); // template.addImage(portoA,Awidth,0f,0f,60f,portoAXPos,0); } return template; }
From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java
License:Open Source License
public void createHeaderDate(Document document, PdfWriter writer, String dateString) throws DocumentException { /*// ww w . ja v a 2 s . c o m * final PdfPTable header = new PdfPTable(new float[]{1}); header.setWidthPercentage(100f); final PdfPCell defaultCell = header.getDefaultCell(); * defaultCell.setBorder(0); //defaultCell.setFixedHeight(getPointsFromMM(40)); defaultCell.setPadding(0); defaultCell.setNoWrap(true); * defaultCell.setVerticalAlignment(align); header.addCell(new Phrase(new Chunk(dateString, getDefaultParagraphFont()))); document.add(header); */ PdfContentByte cb = writer.getDirectContent(); cb.beginText(); Font font = getDefaultParagraphFont(); try { BaseFont bf = BaseFont.createFont(font.getFamilyname(), BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.setFontAndSize(bf, font.size()); // we show some text starting on some absolute position with a given // alignment cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, dateString, getPointsFromMM(210 - 20), getPointsFromMM(297 - 20), 0); cb.endText(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java
License:Open Source License
private Font getFont(String baseFont) { BaseFont bf = null;//from w ww . j a v a 2s.com Font font; try { bf = BaseFont.createFont(baseFont.toString(), FONTS[0][1], BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } font = new Font(bf, 6); return font; }
From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java
License:Open Source License
private Font getFont() { BaseFont bf = null;/* ww w .j a v a2 s .com*/ Font font; try { bf = BaseFont.createFont(FONTS[0][0], FONTS[0][1], BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } font = new Font(bf, 6); return font; }
From source file:ispyb.client.biosaxs.pdf.DataAcquisitionPDFReport.java
License:Open Source License
private ByteArrayOutputStream exportAsPdf(Experiment3VO experiment, List<Buffer3VO> buffers, Proposal3VO proposal) throws Exception { Document document = new Document(PageSize.A4.rotate(), 10, 10, 20, 20); document.addTitle("exportSamplesView"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); HeaderFooter header = new HeaderFooter( new Phrase(proposal.getTitle() + " " + proposal.getCode() + proposal.getNumber()), false); header.setAlignment(Element.ALIGN_CENTER); header.getBefore().getFont().setSize(8); HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true); footer.setAlignment(Element.ALIGN_RIGHT); footer.setBorderWidth(1);// w w w.ja va 2s .c om footer.getBefore().getFont().setSize(6); document.setHeader(header); document.setFooter(footer); document.open(); BaseFont bf = BaseFont.createFont(FONTS[0][0], FONTS[0][1], BaseFont.EMBEDDED); Font font = new Font(bf, 6); document.add(new Paragraph("Data Acquisition: " + experiment.getName(), font)); document.add(new Paragraph("Type: " + experiment.getType(), font)); document.add(new Paragraph("Date: " + experiment.getCreationDate(), font)); document.add(new Paragraph("Proposal: " + proposal.getCode() + proposal.getNumber(), font)); document.add(new Paragraph("Title: " + proposal.getTitle(), font)); document.add(new Paragraph(" ")); document.add(new Paragraph("Measurements", PdfRtfExporter.FONT_DOC_BOLD)); document.add(new Paragraph(" ")); document.add(this.getMeasurementTable(experiment, buffers)); document.newPage(); document.add(new Paragraph(" ")); document.add(new Paragraph("Analysis", PdfRtfExporter.FONT_DOC_BOLD)); document.add(new Paragraph(" ")); document.add(this.getAnalysis(experiment, buffers)); document.newPage(); document.add(this.getImageTable(experiment, buffers)); document.close(); return baos; }
From source file:jdbreport.model.io.pdf.itext2.ReportFontMapper.java
License:Apache License
private BaseFont getDefaultBaseFont() throws DocumentException, IOException { if (getDefaultFont() != null) { return BaseFont.createFont(getDefaultFont(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); }/*www . j a va2 s . c o m*/ return null; }
From source file:jgnash.ui.report.FontRegistry.java
License:Open Source License
private void registerFont(final String path) { try {//from w w w .j av a 2 s .com if (path.toLowerCase().endsWith(".ttf") || path.toLowerCase().endsWith(".otf") || path.toLowerCase().indexOf(".ttc,") > 0) { Object allNames[] = BaseFont.getAllFontNames(path, BaseFont.WINANSI, null); String[][] names = (String[][]) allNames[2]; //full name for (String[] name : names) { registeredFontMap.put(name[3].toLowerCase(), path); } } else if (path.toLowerCase().endsWith(".ttc")) { String[] names = BaseFont.enumerateTTCNames(path); for (int i = 0; i < names.length; i++) { registerFont(path + "," + i); } } else if (path.toLowerCase().endsWith(".afm") || path.toLowerCase().endsWith(".pfm")) { BaseFont bf = BaseFont.createFont(path, BaseFont.CP1252, false); String fullName = bf.getFullFontName()[0][3].toLowerCase(); registeredFontMap.put(fullName, path); } } catch (DocumentException | IOException e) { throw new RuntimeException(e); } }
From source file:joelib2.io.types.PDF.java
License:Open Source License
/** * Writes a molecule with his <tt>PairData</tt> . * * @param mol the molecule with additional data * @param title the molecule title or <tt>null</tt> if the title * from the molecule should be used * @param writePairData if <tt>true</tt> then the additional molecule data * is written//ww w.ja v a 2 s . c o m * @param attribs2write Description of the Parameter * @return <tt>true</tt> if the molecule and the data has * been succesfully written. * @exception IOException Description of the Exception */ public boolean write(Molecule mol, String title, boolean writePairData, List attribs2write, SMARTSPatternMatcher smarts) throws IOException { if (firstMoleculeWritten == false) { document.open(); firstMoleculeWritten = true; } Dimension d = new Dimension(Mol2Image.instance().getDefaultWidth(), Mol2Image.instance().getDefaultHeight()); RenderingAtoms container = new RenderingAtoms(); container.add(mol); RenderHelper.translateAllPositive(container); RenderHelper.scaleMolecule(container, d, 0.8); RenderHelper.center(container, d); Renderer2D renderer = new Renderer2D(); //BaseFont helvetica = null; try { BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED); } catch (DocumentException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } int w = d.width; int h = d.height; PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphics(w, h); g2.setStroke(new BasicStroke(0.1f)); tp.setWidth(w); tp.setHeight(h); g2.setColor(renderer.getRenderer2DModel().getBackColor()); g2.fillRect(0, 0, d.width, d.height); if (smarts != null) { renderer.selectSMARTSPatterns(container, smarts); } renderer.paintMolecule(container, g2); g2.dispose(); ////cb.addTemplate(tp, 72, 720 - h); //cb.addTemplate(tp, 12, 720 - h); cb.addTemplate(tp, 0, document.getPageSize().height() - h); // Mol2Image.instance().mol2image(mol); BaseFont bf = null; try { bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); } catch (DocumentException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } String string = ""; //float myBorder = DEFAULT_BORDER; //float fontSize = 10; //float fontSizeDelta = DEFAULT_FONT_OFFSET; float hpos; if (writePairData) { PairData pairData; PairDataIterator gdit = mol.genericDataIterator(); int index = 0; boolean firstPageWritten = false; List attributesV; if (attribs2write == null) { // write all descriptors attributesV = new Vector(); //DescResult tmpPropResult; while (gdit.hasNext()) { pairData = gdit.nextPairData(); attributesV.add(pairData.getKey()); } } else { attributesV = attribs2write; } // sort descriptors by attribute name String[] attributes = new String[attributesV.size()]; for (int i = 0; i < attributesV.size(); i++) { attributes[i] = (String) attributesV.get(i); } Arrays.sort(attributes); // write them for (int i = 0; i < attributes.length; i++) { pairData = mol.getData(attributes[i]); string = pairData.getKey() + " = " + pairData.toString(); // reduce too complex data string = string.replace('\n', ' '); string = string.substring(0, Math.min(string.length(), WRITE_MAX_CHARACTERS)); tp = cb.createTemplate(document.getPageSize().width() - pageBorder, fontSize + fontSizeDelta); tp.setFontAndSize(bf, fontSize); tp.beginText(); tp.setTextMatrix(0, fontSizeDelta); tp.showText(string); tp.endText(); cb.setLineWidth(1f); tp.moveTo(0, 0); tp.lineTo(document.getPageSize().width() - (2 * pageBorder), 0); tp.stroke(); if (firstPageWritten) { hpos = document.getPageSize().height() - ((fontSize + fontSizeDelta) * (index + 1)); } else { hpos = document.getPageSize().height() - h - ((fontSize + fontSizeDelta) * (index + 1)); } if (hpos < pageBorder) { index = 1; firstPageWritten = true; hpos = document.getPageSize().height() - ((fontSize + fontSizeDelta) * (index + 1)); try { document.newPage(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } cb.addTemplate(tp, pageBorder, hpos); index++; } } try { document.newPage(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } return (true); }
From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java
License:Apache License
public byte[] writePage() throws Exception { ByteArrayOutputStream bout = new ByteArrayOutputStream(); try {// w w w.j ava2s . c om logo = Image.getInstance(root.getAbsolutePath() + "/logo.gif"); logo.setAlignment(Image.ALIGN_LEFT); } catch (Exception exc) { exc.printStackTrace(); } baseArial = BaseFont.createFont(root.getAbsolutePath() + "/objects/arial.ttf", BaseFont.CP1257, BaseFont.EMBEDDED); Document doc = new Document(PageSize.A4, 56.5354331f, 22.6771654f, 28.3464567f, 25.0f); PdfWriter.getInstance(doc, bout); doc.open(); logo.setAbsolutePosition(28.3464567f, doc.getPageSize().height() - logo.height() - 25.0f); doc.add(logo); Paragraph pg = new Paragraph(sdf.format(new Date()), new Font(baseArial, 10)); pg.setAlignment(Element.ALIGN_RIGHT); doc.add(pg); doc.add(new Phrase("\n\n\n")); writeClientInfo(doc); writeTicketInfo(doc); writeJobInfo(doc); writeWorkerInfo(doc); doc.close(); return bout.toByteArray(); }