List of usage examples for com.lowagie.text.pdf PdfTemplate moveTo
public void moveTo(float x, float y)
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); template.lineTo(convLengt, convHeight); template.moveTo(convLengt, 0f);//from w w w .j ava 2s. c o m 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: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/*from w w w . j av a 2s .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:tufts.vue.PresentationNotes.java
License:Educational Community License
private static PdfTemplate drawLines(PdfWriter writer) { PdfContentByte cb2 = writer.getDirectContent(); //cb.cr/* w w w . j a v a 2 s. co m*/ PdfTemplate tp2 = cb2.createTemplate(SlideSizeX + 40, SlideSizeY); tp2.setColorStroke(Color.gray); //tp2.setColorFill(Color.gray); int x = 30; for (int i = 1; i < 9; i++) { tp2.moveTo(0, x); tp2.lineTo(SlideSizeX + 40, x); tp2.stroke(); x += 20; } return tp2; }