List of usage examples for com.itextpdf.text FontFactory HELVETICA
String HELVETICA
To view the source code for com.itextpdf.text FontFactory HELVETICA.
Click Source Link
From source file:com.ephesoft.dcma.imagemagick.MultiPageExecutor.java
License:Open Source License
/** * The <code>addImageToPdf</code> method is used to add image to pdf and make it searchable by adding image text in invisible mode * w.r.t parameter 'isPdfSearchable' passed. * //from w w w . ja v a2s . c o m * @param pdfWriter {@link PdfWriter} writer of pdf in which image has to be added * @param htmlUrl {@link HocrPage} corresponding html file for fetching text and coordinates * @param imageUrl {@link String} url of image to be added in pdf * @param isPdfSearchable true for searchable pdf else otherwise * @param widthOfLine */ private void addImageToPdf(PdfWriter pdfWriter, HocrPage hocrPage, String imageUrl, boolean isPdfSearchable, final int widthOfLine) { if (null != pdfWriter && null != imageUrl && imageUrl.length() > 0) { try { LOGGER.info("Adding image" + imageUrl + " to pdf using iText"); Image pageImage = Image.getInstance(imageUrl); float dotsPerPointX = pageImage.getDpiX() / PDF_RESOLUTION; float dotsPerPointY = pageImage.getDpiY() / PDF_RESOLUTION; PdfContentByte pdfContentByte = pdfWriter.getDirectContent(); pageImage.scaleToFit(pageImage.getWidth() / dotsPerPointX, pageImage.getHeight() / dotsPerPointY); pageImage.setAbsolutePosition(0, 0); // Add image to pdf pdfWriter.getDirectContentUnder().addImage(pageImage); pdfWriter.getDirectContentUnder().add(pdfContentByte); // If pdf is to be made searchable if (isPdfSearchable) { LOGGER.info("Adding invisible text for image: " + imageUrl); float pageImagePixelHeight = pageImage.getHeight(); Font defaultFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD, CMYKColor.BLACK); // Fetch text and coordinates for image to be added Map<String, int[]> textCoordinatesMap = getTextWithCoordinatesMap(hocrPage, widthOfLine); Set<String> ketSet = textCoordinatesMap.keySet(); // Add text at specific location for (String key : ketSet) { int[] coordinates = textCoordinatesMap.get(key); float bboxWidthPt = (coordinates[2] - coordinates[0]) / dotsPerPointX; float bboxHeightPt = (coordinates[3] - coordinates[1]) / dotsPerPointY; pdfContentByte.beginText(); // To make text added as invisible pdfContentByte.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE); pdfContentByte.setLineWidth(Math.round(bboxWidthPt)); // Ceil is used so that minimum font of any text is 1 // For exception of unbalanced beginText() and endText() if (bboxHeightPt > 0.0) { pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), (float) Math.ceil(bboxHeightPt)); } else { pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), 1); } float xCoordinate = (float) (coordinates[0] / dotsPerPointX); float yCoordinate = (float) ((pageImagePixelHeight - coordinates[3]) / dotsPerPointY); pdfContentByte.moveText(xCoordinate, yCoordinate); pdfContentByte.showText(key); pdfContentByte.endText(); } } pdfContentByte.closePath(); } catch (BadElementException badElementException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + badElementException.toString()); } catch (DocumentException documentException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + documentException.toString()); } catch (MalformedURLException malformedURLException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + malformedURLException.toString()); } catch (IOException ioException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + ioException.toString()); } } }
From source file:com.myapp.struts.transaction.transactionAction.java
public ActionForward generatememberreport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException, Exception { if (Constants.isSessionActive(request)) { transactionForm transactionForm = (transactionForm) form; try {//ww w.jav a2 s . co m Date utilDate = new Date(); java.sql.Date date = new java.sql.Date(utilDate.getTime()); Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD, BaseColor.BLACK); Font bigFont_Uderline = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD | Font.UNDERLINE, BaseColor.BLACK); Font boldfont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 9, Font.BOLD); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); //Or whatever format fits best your needs. Paragraph para1 = new Paragraph("PALKE JEWELLERS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph("MEMBER ACCOUNT DETAILS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph(transactionForm.getSelectedmember(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph( transactionForm.getMemberaddress() + "\n" + transactionForm.getMembercontactno(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); Groups obj = (Groups) hmGroups.get(transactionForm.getGroupid() + ""); if (obj != null) { para1 = new Paragraph("Group : " + obj.getGroupname(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Paid Amount : " + transactionForm.getTotalpaidamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Prize Amount : " + transactionForm.getDrawamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Total Amount : " + transactionForm.getTotalamount(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Status : " + transactionForm.getStatus(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); if (transactionForm.getStatus().equalsIgnoreCase("Settled")) { para1 = new Paragraph(transactionForm.getSettlementcomment(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); } String dateStr = sdf.format(date); para1 = new Paragraph("DATED:" + dateStr, font); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); // add a couple of blank lines document.add(Chunk.NEWLINE); if (transactionForm.getLstPayment() != null && transactionForm.getLstPayment().size() > 0) { PdfPTable table2 = new PdfPTable(7); float[] columnWidths = { 1.5f, 1.5f, 3f, 4f, 4f, 7f, 2f }; table2.setWidthPercentage(100); table2.setWidths(columnWidths); para1 = new Paragraph("Sl No.", font); para1.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Term", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt No.", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt Date", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Payment Mode", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Remarks", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Paid Amount", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); int x = 1; double total = 0; //Iterator it = hmPayments.entrySet().iterator(); //while (it.hasNext()) { if (hmPayments.size() > 0) { for (int i = 1; i <= obj.getNoofinstallment(); i++) { //float f = columnWidths[i]; Payment f1 = (Payment) hmPayments.get(i + ""); //} //Map.Entry pairs = (Map.Entry) it.next(); //Payment f1 = (Payment) pairs.getValue(); String term = i + ""; para1 = new Paragraph(Integer.toString(x), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); x++; para1 = new Paragraph(term, font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentid() + "", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(sdf.format(f1.getPaiddate()), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentmode() == 1 ? "Cash" : "Cheque/NEFT", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getRemarks(), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); //para1 = new Paragraph(f1.getPaidamount() + "", boldfont); para1 = new Paragraph((int) obj.getInstallmentamount() + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); total = total + obj.getInstallmentamount(); if (hmPayments.size() == i) { break; } } para1 = new Paragraph("Total", boldfont); para1.setAlignment(Element.ALIGN_LEFT); cell = new PdfPCell(para1); cell.setColspan(6); table2.addCell(cell); //String numberStr = String.format("%.2f", total + ""); para1 = new Paragraph(total + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); //cell.setColspan(7); table2.addCell(cell); table2.setHorizontalAlignment(Element.ALIGN_LEFT); document.add(table2); } else { para1 = new Paragraph("NO PAYMENTS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } document.add(Chunk.NEWLINE); //document.close(); //fileInputStream = new FileInputStream(new File("C:\\reports\\PaymentReports.pdf")); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } } catch (DocumentException i) { System.out.println(i); return mapping.findForward("fail"); } catch (IOException i) { System.out.println(i); return mapping.findForward("fail"); } } else { return mapping.findForward("exp"); } }
From source file:com.vectorprint.report.itext.debug.DebugHelper.java
License:Open Source License
public static BaseFont debugFont(PdfContentByte canvas, EnhancedMap settings) { BaseFont bf = FontFactory.getFont(FontFactory.HELVETICA).getBaseFont(); canvas.setFontAndSize(bf, 8);//from www . j a v a 2 s . c o m canvas.setColorFill( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); canvas.setColorStroke( itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); return bf; }
From source file:com.vectorprint.report.itext.style.stylers.FieldFont.java
License:Open Source License
public FieldFont() { addParameter(new com.vectorprint.configuration.parameters.FloatParameter(SIZE_PARAM, "fontsize") .setDefault((float) com.itextpdf.text.Font.DEFAULTSIZE), FieldFont.class); addParameter(new ColorParameter(COLOR_PARAM, "#rgb").setDefault(Color.BLACK), FieldFont.class); addParameter(new StringParameter(FAMILY_PARAM, "alias for based on which a font is retrieved (preferred over style)") .setDefault(FontFactory.HELVETICA), FieldFont.class); addParameter(new FontStyleParameter(STYLE_PARAM, "style for a font" + Arrays.asList(Font.STYLE.values()).toString()).setDefault(Font.STYLE.normal), FieldFont.class); }
From source file:com.vectorprint.report.itext.style.stylers.Font.java
License:Open Source License
public Font() { super();/*w ww. j a v a 2 s .com*/ addParameter(new com.vectorprint.configuration.parameters.FloatParameter(SIZE_PARAM, "fontsize") .setDefault((float) com.itextpdf.text.Font.DEFAULTSIZE), Font.class); addParameter(new ColorParameter(COLOR_PARAM, "#rgb").setDefault(Color.BLACK), Font.class); addParameter( new FontStyleParameter(STYLE_PARAM, "style for a font" + Arrays.asList(STYLE.values()).toString()) .setDefault(STYLE.normal), Font.class); addParameter(new FontEncodingParameter(FONTENCODING, "encoding for a font" + Arrays.asList(ENCODING.values()).toString()).setDefault(ENCODING.WINANSI), Font.class); addParameter(new StringParameter(FAMILY_PARAM, "font family").setDefault(FontFactory.HELVETICA), Font.class); }
From source file:com.vectorprint.report.itext.style.stylers.Text.java
License:Open Source License
private void initParams() { addParameter(new IntParameter(SIZE_PARAM, "fontsize").setDefault(com.itextpdf.text.Font.DEFAULTSIZE), Text.class); addParameter(new ColorParameter(COLOR_PARAM, "#rgb").setDefault(Color.BLACK), Text.class); addParameter(new StringParameter(Font.FAMILY_PARAM, "string").setDefault(FontFactory.HELVETICA), Text.class); addParameter(new com.vectorprint.configuration.parameters.FloatParameter(ROTATE, "float"), Text.class); }
From source file:control.ReportHandler.java
public ReportHandler(EnrollmentRegister enR, PersonRegister peR, QuarantineRegister quR, UserRegister usR) { this.enR = enR; this.peR = peR; this.quR = quR; this.usR = usR; columnFont = FontFactory.getFont(FontFactory.HELVETICA, 12); columnFont.setColor(BaseColor.WHITE); }
From source file:controller.PDFGenerator.java
@Override public void GenerateDocument(Resolution doc) { String resId = "RES-IC-" + format(doc.getId()) + "-" + Calendar.getInstance().get(Calendar.YEAR); Document pdf = createDocument(resId + ".pdf"); if (pdf == null) return;/*from ww w . j av a2s.c o m*/ try { pdf.open(); Font boldFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); Font parFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Chunk chunk = new Chunk(doc.getTitle() + "\n\n", boldFont); Paragraph par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_CENTER); pdf.add(par); chunk = new Chunk(resId + "\n\n", boldFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_CENTER); pdf.add(par); chunk = new Chunk("Atencin: ", boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getAttention() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_LEFT); par.setIndentationLeft((float) 3.0); pdf.add(par); chunk = new Chunk(doc.getIntro() + "\n\n", parFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk((doc.isOneresult() == true ? "RESULTANDO NICO:\n" : "RESULTANDO:\n"), boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getResult() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk((doc.isOneconsideration() == true ? "CONSIDERANDO NICO:\n" : "CONSIDERANDOS:\n"), boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getConsider() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk("RESUELVO:\n", boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getResolve() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk("NOTIFIQUESE:\n", boldFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_LEFT); pdf.add(par); chunk = new Chunk(doc.getNotify(), parFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_LEFT); par.setIndentationLeft(250); pdf.add(par); pdf.close(); } catch (Exception ex) { System.out.println("Error writirn pdf."); } }
From source file:cz.zcu.kiv.eegdatabase.logic.pdf.PDFUtils.java
License:Apache License
public Paragraph setHeader(Document document, String title) throws IOException, BadElementException { Paragraph paragraph = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, BaseColor.BLACK)); paragraph.setAlignment(Element.ALIGN_CENTER); Image img = GetResizedAndCenteredImage(path + convertPath("/files/images/" + HEADERIMG)); float topMargin = img.getHeight() + 2 * PADDING[0]; img.setAbsolutePosition(PADDING[3], (PageSize.A4.getHeight() - img.getHeight()) - PADDING[0]); paragraph.add(img);//from w ww . java 2s.co m img = GetResizedAndCenteredImage(path + convertPath("/files/images/" + FOOTERIMG)); img.setAbsolutePosition((PageSize.A4.getWidth() - img.getWidth()) / 2, PADDING[2]); paragraph.add(img); float bottomMargin = img.getHeight() + 2 * PADDING[2]; document.setMargins(topMargin, PADDING[1], bottomMargin, PADDING[3]); paragraph.setSpacingAfter(1.5f * PADDING[0]); return paragraph; }
From source file:digilib.pdf.PDFTitlePage.java
License:Open Source License
/** * generate iText-PDF-Contents for the title page * // www . j a va 2s.co m * @return */ public Element getPageContents() { Paragraph content = new Paragraph(); content.setAlignment(Element.ALIGN_CENTER); // add vertical whitespace for (int i = 0; i < 8; i++) { content.add(Chunk.NEWLINE); } // add logo content.add(getLogo()); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); // add title Anchor title = new Anchor(new Paragraph(getTitle(), FontFactory.getFont(FontFactory.HELVETICA, 16))); String burl = job_info.getImageJobInformation().getAsString("base.url"); title.setReference(burl + "digilib.jsp?fn=" + job_info.getImageJobInformation().getAsString("fn")); content.add(title); content.add(Chunk.NEWLINE); // add author if (getDate() != " ") content.add(new Paragraph(getAuthor() + " (" + getDate() + ")", FontFactory.getFont(FontFactory.HELVETICA, 14))); else content.add(new Paragraph(getAuthor(), FontFactory.getFont(FontFactory.HELVETICA, 14))); content.add(Chunk.NEWLINE); // add page numbers content.add(new Paragraph(getPages(), FontFactory.getFont(FontFactory.HELVETICA, 12))); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); content.add(Chunk.NEWLINE); // add digilib version content.add(new Paragraph(getDigilibVersion(), FontFactory.getFont(FontFactory.HELVETICA, 10))); for (int i = 0; i < 8; i++) { content.add(Chunk.NEWLINE); } Anchor address = new Anchor( new Paragraph(burl + "digilib.jsp?fn=" + job_info.getImageJobInformation().getAsString("fn"), FontFactory.getFont(FontFactory.COURIER, 9))); address.setReference(burl + "digilib.jsp?fn=" + job_info.getImageJobInformation().getAsString("fn")); content.add(address); return content; }