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:managedbean.aas.reportController.java
public static void concatPDFs(List<InputStream> streamOfPDFFiles, OutputStream outputStream, boolean paginate) { Document document = new Document(); try {/*from w w w . j av a 2s. c om*/ List<InputStream> pdfs = streamOfPDFFiles; List<PdfReader> readers = new ArrayList<PdfReader>(); int totalPages = 0; Iterator<InputStream> iteratorPDFs = pdfs.iterator(); // Create Readers for the pdfs. while (iteratorPDFs.hasNext()) { InputStream pdf = iteratorPDFs.next(); PdfReader pdfReader = new PdfReader(pdf); readers.add(pdfReader); totalPages += pdfReader.getNumberOfPages(); } // Create a writer for the outputstream PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); PdfContentByte cb = writer.getDirectContent(); // Holds the PDF // data PdfImportedPage page; int currentPageNumber = 0; int pageOfCurrentReaderPDF = 0; Iterator<PdfReader> iteratorPDFReader = readers.iterator(); // Loop through the PDF files and add to the output. while (iteratorPDFReader.hasNext()) { PdfReader pdfReader = iteratorPDFReader.next(); // Create a new page in the target for each source page. while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) { document.newPage(); pageOfCurrentReaderPDF++; currentPageNumber++; page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF); cb.addTemplate(page, 0, 0); // Code for pagination. if (paginate) { cb.beginText(); cb.setFontAndSize(bf, 9); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "" + currentPageNumber + " of " + totalPages, 520, 5, 0); cb.endText(); } } pageOfCurrentReaderPDF = 0; } outputStream.flush(); document.close(); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (document.isOpen()) { document.close(); } try { if (outputStream != null) { outputStream.close(); } } catch (IOException ioe) { ioe.printStackTrace(); } } }
From source file:mpv5.utils.export.Export.java
License:Open Source License
private static File mergeFiles(List<File> p) { Document document = new Document(); try {//from w w w . j a v a2s . c o m List<InputStream> pdfs = new ArrayList<InputStream>(); for (int i = 0; i < p.size(); i++) { File inputStream = p.get(i); pdfs.add(new FileInputStream(inputStream)); } List<PdfReader> readers = new ArrayList<PdfReader>(); int totalPages = 0; Iterator<InputStream> iteratorPDFs = pdfs.iterator(); while (iteratorPDFs.hasNext()) { InputStream pdf = iteratorPDFs.next(); PdfReader pdfReader = new PdfReader(pdf); readers.add(pdfReader); totalPages += pdfReader.getNumberOfPages(); } File f = FileDirectoryHandler.getTempFile("pdf"); FileOutputStream outputstream = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(document, outputstream); document.open(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); PdfContentByte cb = writer.getDirectContent(); PdfImportedPage page; int currentPageNumber = 0; int pageOfCurrentReaderPDF = 0; Iterator<PdfReader> iteratorPDFReader = readers.iterator(); // Loop through the PDF files and add to the output. while (iteratorPDFReader.hasNext()) { PdfReader pdfReader = iteratorPDFReader.next(); // Create a new page in the target for each source page. while (pageOfCurrentReaderPDF < pdfReader.getNumberOfPages()) { document.newPage(); pageOfCurrentReaderPDF++; currentPageNumber++; page = writer.getImportedPage(pdfReader, pageOfCurrentReaderPDF); cb.addTemplate(page, 0, 0); } pageOfCurrentReaderPDF = 0; } outputstream.flush(); document.close(); outputstream.close(); return f; } catch (Exception e) { Log.Debug(e); } finally { if (document.isOpen()) { document.close(); } } return null; }
From source file:mx.dr.util.report.impl.PdfService.java
License:Open Source License
/** * write a label in pdf document./*from w ww . j a v a 2 s . c o m*/ * <br/> * escribe una etiqueta en el documento pdf. * @param doc pdf document / documento pdf. * @param dto object that encompasses the values of the labels to be placed in the document / objeto que engloba los valores de las etiquetas que se colocaran en el documento. * @param offset jump on the Y axis to be given before placing the tag in the document / salto en el eje Y que se dara antes de colocar la etiqueta en el documento. * @param table container table if applicable / contenedor de tabla si es que aplica. * @throws Exception If an error occurs / si ocurre algun error. */ public void estampaEtiqueta(Document doc, Object dto, Float offset, PdfPTable table) throws Exception { List<Field> fields = new ArrayList<Field>(); for (Field m : dto.getClass().getDeclaredFields()) { m.setAccessible(true); if (m.getAnnotation(DRPdfLabel.class) != null) { fields.add(m); } } Collections.sort(fields, new Comparator<Field>() { public int compare(Field o1, Field o2) { DRPdfLabel etiqueta1 = o1.getAnnotation(DRPdfLabel.class); DRPdfLabel etiqueta2 = o2.getAnnotation(DRPdfLabel.class); String uno = int2String(etiqueta1.y()) + "." + int2String(etiqueta1.order()); String dos = int2String(etiqueta2.y()) + "." + int2String(etiqueta2.order()); return uno.compareTo(dos); } private String int2String(int num) { if (num < 10) { return "0" + num; } else { return String.valueOf(num); } } }); DRPdfLabel etiqueta; DRPdfTable etiquetaTabla; int lineaActual = 0; Paragraph pantagram = null; StringBuffer sb = null; Font font; Object valor; String label; DRPdfImage img; int residuo; int adicional = 0; for (Field m : fields) { etiqueta = m.getAnnotation(DRPdfLabel.class); img = m.getAnnotation(DRPdfImage.class); valor = m.get(dto); if (valor != null && valor instanceof List) { etiquetaTabla = m.getAnnotation(DRPdfTable.class); PdfPTable tableDance = null; if (etiquetaTabla != null) { tableDance = new PdfPTable(etiquetaTabla.colsPercentage()); tableDance.setSpacingBefore(etiqueta.offset()); for (String c : etiquetaTabla.columnLabels()) { tableDance.addCell(c); } } if (pantagram != null) { doc.add(pantagram); pantagram = null; } for (int i = 0; i < ((List) valor).size(); i++) { if (i == 0 && etiqueta.offset() > 0) { estampaEtiqueta(doc, ((List) valor).get(i), etiqueta.offset(), tableDance); } else { estampaEtiqueta(doc, ((List) valor).get(i), null, tableDance); } } if (etiquetaTabla != null) { doc.add(tableDance); } } else if (img != null) { /* File file = new File(IMGDIR + valor); FileInputStream inImg = new FileInputStream(file); byte[] b=new byte[(int)file.length()]; inImg.read(b);*/ Image ima = Image.getInstance(IMGDIR + valor); //System.out.println(ima.getPlainWidth()); ima.scaleAbsoluteWidth(img.width()); //System.out.println(ima.getScaledWidth()); ima.scaleAbsoluteHeight(ima.getScaledWidth()); ima.setAlignment(img.style()); ima.setAbsolutePosition(img.x(), img.y()); doc.add(ima); } else if (table != null) { PdfPCell cerda = null; label = value2String(valor); residuo = etiqueta.length() - label.length(); label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label; DRPdfColumn col = m.getAnnotation(DRPdfColumn.class); if (col != null) { cerda = new PdfPCell(new Paragraph(label)); cerda.setColspan(col.colspan()); table.addCell(cerda); } else { table.addCell(label); } } else { if (lineaActual < etiqueta.y()) { if (pantagram != null) { doc.add(pantagram); } if (offset == null || etiqueta.y() > 1) { if (etiqueta.offset() > 0) { pantagram = new Paragraph(etiqueta.offset()); } else { pantagram = new Paragraph(); } } else { pantagram = new Paragraph(offset); } lineaActual = etiqueta.y(); } if (etiqueta.wspacesBefore() > 0) { sb = new StringBuffer(""); fillEmpty(etiqueta.wspacesBefore(), sb); font = new Font(Font.COURIER, 12); pantagram.add(new Chunk(sb.toString(), font)); } sb = new StringBuffer(""); label = value2String(valor); residuo = etiqueta.length() - label.length(); label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label; if (etiqueta.font().equals(BaseFont.COURIER)) { font = new Font(Font.COURIER, etiqueta.fontSize(), etiqueta.style(), new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2])); adicional = 0; } else { font = FontFactory.getFont(TTFDIR + etiqueta.font(), BaseFont.CP1252, BaseFont.EMBEDDED, etiqueta.fontSize(), etiqueta.style(), new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2])); adicional = label.equals("") ? (residuo / 2) + 1 : 0; } if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.DER) && residuo > 0) { fillEmpty(residuo + adicional, sb); } sb.append(label); if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.IZQ) && residuo > 0) { fillEmpty(residuo + adicional, sb); } pantagram.add(new Chunk(sb.toString(), font)); } } if (pantagram != null) { doc.add(pantagram); } }
From source file:net.bull.javamelody.swing.print.AdvancedPageNumberEvents.java
License:Apache License
/** * we override the onOpenDocument method. * * @param writer//ww w .j av a 2 s.c om * PdfWriter * @param document * Document */ @Override 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 de) { throw new IllegalStateException(de); } catch (final IOException ioe) { throw new IllegalStateException(ioe); } }
From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java
License:Open Source License
static private Map<FontKey, PdfFont> createFontMap() { final Map<FontKey, PdfFont> result = new HashMap<FontKey, PdfFont>(4); addFont(result, "Quadraat-Regular", "QUAD____.ttf", BaseFont.CP1252); addFont(result, "Quadraat-Bold", "QUADBD__.ttf", BaseFont.CP1252); addFont(result, "Quadraat-Italic", "QUADI___.ttf", BaseFont.CP1252); addFont(result, "Quadraat-BoldItalic", "QUADBDI_.ttf", BaseFont.CP1252); addFont(result, "Arial", "Arial.ttf", BaseFont.CP1252); addFont(result, "Arial Black", "Arial_Black.ttf", BaseFont.CP1252); addFont(result, "Lucida Handwriting", "LucidaHandwriting.ttf", BaseFont.CP1252); addFont(result, "Garamond", "AdobeGaramondPro.ttf", BaseFont.CP1252); addFont(result, "Garamond Bold", "AdobeGaramondBold.ttf", BaseFont.CP1252); addFont(result, "Arial Unicode MS", "arialuni.ttf", BaseFont.IDENTITY_H); addFont(result, "DejaVu Serif Bold", "DejaVuSerif-Bold.ttf", BaseFont.IDENTITY_H); addFont(result, "Times New Roman", "tnr.ttf", BaseFont.CP1252); return result; }
From source file:nl.dykema.jxmlnote.report.pdf.MyDefaultFontMapper.java
License:Open Source License
public int insertFile(File file, int count) { String name = file.getPath().toLowerCase(); try {/* w ww . j a v a 2 s .c o m*/ if (name.endsWith(".ttf") || name.endsWith(".otf") || name.endsWith(".afm")) { Object allNames[] = BaseFont.getAllFontNames(file.getPath(), BaseFont.CP1252, null); insertNames(allNames, file.getPath()); ++count; } else if (name.endsWith(".ttc")) { String ttcs[] = BaseFont.enumerateTTCNames(file.getPath()); for (int j = 0; j < ttcs.length; ++j) { String nt = file.getPath() + "," + j; Object allNames[] = BaseFont.getAllFontNames(nt, BaseFont.CP1252, null); insertNames(allNames, nt); } ++count; } } catch (Exception e) { } return count; }
From source file:org.apache.maven.doxia.module.itext.ITextFont.java
License:Apache License
/** * Convenience method to get a defined MonoSpaced font depending the wanted style and size. * * @param style the font style./*from ww w .j a v a 2s. c om*/ * @param size the font size. * @param color the font color. * @return a font the font. */ public static Font getMonoSpacedFont(int style, float size, Color color) { try { return new Font(BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, false), size, style, color); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:org.areasy.common.doclet.document.DocumentEventHandler.java
License:Open Source License
/** * Constructs an event handler for a given PDF writer. * * @param pdfWriter The writer used to create the document. * @throws Exception/*from w ww. j a va 2 s . c o m*/ */ public DocumentEventHandler(PdfWriter pdfWriter) throws Exception { cb = pdfWriter.getDirectContent(); bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); template = cb.createTemplate(bf.getWidthPoint("Page 999 of 999", 8), 250); leftHeader = DefaultConfiguration.getString(ARG_HEADER_LEFT, ""); centerHeader = DefaultConfiguration.getString(ARG_HEADER_CENTER, ""); rightHeader = DefaultConfiguration.getString(ARG_HEADER_RIGHT, ""); String pageNumberTypeValue = DefaultConfiguration.getString(ARG_PGN_TYPE, ARG_VAL_FULL); if (pageNumberTypeValue.equalsIgnoreCase(ARG_VAL_FULL)) pageNumberType = PAGE_NUMBER_FULL; else pageNumberType = PAGE_NUMBER_SIMPLE; String pageNumberAlignValue = DefaultConfiguration.getString(ARG_PGN_ALIGNMENT, ARG_VAL_SWITCH); if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_LEFT)) pageNumberAlign = PAGE_NUMBER_ALIGN_LEFT; if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_CENTER)) pageNumberAlign = PAGE_NUMBER_ALIGN_CENTER; if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_RIGHT)) pageNumberAlign = PAGE_NUMBER_ALIGN_RIGHT; if (pageNumberAlignValue.equalsIgnoreCase(ARG_VAL_SWITCH)) pageNumberAlign = PAGE_NUMBER_ALIGN_SWITCH; }
From source file:org.areasy.common.doclet.document.Fonts.java
License:Open Source License
public static Font getFont(int faceType, int style, int size) { Font font = null;//from w w w . jav a2 s .co m String lookup = String.valueOf(faceType); String fontFile = fontTable.getProperty(lookup); int fontStyle = Font.NORMAL; Color color = COLOR_BLACK; if ((style & LINK) != 0) { fontStyle += Font.UNDERLINE; color = COLOR_LINK; } else if ((style & UNDERLINE) != 0) fontStyle += Font.UNDERLINE; if ((style & STRIKETHROUGH) != 0) fontStyle += Font.STRIKETHRU; if (fontFile != null) { File file = new File(DefaultConfiguration.getWorkDir(), fontFile); if (file.exists() && file.isFile()) { try { String encoding = encTable.getProperty(lookup, BaseFont.CP1252); BaseFont bfComic = BaseFont.createFont(file.getAbsolutePath(), encoding, BaseFont.EMBEDDED); if ((style & AbstractConfiguration.ITALIC) > 0) { if ((style & AbstractConfiguration.BOLD) > 0) fontStyle += Font.BOLDITALIC; else fontStyle += Font.ITALIC; } else if ((style & AbstractConfiguration.BOLD) > 0) fontStyle += Font.BOLD; if (fontStyle != Font.NORMAL) font = new Font(bfComic, size, fontStyle, color); else font = new Font(bfComic, size); if (font == null) throw new IllegalArgumentException("Font null: " + fontFile); } catch (Exception e) { e.printStackTrace(); throw new IllegalArgumentException("Font unusable"); } } else DocletUtility.error("Font file not found: " + fontFile); } else { // Use predefined font String face = ""; if (faceType == TEXT_FONT) { face = FontFactory.HELVETICA; if ((style & AbstractConfiguration.ITALIC) > 0) { if ((style & AbstractConfiguration.BOLD) > 0) face = FontFactory.HELVETICA_BOLDOBLIQUE; else face = FontFactory.HELVETICA_OBLIQUE; } else if ((style & AbstractConfiguration.BOLD) > 0) face = FontFactory.HELVETICA_BOLD; } else { face = FontFactory.COURIER; if ((style & ITALIC) > 0) { if ((style & BOLD) > 0) face = FontFactory.COURIER_BOLDOBLIQUE; else face = FontFactory.COURIER_OBLIQUE; } else if ((style & BOLD) > 0) face = FontFactory.COURIER_BOLD; } if (fontStyle != Font.NORMAL) font = FontFactory.getFont(face, size, fontStyle, color); else font = FontFactory.getFont(face, size); } return font; }
From source file:org.caisi.tickler.web.TicklerPrinter.java
License:Open Source License
public void start() throws DocumentException, IOException { //Create the font we are going to print to bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); font = new Font(bf, FONTSIZE, Font.NORMAL); boldFont = new Font(bf, FONTSIZE, Font.BOLD); document = new Document(); writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT); writer.setStrictImageSequence(true); document.setPageSize(PageSize.LETTER); document.open();// w w w .ja v a2s . c om }