List of usage examples for com.lowagie.text.pdf BaseFont WINANSI
String WINANSI
To view the source code for com.lowagie.text.pdf BaseFont WINANSI.
Click Source Link
From source file:cn.js.nt.yao.sudokupdf.PDFFontMapper.java
License:Apache License
@Override public BaseFont awtToPdf(Font font) { try {/*w w w . j a v a 2 s . c om*/ return BaseFont.createFont("/URWGothicL-Demi.afm", BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (DocumentException ex) { Logger.getLogger(PDFFontMapper.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException(ex); } catch (IOException ex) { Logger.getLogger(PDFFontMapper.class.getName()).log(Level.SEVERE, null, ex); throw new RuntimeException(ex); } }
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
public static void addHeader(PdfWriter writer, String header) { class MyFooter extends PdfPageEventHelper { com.lowagie.text.Font ffont; @Override/*from w w w . ja v a 2 s . c o m*/ public void onEndPage(PdfWriter writer, Document document) { try { ffont = new com.lowagie.text.Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED), 6f, com.lowagie.text.Font.ITALIC); } catch (Exception e) { e.printStackTrace(); return; } String date = FormatterUtils.formatDateTime(new Date()); PdfContentByte cb = writer.getDirectContent(); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(header, ffont), document.left(), document.top() + 5, 0); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase("Page " + writer.getCurrentPageNumber(), ffont), (document.right() - document.left()) / 2 + document.leftMargin(), document.bottom() - 5, 0); ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, new Phrase(date, ffont), document.right(), document.bottom() - 5, 0); } } writer.setPageEvent(new MyFooter()); }
From source file:com.geek.tutorial.itext.acroform.RadioCheckBoxForm.java
License:Open Source License
public RadioCheckBoxForm() throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("RadioCheckBoxForm.pdf")); document.open();/*from w w w .j av a2 s .c o m*/ PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); Rectangle rect; // Code 1 create radio button String[] radios = { "Radio1", "Radio2", "Radio3" }; PdfFormField radioField = PdfFormField.createRadioButton(writer, true); radioField.setFieldName("radioField"); radioField.setValueAsName(radios[0]); for (int i = 0; i < radios.length; i++) { rect = new Rectangle(40, 815 - i * 30, 60, 797 - i * 30); addRadioButton(writer, rect, radioField, radios[i], i == 0); cb.beginText(); cb.setFontAndSize(bf, 12); cb.showTextAligned(Element.ALIGN_LEFT, radios[i], 70, 802 - i * 30, 0); cb.endText(); } writer.addAnnotation(radioField); // Code 2 create checkbox button String[] options = { "Check1", "Check2", "Check3" }; for (int i = 0; i < options.length; i++) { rect = new Rectangle(160, 815 - i * 30, 180, 797 - i * 30); addCheckbox(writer, rect, options[i]); cb.beginText(); cb.setFontAndSize(bf, 12); cb.showTextAligned(Element.ALIGN_LEFT, options[i], 190, 802 - i * 30, 0); cb.endText(); } // Code 3 add function and button for showing state writer.addJavaScript( "function showState(){" + "app.alert('Radio:'+ this.getField('radioField').value +'\\n\\n'+" + "'Check1:'+this.getField('Check1').value +'\\n'+" + "'Check2:'+this.getField('Check2').value +'\\n'+" + "'Check3:'+this.getField('Check3').value);" + "}"); PushbuttonField push = new PushbuttonField(writer, new Rectangle(80, 710, 150, 730), "pushAction"); push.setBackgroundColor(Color.LIGHT_GRAY); push.setBorderColor(Color.GRAY); push.setText("Show State"); push.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); push.setTextColor(Color.BLACK); PdfFormField pushbutton = push.getField(); pushbutton.setAction(PdfAction.javaScript("showState()", writer)); writer.addAnnotation(pushbutton); document.close(); }
From source file:com.gp.cong.logisoft.lcl.report.FreightInvoiceLclPdfCreator.java
@Override public void onOpenDocument(PdfWriter writer, Document document) { total = writer.getDirectContent().createTemplate(100, 100); total.setBoundingBox(new Rectangle(-20, -20, 100, 100)); try {/*from w w w .jav a2 s . c o m*/ helv = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); } catch (Exception e) { log.info("onOpenDocument failed on " + new Date(), e); throw new ExceptionConverter(e); } }
From source file:com.logiware.accounting.reports.ArDisputeReportCreator.java
@Override public void onOpenDocument(PdfWriter writer, Document document) { pageTemplate = writer.getDirectContent().createTemplate(20, 10); pageTemplate.setBoundingBox(new Rectangle(-20, -20, 20, 50)); try {// w w w . j ava 2 s . c om helvFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); } catch (DocumentException e) { log.info("onOpenDocument failed on " + new Date(), e); } catch (IOException e) { log.info("onOpenDocument failed on " + new Date(), e); } }
From source file:com.moss.check.us.CheckPdfRenderer.java
License:Open Source License
public void render(CheckModel model, OutputStream out) throws Exception { Document document = new Document(); document.setPageSize(new Rectangle(PAGE_WIDTH, PAGE_HEIGHT)); PdfWriter writer = PdfWriter.getInstance(document, out); document.open();//from w w w . j a v a2s .c om PdfContentByte cb = writer.getDirectContent(); Check check = new Check(); check.defaultFont = BaseFont.createFont("Helvetica", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); check.defaultFontSize = 8; check.defaultFontLeading = 10; check.largeFontSize = 9; check.largeFontLeading = 12; check.fixedWidthFont = createFixedFont(); check.fixedWidthFontSize = 8; check.voidFont = BaseFont.createFont("Helvetica-Bold", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); check.voidFontSize = 14; check.micrFont = createMicrFont(); check.micrFontSize = 12; check.model = model; check.x = 0; check.y = 0; check.renderMode = CheckRenderMode.CHECK; check.render(cb); if (StubPrintMode.CHECK_DUPLICATE == model.stubPrintMode) { check.renderMode = CheckRenderMode.STUB; check.y = document.top() - (8.2f * POINTS_IN_A_CM); check.render(cb); } else if (StubPrintMode.CUSTOM == model.stubPrintMode) { PdfReader reader = new PdfReader(model.customStubPdf); PdfImportedPage customPage = writer.getImportedPage(reader, 1); cb.addTemplate(customPage, 0f, 0f); } else { throw new RuntimeException("Unknown stub print mode: " + model.stubPrintMode); } document.close(); }
From source file:com.moss.check.us.CheckPdfRenderer.java
License:Open Source License
private BaseFont createMicrFont() throws Exception { boolean cached = true; byte[] ttf;/*from ww w . j ava2 s. c om*/ { InputStream in = CheckPdfRenderer.class.getResourceAsStream("/com/moss/check/us/GnuMICR.ttf"); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024 * 10]; //10k buffer for (int numRead = in.read(buffer); numRead != -1; numRead = in.read(buffer)) { out.write(buffer, 0, numRead); } ttf = out.toByteArray(); } byte[] pfb = null; boolean noThrow = false; BaseFont baseFont = BaseFont.createFont("GnuMICR.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, cached, ttf, pfb, noThrow); return baseFont; }
From source file:com.moss.check.us.CheckPdfRenderer.java
License:Open Source License
private BaseFont createFixedFont() throws Exception { boolean cached = true; byte[] ttf;//from ww w .ja v a2 s .c o m { InputStream in = CheckPdfRenderer.class.getResourceAsStream("/com/moss/check/us/VeraMono.ttf"); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024 * 10]; //10k buffer for (int numRead = in.read(buffer); numRead != -1; numRead = in.read(buffer)) { out.write(buffer, 0, numRead); } ttf = out.toByteArray(); } byte[] pfb = null; boolean noThrow = false; BaseFont baseFont = BaseFont.createFont("VeraMono.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, cached, ttf, pfb, noThrow); return baseFont; }
From source file:com.moss.pdf.template.core.Renderer.java
License:Open Source License
public void render(InputStream in, List<? extends PropertyMapping> fields, OutputStream out) throws Exception { PdfReader reader = new PdfReader(in); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfWriter writer = PdfWriter.getInstance(document, out); document.open();//from w w w . j av a2s . co m for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte cb = writer.getDirectContent(); PdfImportedPage customPage = writer.getImportedPage(reader, i); /* * add the page to our new document, turning this page to its * original rotation */ int pageRotation = reader.getPageRotation(i); if (pageRotation > 0) { System.out.println("page rotation found: " + pageRotation); double angle = -((2 * Math.PI) * pageRotation / 360); // double angle = -(Math.PI / 2); cb.addTemplate(customPage, (float) Math.cos(angle), (float) Math.sin(angle), (float) -Math.sin(angle), (float) Math.cos(angle), 0f, // x document.top() + document.topMargin() // y ); } else { cb.addTemplate(customPage, 0f, 0f); } Map<FontName, BaseFont> fonts = new HashMap<FontName, BaseFont>(); for (PropertyMapping field : fields) { if (field.getPageNumber() != i) { continue; } /* * Only builtin fonts are supported at the moment */ BaseFont font; int fontSize; int alignment; String text; float x, y; float rotation; { font = fonts.get(field.getFontName()); if (font == null) { FontName e = field.getFontName(); String name = null; if (FontName.COURIER == e) { name = BaseFont.COURIER; } else if (FontName.COURIER_BOLD == e) { name = BaseFont.COURIER_BOLD; } else if (FontName.COURIER_BOLD_OBLIQUE == e) { name = BaseFont.COURIER_BOLDOBLIQUE; } else if (FontName.COURIER_OBLIQUE == e) { name = BaseFont.COURIER_OBLIQUE; } else if (FontName.HELVETICA == e) { name = BaseFont.HELVETICA; } else if (FontName.HELVETICA_BOLD == e) { name = BaseFont.HELVETICA_BOLD; } else if (FontName.HELVETICA_BOLD_OBLIQUE == e) { name = BaseFont.HELVETICA_BOLDOBLIQUE; } else if (FontName.HELVETICA_OBLIQUE == e) { name = BaseFont.HELVETICA_OBLIQUE; } else if (FontName.TIMES_BOLD == e) { name = BaseFont.TIMES_BOLD; } else if (FontName.TIMES_BOLD_ITALIC == e) { name = BaseFont.TIMES_BOLDITALIC; } else if (FontName.TIMES_ITALIC == e) { name = BaseFont.TIMES_ITALIC; } else if (FontName.TIMES_ROMAN == e) { name = BaseFont.TIMES_ROMAN; } if (name == null) { throw new RuntimeException("Unknown font type: " + e); } font = BaseFont.createFont(name, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); fonts.put(field.getFontName(), font); } fontSize = field.getFontSize(); if (TextAlignment.LEFT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_LEFT; } else if (TextAlignment.CENTER == field.getAlignment()) { alignment = PdfContentByte.ALIGN_CENTER; } else if (TextAlignment.RIGHT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_RIGHT; } else { alignment = PdfContentByte.ALIGN_LEFT; } Object value = p.eval(field.getExpr()); if (value == null) { text = ""; } else { text = value.toString(); } x = field.getX() * POINTS_IN_A_CM; y = field.getY() * POINTS_IN_A_CM; rotation = 0; } cb.beginText(); cb.setFontAndSize(font, fontSize); cb.showTextAligned(alignment, text, x, y, rotation); cb.endText(); } document.newPage(); } reader.close(); document.close(); }
From source file:com.openkm.util.PDFUtils.java
License:Open Source License
/** * Obtain base font for PDF processing/* w w w .j a va2s.c om*/ */ private static BaseFont getBaseFont() throws DocumentException, IOException { String fontName = Config.HOME_DIR + "/lib/unicode.ttf"; String fontEncoding = BaseFont.IDENTITY_H; if (!new File(fontName).exists()) { log.warn("Unicode TTF font not found: {}", fontName); fontName = BaseFont.HELVETICA; fontEncoding = BaseFont.WINANSI; } return BaseFont.createFont(fontName, fontEncoding, BaseFont.EMBEDDED); }