List of usage examples for com.lowagie.text.pdf BaseFont EMBEDDED
boolean EMBEDDED
To view the source code for com.lowagie.text.pdf BaseFont EMBEDDED.
Click Source Link
From source file:org.revager.export.ProtocolPDFExporter.java
License:Open Source License
/** * Writes the given attendees to the protocol. * /* ww w .j a v a2 s .c o m*/ * @param protocol * the protocol * @param showAttendeesAspects * true, if the aspects of the reviewers should be part of the * protocol * @param showAttendeesPrepTime * true, if the preparation time of the reviewers should be part * of the protocol * @param showSignatureFields * ture, if the signature fields should be part of the protocol * * @throws ExportException * If an error occurs while writing the attendees to the * protocol */ protected void writeAttendees(Protocol protocol, boolean showAttendeesAspects, boolean showAttendeesPrepTime, boolean showSignatureFields) throws ExportException { List<Attendee> atts; if (protocol != null) { atts = protMgmt.getAttendees(protocol); } else { atts = Application.getInstance().getAttendeeMgmt().getAttendees(); } /* * Sort the attendees by their role into different lists */ List<Attendee> reviewers = new ArrayList<Attendee>(); List<Attendee> moderators = new ArrayList<Attendee>(); List<Attendee> scribes = new ArrayList<Attendee>(); List<Attendee> authors = new ArrayList<Attendee>(); List<Attendee> customers = new ArrayList<Attendee>(); List<Attendee> others = new ArrayList<Attendee>(); for (Attendee att : atts) { switch (att.getRole()) { case AUTHOR: authors.add(att); break; case CUSTOMER: customers.add(att); break; case MODERATOR: moderators.add(att); break; case REVIEWER: reviewers.add(att); break; case SCRIBE: scribes.add(att); break; default: others.add(att); break; } } List<List<Attendee>> attendees = new ArrayList<List<Attendee>>(); attendees.add(moderators); attendees.add(scribes); attendees.add(authors); attendees.add(customers); attendees.add(reviewers); attendees.add(others); /* * Write attendees */ try { Font contactFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font nameFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font roleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font aspectsFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font aspectsTitleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); /* * Build base table for all attendees */ PdfPTable tableAttendees = new PdfPTable(1); tableAttendees.setWidthPercentage(100); tableAttendees.setSplitRows(false); tableAttendees.getDefaultCell().setBorderWidth(0); tableAttendees.getDefaultCell().setPadding(0); boolean grayBackground = true; for (List<Attendee> attList : attendees) { for (Attendee att : attList) { /* * Build table for one attendee */ PdfPTable tableAttendee = new PdfPTable(new float[] { 0.80f, 0.20f }); tableAttendee.setWidthPercentage(100); tableAttendee.getDefaultCell().setBorderWidth(0); tableAttendee.getDefaultCell().setPadding(0); PdfPCell cellAttendee = new PdfPCell(); cellAttendee.setPadding(0); cellAttendee.setBorder(0); /* * Name of the attendee */ PdfPCell cell = new PdfPCell(); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingBottom(padding * 1.5f); cell.addElement(new Phrase(att.getName(), nameFont)); cell.addElement(new Phrase(att.getContact(), contactFont)); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading * 0.6f); /* * Aspects of this attendee */ if (!attMgmt.getAspects(att).isEmpty() && showAttendeesAspects) { String separator = ""; cell.addElement(phraseStrut); cell.addElement(new Phrase(translate("Assigned aspects:") + " ", aspectsTitleFont)); Phrase phraseAspects = new Phrase(); phraseAspects.setLeading(leading); phraseAspects.setFont(aspectsFont); for (Aspect asp : attMgmt.getAspects(att)) { phraseAspects.add(new Chunk( separator + asp.getDirective() + " (" + asp.getCategory() + ")", aspectsFont)); separator = " "; } cell.addElement(phraseAspects); } /* * Preparation time of the attendee */ Duration prepTime; if (protocol != null) { prepTime = protMgmt.getAttendeePrepTime(att, protocol); } else { prepTime = null; } if (prepTime != null && showAttendeesPrepTime) { cell.addElement(phraseStrut); cell.addElement(new Phrase(translate("Preparation time:") + " ", aspectsTitleFont)); Phrase phrasePrepTime = new Phrase(); phrasePrepTime.setLeading(leading); phrasePrepTime.setFont(aspectsFont); String prep = ""; String separator = ""; if (prepTime.getDays() > 0) { prep = prep + prepTime.getDays() + " " + translate("Day(s)"); separator = ", "; } if (prepTime.getHours() > 0) { prep = prep + separator + prepTime.getHours() + " " + translate("Hour(s)"); separator = ", "; } if (prepTime.getMinutes() >= 0) { prep = prep + separator + prepTime.getMinutes() + " " + translate("Minute(s)"); separator = ", "; } phrasePrepTime.add(new Chunk(prep, aspectsFont)); cell.addElement(phrasePrepTime); } /* * Signature field for the attendee */ if (showSignatureFields) { cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(new Phrase("________________________________________", aspectsFont)); cell.addElement( new Phrase(translate("Date, Signature") + " (" + att.getName() + ")", aspectsFont)); } tableAttendee.addCell(cell); /* * role of the attendee */ cell = new PdfPCell(new Phrase(translate(att.getRole().toString()), roleFont)); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingTop(padding * 1.1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableAttendee.addCell(cell); cellAttendee.addElement(tableAttendee); cellAttendee.setPadding(0); cellAttendee.setPaddingLeft(padding); cellAttendee.setPaddingRight(padding); if (grayBackground == true) { grayBackground = false; cellAttendee.setBackgroundColor(cellBackground); } else { grayBackground = true; } /* * Add attendee to the list */ tableAttendees.addCell(cellAttendee); } } PdfPCell cellBottomLine = new PdfPCell(); cellBottomLine.setPadding(0); cellBottomLine.setBorderWidth(0); cellBottomLine.setBorderWidthBottom(1); cellBottomLine.setBorderColor(cellBackground); tableAttendees.addCell(cellBottomLine); /* * Add the attendee base table to the document */ pdfDoc.add(tableAttendees); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put attendees into the PDF document.")); } }
From source file:org.revager.export.ProtocolPDFExporter.java
License:Open Source License
/** * Write the findings to the protocol.//from w w w. jav a 2s . c om * * @param protocol * the protocol * @param attachExtRefs * true if the external references should be part of the protocol * * @throws ExportException * If an error occurs while writing the findings to the protocol */ protected void writeFindings(Protocol protocol, boolean attachExtRefs) throws ExportException { try { /* * Define fonts */ Font plainFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9, Font.NORMAL, Color.WHITE); Font boldFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10, Font.NORMAL, Color.WHITE); Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldItalicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); /* * Write findings */ PdfPTable tableBase = new PdfPTable(1); tableBase.setWidthPercentage(100); tableBase.setSplitRows(false); tableBase.getDefaultCell().setBorderWidth(0); tableBase.getDefaultCell().setPadding(0); for (Finding f : protocol.getFindings()) { tableBase.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 1)); PdfPCell cellFinding = new PdfPCell(); cellFinding.setBorderColor(Color.GRAY); cellFinding.setBorderWidth(0.5f); PdfPTable tableTitle = new PdfPTable(3); tableTitle.setWidthPercentage(100); /* * Print title of the finding */ Phrase phraseTitle = new Phrase(translate("Finding") + " " + f.getId(), boldFontTitle); PdfPCell cellTitle = new PdfPCell(phraseTitle); cellTitle.setBackgroundColor(bgColorTitle); cellTitle.setBorderWidth(0); cellTitle.setPadding(padding); cellTitle.setPaddingBottom(padding * 1.5f); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); tableTitle.addCell(cellTitle); /* * Print severity of the finding */ Phrase phraseSeverity = new Phrase(findMgmt.getLocalizedSeverity(f), plainFontTitle); PdfPCell cellSeverity = new PdfPCell(phraseSeverity); cellSeverity.setBackgroundColor(bgColorTitle); cellSeverity.setBorderWidth(0); cellSeverity.setPadding(padding); cellSeverity.setPaddingTop(padding * 1.1f); cellSeverity.setHorizontalAlignment(Element.ALIGN_CENTER); tableTitle.addCell(cellSeverity); /* * Print the meeting date and time of the finding */ String meetingDate = sdfDate.format(protocol.getDate().getTime()); PdfPCell cellMeeting = new PdfPCell(new Phrase(meetingDate, plainFontTitle)); cellMeeting.setBackgroundColor(bgColorTitle); cellMeeting.setBorderWidth(0); cellMeeting.setPadding(padding); cellMeeting.setPaddingTop(padding * 1.1f); cellMeeting.setHorizontalAlignment(Element.ALIGN_RIGHT); tableTitle.addCell(cellMeeting); /* * Description */ Phrase phraseDesc = new Phrase(f.getDescription(), plainFont); phraseDesc.setLeading(leading); PdfPCell cellDesc = new PdfPCell(); cellDesc.addElement(phraseDesc); cellDesc.setBorderWidth(0); cellDesc.setPadding(padding); cellDesc.setColspan(3); tableTitle.addCell(cellDesc); cellFinding.addElement(tableTitle); /* * List point used for lists */ Phrase phraseListPoint = new Phrase("", boldFont); phraseListPoint.setLeading(leading * 0.93f); PdfPCell cellListPoint = new PdfPCell(); cellListPoint.addElement(phraseListPoint); cellListPoint.setBorderWidth(0); cellListPoint.setPadding(padding); cellListPoint.setPaddingLeft(padding * 2); /* * Table of references */ if (f.getReferences().size() > 0 || (f.getExternalReferences().size() > 0 && attachExtRefs == true)) { PdfPTable tableRefs = new PdfPTable(new float[] { 0.04f, 0.96f }); tableRefs.setWidthPercentage(100); PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("References:"), boldItalicFont)); cellRefTitle.setBorderWidth(0); cellRefTitle.setPadding(padding); cellRefTitle.setPaddingTop(padding * 3); cellRefTitle.setPaddingBottom(0); cellRefTitle.setColspan(2); tableRefs.addCell(cellRefTitle); /* * Textual references */ for (String ref : f.getReferences()) { Phrase phraseRef = new Phrase(ref, plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); tableRefs.addCell(cellListPoint); tableRefs.addCell(cellRef); } /* * External file references */ if (attachExtRefs == true) { for (File ref : findMgmt.getExtReferences(f)) { Phrase phraseRef = new Phrase(); phraseRef.add(new Chunk(ref.getName(), plainFont)); phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFont)); phraseRef.setFont(plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); tableRefs.addCell(cellListPoint); cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref)); tableRefs.addCell(cellRef); } } cellFinding.addElement(tableRefs); } /* * Table of aspects */ if (f.getAspects().size() > 0) { PdfPTable tableAspects = new PdfPTable(new float[] { 0.04f, 0.96f }); tableAspects.setWidthPercentage(100); PdfPCell cellAspTitle = new PdfPCell(new Phrase(translate("Aspects:"), boldItalicFont)); cellAspTitle.setBorderWidth(0); cellAspTitle.setPadding(padding); cellAspTitle.setPaddingTop(padding * 3); cellAspTitle.setPaddingBottom(0); cellAspTitle.setColspan(2); tableAspects.addCell(cellAspTitle); for (String asp : f.getAspects()) { Phrase phraseAsp = new Phrase(asp, plainFont); phraseAsp.setLeading(leading); PdfPCell cellAsp = new PdfPCell(); cellAsp.addElement(phraseAsp); cellAsp.setBorderWidth(0); cellAsp.setPadding(padding); tableAspects.addCell(cellListPoint); tableAspects.addCell(cellAsp); } cellFinding.addElement(tableAspects); } /* * Vertical strut at the end of the table */ PdfPTable tableStrut = new PdfPTable(1); tableStrut.setWidthPercentage(100); tableStrut.addCell(createVerticalStrut(padding, 1)); cellFinding.addElement(tableStrut); tableBase.addCell(cellFinding); } pdfDoc.add(tableBase); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put findings into the PDF document.")); } }
From source file:org.revager.export.ReviewProtocolPDFExporter.java
License:Open Source License
@Override protected void writeContent() throws ExportException { try {/* w ww . j a v a2s . c o m*/ /* * Write the title page of the protocol */ writeTitlePage(Application.getInstance().getMeetingMgmt().getMeetings(), attachProdExtRefs); /* * Write attendees of the whole review */ int numOfAtts = Application.getInstance().getAttendeeMgmt().getNumberOfAttendees(); if (showSignFields == true && numOfAtts > 0) { Font introFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); pdfDoc.newPage(); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); PdfPCell cellSignIntro = new PdfPCell(new Phrase( translate("The following persons participated in the whole review:"), introFont)); cellSignIntro.setBorderWidth(0); cellSignIntro.setPadding(padding); cellSignIntro.setPaddingBottom(PDFTools.cmToPt(0.8f)); table.addCell(cellSignIntro); pdfDoc.add(table); writeAttendees(null, false, false, true); } /* * Write the meetings of this review */ for (Meeting m : Application.getInstance().getMeetingMgmt().getMeetings()) { Protocol prot = m.getProtocol(); if (prot != null) { pdfDoc.newPage(); writeMeeting(m, attachFindExtRefs, false); } } } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot create PDF document.")); } }
From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java
License:Educational Community License
public void addTitlePage(String evaltitle, String groupNames, String startDate, String endDate, String responseInformation, byte[] bannerImageBytes, String evalSystemTitle, String informationTitle) { try {//from w ww. ja va2 s . com float pagefooter = paragraphFont.getSize(); PdfContentByte cb = pdfWriter.getDirectContent(); float docMiddle = (document.right() - document.left()) / 2 + document.leftMargin(); Paragraph emptyPara = new Paragraph(" "); emptyPara.setSpacingAfter(100.0f); // Title Paragraph titlePara = new Paragraph("\n\n\n" + evaltitle, frontTitleFont); titlePara.setAlignment(Element.ALIGN_CENTER); document.add(titlePara); // Groups Paragraph groupPara = new Paragraph(groupNames, frontAuthorFont); groupPara.setSpacingBefore(25.0f); groupPara.setAlignment(Element.ALIGN_CENTER); document.add(groupPara); // Little info area? I don't know, it was on the mockup though Paragraph infoPara = new Paragraph(informationTitle, frontInfoFont); infoPara.setAlignment(Element.ALIGN_CENTER); infoPara.setSpacingBefore(90.0f); document.add(infoPara); // Started on Paragraph startedPara = new Paragraph(startDate, frontInfoFont); startedPara.setAlignment(Element.ALIGN_CENTER); startedPara.setSpacingBefore(25.0f); document.add(startedPara); // Ended on Paragraph endedPara = new Paragraph(endDate, frontInfoFont); endedPara.setAlignment(Element.ALIGN_CENTER); endedPara.setSpacingBefore(25.0f); document.add(endedPara); // Reply Rate Paragraph replyRatePara = new Paragraph(responseInformation, frontInfoFont); replyRatePara.setAlignment(Element.ALIGN_CENTER); replyRatePara.setSpacingBefore(25.0f); document.add(replyRatePara); // Logo and Tagline cb.beginText(); cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, evalSystemTitle, docMiddle, document.bottom() + 20, 0); cb.endText(); if (bannerImageBytes != null) { Image banner = Image.getInstance(bannerImageBytes); cb.addImage(banner, banner.getWidth(), 0, 0, banner.getHeight(), docMiddle - (banner.getWidth() / 2), document.bottom() + 35); } document.newPage(); responseArea = new ColumnText(cb); responseArea.setSimpleColumn(document.left(), document.top(), document.right() / 2, document.bottom() + pagefooter); responseArea.go(); } catch (DocumentException | IOException de) { throw UniversalRuntimeException.accumulate(de, "Unable to create title page"); } }
From source file:org.vulpe.commons.util.Html2PdfUtil.java
License:Open Source License
public static void convert(InputStream input, OutputStream out) throws DocumentException { try {/*from w ww .j a v a2 s . co m*/ final Tidy tidy = new Tidy(); final Document doc = tidy.parseDOM(input, null); final ITextRenderer renderer = new ITextRenderer(); final File liberationSansRegular = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-Regular.ttf")); final File liberationSansBold = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-Bold.ttf")); final File liberationSansBoldItalic = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-BoldItalic.ttf")); final File liberationSansItalic = new File( getRealPath("/reports/fonts/liberation_sans/LiberationSans-Italic.ttf")); renderer.getFontResolver().addFont(liberationSansRegular.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.getFontResolver().addFont(liberationSansBold.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.getFontResolver().addFont(liberationSansBoldItalic.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); renderer.getFontResolver().addFont(liberationSansItalic.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // final BaseFont font = BaseFont.createFont(file.getAbsolutePath(), // BaseFont.IDENTITY_H, // BaseFont.NOT_EMBEDDED); // final String fontFamilyName = TrueTypeUtil.getFamilyName(font); renderer.setDocument(doc, null); renderer.layout(); renderer.createPDF(out); } catch (Exception e) { LOG.error(e.getMessage()); } }
From source file:papertoolkit.pattern.output.PDFPatternGenerator.java
License:BSD License
/** * @return the tahoma font from disk.//from w ww .ja va 2s. co m * TODO: What happened? It used to work... Where does BaseFont Look? */ private static BaseFont createBaseFontTahoma() { // TODO RON YEH xxxx DebugUtils.println(new File(".").getAbsolutePath()); try { return BaseFont.createFont(PaperToolkit.getDataFile("fonts/tahoma.ttf").getAbsolutePath(), BaseFont.CP1252, BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:pl.exsio.ca.app.report.terraincard.view.TerrainCardsView.java
License:Open Source License
private Font getFont() throws Exception { BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); Font f = new Font(bf, 10, Font.NORMAL); return f;// www. j a va 2s . c o m }
From source file:questions.compression.CompressionLevelsFonts.java
public static void createPdf(int compressionLevel) { try {/*from w w w .java2s .com*/ Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1])); writer.setCompressionLevel(compressionLevel); document.open(); BaseFont bf = BaseFont.createFont(RESOURCE, BaseFont.WINANSI, BaseFont.EMBEDDED); bf.setCompressionLevel(compressionLevel); Font f = new Font(bf, 12); document.add(new Paragraph("0123456789", f)); document.add(new Paragraph("abcdefghijklmnopqrstuvwxyz", f)); document.add(new Paragraph("ABCDEFGHIJKLMNOPQRSTUVWXYZ", f)); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.fonts.EncodingFont.java
public static void main(String[] args) { Document document = new Document(); try {/* ww w . j a v a 2 s. c o m*/ PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); String cp1252String, cp1250String, cp1253String; Font cp1252Font, cp1250Font, cp1253Font; document.add(new Paragraph("The importance of using the right encoding!")); document.add(new Paragraph("CORRECT:")); // CP1252 cp1252String = "CP1252: 'Un long dimanche de fian\u00e7ailles'"; cp1252Font = FontFactory.getFont("c:/windows/fonts/arial.ttf", "Cp1252", BaseFont.EMBEDDED, 12); document.add(new Paragraph(cp1252String, cp1252Font)); // CP1250 cp1250String = "CP1250: 'Nikogar\u0161nja zemlja'"; cp1250Font = FontFactory.getFont("c:/windows/fonts/arial.ttf", "Cp1250", BaseFont.EMBEDDED, 12); document.add(new Paragraph(cp1250String, cp1250Font)); // CP1253 cp1253String = "CP1253: '\u039D\u03cd\u03c6\u03b5\u03c2'"; cp1253Font = FontFactory.getFont("c:/windows/fonts/arial.ttf", "Cp1253", BaseFont.EMBEDDED, 12); document.add(new Paragraph(cp1253String, cp1253Font)); // The right String with the wrong encoding document.add(new Paragraph("POSSIBLY WRONG:")); document.add(new Paragraph(cp1252String + " (1250)", cp1250Font)); document.add(new Paragraph(cp1252String + " (1253)", cp1253Font)); document.add(new Paragraph(cp1250String + " (1252)", cp1252Font)); document.add(new Paragraph(cp1250String + " (1253)", cp1253Font)); document.add(new Paragraph(cp1253String + " (1252)", cp1252Font)); document.add(new Paragraph(cp1253String + " (1250)", cp1250Font)); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:questions.graphics2D.ArabicText.java
public static void main(String[] args) { Document document = new Document(PageSize.A4); try {// www . ja v a 2 s . c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); String text1 = "\u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631"; String text2 = "\u0634"; java.awt.Font font = new java.awt.Font("arial", 0, 12); PdfContentByte cb = writer.getDirectContent(); java.awt.Graphics2D g2Shapes = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight()); g2Shapes.setFont(font); g2Shapes.drawString("text1, expected to render RTL", 50, 100); g2Shapes.drawString(text1, 50, 120); g2Shapes.drawString("text2, expected to match right-most glyph above", 50, 140); g2Shapes.drawString(text2, 50, 160); g2Shapes.dispose(); ColumnText text = new ColumnText(cb); Font f = new Font( BaseFont.createFont("c://windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 12); text.setSimpleColumn(50, 620, 545, 50); text.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); text.setText(new Phrase(text1, f)); text.go(); text.setText(new Phrase(text2, f)); text.go(); FontMapper arialuni = new FontMapper() { public BaseFont awtToPdf(java.awt.Font font) { try { return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; } public java.awt.Font pdfToAwt(BaseFont font, int size) { return null; } }; java.awt.Graphics2D g = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight(), arialuni); g.setFont(null); g.drawString("text1, not expected to render RTL", 50, 180); g.drawString(text1, 50, 200); g.drawString("text2, not expected to match right-most glyph above", 50, 220); g.drawString(text2, 50, 240); g.drawString("to your right you see what it SHOULD look like:", 50, 260); g.drawString("If it doesn't, the problem is in the JDK, it's not an iText problem.", 50, 280); g.dispose(); document.close(); } catch (Exception de) { de.printStackTrace(); } }