List of usage examples for com.lowagie.text.pdf BaseFont CP1252
String CP1252
To view the source code for com.lowagie.text.pdf BaseFont CP1252.
Click Source Link
From source file:AppletViewer.java
License:Open Source License
/** * Metodo que agrega annotaciones (en texto) al nuevo PDF * @param stamper// w ww .j a v a 2 s. c om * @param pageNumber * @param x * @param y * @param text * @param size */ public void addTextAnnotation(PdfStamper stamper, int pageNumber, float x, float y, String text, float size) { try { BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); // set font PdfContentByte over = stamper.getOverContent(pageNumber); float positionX = ((x * 2480) / 1654); float positionY = ((y * 3508) / 2339); // write text over.beginText(); over.setFontAndSize(bf, size); // set font and size over.setTextMatrix(positionX, positionY); // set x,y position (0,0 is at the bottom left) over.showText(text); // set text over.endText(); } catch (Exception e) { e.printStackTrace(); } }
From source file:br.gov.jfrj.siga.ex.util.GeradorRTF.java
License:Open Source License
public byte[] geraRTF(ExDocumento doc) throws Exception { html = doc.getConteudoBlobHtmlString(); html = (new ProcessadorHtml()).canonicalizarHtml(html, true, false, true, true, false); html = html.replace("<!-- INICIO MIOLO -->", "<MIOLO>"); html = html.replace("<!-- FIM MIOLO -->", "</MIOLO>"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); RtfWriter2.getInstance(document, baos); document.open();/*from w w w . j av a2s . c om*/ document.setMargins(29, 340, 29, 29); parser.setInput(new StringReader(html)); BaseFont arial = BaseFont.createFont("C:\\WINDOWS\\FONTS\\ARIAL.TTF", BaseFont.CP1252, true); Font fonte = new Font(arial); fonte.setSize(7); Paragraph paragrafoBase = new Paragraph("", fonte); paragrafoBase.add("\t" + doc.getOrgaoUsuario().getDescricaoMaiusculas()); paragrafoBase.add("\n\n"); paragrafoBase .add("\t" + doc.getExFormaDocumento().getDescricao().toUpperCase() + " " + doc.getCodigoString()); if (doc.getDtDocDDMMYY() != null && doc.getDtDocDDMMYY().length() > 0) paragrafoBase.add(" DE " + doc.getDtDocDDMMYY()); paragrafoBase.add("\n\n"); try { seekTag("MIOLO"); paragrafoBase = (Paragraph) percorreProximoBloco(paragrafoBase, 0, true); document.add(paragrafoBase); } catch (XmlPullParserException xppe) { int a = 2; } catch (IOException ioe) { int a = 2; } finally { document.close(); } /* * Pattern p1 = Pattern .compile("^.<!-- INICIO MIOLO -->.<!-- * FIM MIOLO -->."); final Matcher m = p1.matcher(html); */ byte[] retorno = baos.toByteArray(); baos.close(); return retorno; }
From source file:br.org.archimedes.io.pdf.elements.TextExporter.java
License:Open Source License
public void exportElement(Text text, Object outputObject) throws IOException { PDFWriterHelper helper = (PDFWriterHelper) outputObject; PdfContentByte cb = helper.getPdfContentByte(); Point lowerLeft = text.getLowerLeft(); Point docPoint = helper.modelToDocument(lowerLeft); BaseFont font = null;//from w w w . j a v a 2s.c o m try { font = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); } catch (DocumentException e) { // Problems creating the font. This means the current // platform does not support this encoding or font. System.err.println(Messages.TextExporter_FontCreatingError); e.printStackTrace(); } cb.setFontAndSize(font, (float) text.getSize()); cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL); cb.beginText(); cb.moveText((float) docPoint.getX(), (float) docPoint.getY()); double angle = 0; try { angle = Geometrics.calculateAngle(new Point(0, 0), text.getDirection().getPoint()); } catch (NullArgumentException e) { // Shouldn't happen since the text MUST have a direction to exists // and the point 0,0 is valid e.printStackTrace(); } float degreeAngle = (float) (angle * 180 / Math.PI); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, text.getText(), (float) docPoint.getX(), (float) docPoint.getY(), degreeAngle); cb.endText(); }
From source file:classroom.intro.HelloWorld05.java
public static void main(String[] args) { // step 1/*from w w w . j a v a 2 s . co m*/ Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.saveState(); // q cb.beginText(); // BT cb.moveText(36, 806); // 36 806 Td cb.moveText(0, -18); // 0 -18 Td cb.setFontAndSize(bf, 12); // /F1 12 Tf cb.showText("Hello World"); // (Hello World)Tj cb.endText(); // ET cb.restoreState(); // Q } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld06.java
public static void main(String[] args) { // step 1/*ww w . j ava 2 s.co m*/ Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setTextMatrix(36, 788); cb.setFontAndSize(bf, 12); cb.showText("Hello World"); cb.endText(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld07.java
public static void main(String[] args) { // step 1/*from w w w . j av a2 s . c om*/ Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 12); cb.showTextAligned(Element.ALIGN_LEFT, "Hello World", 36, 788, 0); cb.endText(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld08.java
public static void main(String[] args) { Document.compress = false;/*from w ww .j a v a2 s . c o m*/ // step 1 Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 12); cb.moveText(88.66f, 788); cb.showText("ld"); cb.moveText(-22f, 0); cb.showText("Wor"); cb.moveText(-15.33f, 0); cb.showText("llo"); cb.endText(); PdfTemplate tmp = cb.createTemplate(250, 25); tmp.beginText(); tmp.setFontAndSize(bf, 12); tmp.moveText(0, 7); tmp.showText("He"); tmp.endText(); cb.addTemplate(tmp, 36, 781); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld09.java
public static void main(String[] args) { Document.compress = false;// www. j a va2s .co m BaseFont bf = null; // step 1 Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT1)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 12); cb.moveText(88.66f, 788); cb.showText("ld"); cb.moveText(-22f, 0); cb.showText("Wor"); cb.endText(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); try { PdfReader reader = new PdfReader(RESULT1); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT2)); PdfContentByte cb1 = stamper.getUnderContent(1); cb1.beginText(); cb1.setFontAndSize(bf, 12); cb1.setTextMatrix(51.33f, 788); cb1.showText("llo"); cb1.endText(); PdfContentByte cb2 = stamper.getOverContent(1); PdfTemplate tmp = cb2.createTemplate(250, 25); tmp.beginText(); tmp.setFontAndSize(bf, 12); tmp.moveText(0, 7); tmp.showText("He"); tmp.endText(); cb2.addTemplate(tmp, 36, 781); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:com.aryjr.nheengatu.testes.AbsolutePosition.java
License:Open Source License
public static void main(final String[] args) { // System.out.println("My First PdfPTable"); final Document document = new Document(); try {// w w w .j av a 2 s . c om final PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/aryjr/MyFirstTable.pdf")); document.open(); // PdfPTable table = createTable(); // document.add(table); // table.writeSelectedRows(0, -1, 50, 200, // writer.getDirectContent()); final PdfContentByte cb = writer.getDirectContent(); cb.concatCTM(1f, 0f, 0f, -1f, 0f, 0f); // Paragraph text = new Paragraph("Ary Junior", // FontFactory.getFont(Style.DEFAULT_FONT_FAMILY, // Style.DEFAULT_FONT_SIZE, Font.NORMAL, Style.DEFAULT_FONT_COLOR)); final BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(bf, 12); cb.showText("Ary Junior"); cb.endText(); Runtime.getRuntime().exec("acroread /home/aryjr/MyFirstTable.pdf"); } catch (final DocumentException de) { System.err.println(de.getMessage()); } catch (final IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:com.estate.pdf.PageBorder.java
public void draw(Document doc, int iconNum, String pageNum, String toolName) { try {//from w w w . ja v a 2 s . c o m PdfContentByte cb = writer.getDirectContentUnder(); BaseFont fontBold = BaseFont.createFont(Locations.getFontLocation() + "timesbd.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); BaseFont font = BaseFont.createFont(Locations.getFontLocation() + "times.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); Rectangle rct = new Rectangle(doc.getPageSize()); float iconBase = (1.25f * 72); // This is the base of the icons on // the page Image icon = Image.getInstance(Locations.getImageLocation() + icons[iconNum]); // Image box = Image.getInstance(Locations.ImageLocation() + // "blueBOX.png"); icon.scalePercent(23); float scale = .23f; float iconLeft = (icon.getWidth() / 2) * scale; float boxSize = (.1875f * 72); // Adjust the top rct.setTop(rct.getTop() - (.5f * 72)); // Place the Icon icon.setAbsolutePosition((1.25f * 72) - iconLeft, rct.getTop() - iconBase); doc.add(icon); // Set our line color cb.setRGBColorStroke(0, 72, 117); cb.setLineWidth(.75f); // do the bottom line cb.moveTo(1.25f * 72, (.5f * 72)); cb.lineTo(rct.getRight() - (.5f * 72), (.5f * 72)); cb.moveTo(1.25f * 72, (.5f * 72)); cb.lineTo(1.25f * 72, rct.getTop()); // stroke the lines cb.stroke(); // Do the lower left box cb.rectangle((1.25f - 0.09375f) * 72, (.5f - 0.09375f) * 72, boxSize, boxSize); cb.setRGBColorFill(0, 72, 117); cb.closePathFillStroke(); // Do the lower right box Rectangle pnRect = new Rectangle(0, 0); pnRect.setLeft(rct.getRight() - ((.5f + 0.09375f) * 72)); pnRect.setTop((.5f - 0.09375f) * 72); pnRect.setRight(pnRect.getLeft() + boxSize); pnRect.setBottom(pnRect.getTop() - boxSize); // cb.rectangle(rct.getRight() - ((.5f + 0.09375f) * 72), (.5f - // 0.09375f) * 72, (.1875f * 72), (.1875f * 72)); cb.rectangle(pnRect.getLeft(), pnRect.getTop(), boxSize, boxSize); cb.setRGBColorFill(0, 72, 117); cb.closePathFillStroke(); // Now we do the page number if one is supplied. if (pageNum.length() > 0) { float pnHeight = fontBold.getAscentPoint(pageNum, 9) - fontBold.getDescentPoint(pageNum, 9); float pnWidth = fontBold.getWidthPoint(pageNum, 9); float l = pnRect.getLeft() + ((boxSize - pnWidth) / 2); float b = pnRect.getTop() + ((boxSize - pnHeight) / 2); cb.beginText(); cb.setFontAndSize(fontBold, 9); cb.setRGBColorFill(255, 255, 255); cb.setTextMatrix(l, b); cb.showText(pageNum); cb.endText(); } // Display the copyright SimpleDateFormat df = new SimpleDateFormat("yyyy"); char cs = 0x00a9; // Unicode for the copyright symbol String copyRight = com.estate.constants.StringConstants.copyRight + cs + " " + df.format(new Date()); float crWidth; float crLeft; crWidth = font.getWidthPoint(copyRight, 8); cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); crLeft = (doc.getPageSize().getRight() - crWidth) / 2; cb.setTextMatrix(crLeft, .375f * 72); // Place the base of the // copyright at 3/8" up from // the bottom cb.showText(copyRight); cb.endText(); if (toolName.length() > 0) { cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); cb.setTextMatrix((1.25f * 72) + boxSize, .375f * 72); cb.showText(toolName); cb.endText(); } // Fix a licensee at left cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, " Licensee: " + getLicense(), (10.2f * 72), .375f * 72, 0); cb.endText(); } catch (Exception e) { System.out.println(e.getMessage()); } }