List of usage examples for com.lowagie.text Document setPageSize
public boolean setPageSize(Rectangle pageSize)
From source file:com.kahlon.guard.controller.DocumentManager.java
/** * * @param document/*from w w w . ja v a2 s . c o m*/ */ public void preProcessPDF(Object document) { try { BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false); Document pdf = (Document) document; pdf.setPageSize(PageSize.A4); pdf.setMargins(5f, 5f, 10f, 5f); // headers and footers must be added before the document is opened HeaderFooter footer = new HeaderFooter(new Phrase("page: ", new Font(bf_courier)), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); pdf.setFooter(footer); // HeaderFooter header = new HeaderFooter( // new Phrase("This is a header without a page number", new Font(bf_courier)), false); // header.setAlignment(Element.ALIGN_CENTER); // pdf.setHeader(header); pdf.open(); String logoPath = "/resources/image/logo.png"; ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext(); String logo = servletContext.getRealPath(logoPath); pdf.add(Image.getInstance(logo)); Person person = context.getSelectedPerson().getDisplayPerson(); String name = FacesMessageUtil.getMessage("person.name") + " : " + person.getName(); String age = FacesMessageUtil.getMessage("person.age") + " : " + Integer.toString(person.getAge()); String gender = FacesMessageUtil.getMessage("person.gender") + " : " + person.getGender().getDescription(); String race = FacesMessageUtil.getMessage("person.ethnicity") + " : " + person.getEthnicity().getDescription(); Person rootPerson = person.getRootPerson(); PersonImage imgp = imageService.getLastestPersonImage(rootPerson.getId()); Image imgb = Image.getInstance(imgp.getContent()); imgb.scaleToFit(100, 120); PdfPTable headerTable = new PdfPTable(2); PdfPTable personTable = new PdfPTable(1); personTable.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase(name)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(age)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(gender)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); cell = new PdfPCell(new Phrase(race)); cell.setBorder(Rectangle.NO_BORDER); personTable.addCell(cell); BarcodePDF417 pdf417 = new BarcodePDF417(); pdf417.setText(Integer.toString(person.getId())); Image img = pdf417.getImage(); img.scalePercent(150, 60 * pdf417.getYHeight()); cell = new PdfPCell(img); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(15); personTable.addCell(cell); cell.addElement(personTable); headerTable.addCell(cell); cell = new PdfPCell(imgb); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(cell); headerTable.setSpacingAfter(15); pdf.add(headerTable); LineSeparator lineSeparator = new LineSeparator(); lineSeparator.setPercentage(82); pdf.add(lineSeparator); Paragraph space = new Paragraph(); space.add(""); space.setSpacingAfter(15); pdf.add(space); } catch (IOException e) { logger.log(Level.INFO, e.getMessage()); } catch (BadElementException e) { logger.log(Level.INFO, e.getMessage()); } catch (DocumentException e) { logger.log(Level.INFO, e.getMessage()); } catch (Exception e) { logger.log(Level.INFO, e.getMessage()); } }
From source file:com.krawler.esp.servlets.ExportMPXServlet.java
License:Open Source License
public void createPDFFile(Connection conn, HttpServletRequest request, HttpServletResponse response) throws ConfigurationException { String projid = request.getParameter("projectid"); try {// w ww .j a v a 2 s .c om String userid = AuthHandler.getUserid(request); String companyid = AuthHandler.getCompanyid(request); String tasks = projdb.getProjectTasks(conn, projid, userid, companyid, 0, -1, true); ByteArrayOutputStream os = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); document.setPageSize(PageSize.A4.rotate()); PdfWriter writer = PdfWriter.getInstance(document, os); setHeaderFooter(document, request.getParameter("header")); JSONObject jobj = new JSONObject(request.getParameter("options")); JSONArray jarr = jobj.getJSONArray("data"); ArrayList tabCols = new ArrayList(); ArrayList tabArr = createTables(jarr, tabCols, document);//new ArrayList(); writer.setPageEvent(new EndPage()); HashMap taskIdIndex = new HashMap(); JSONArray taskArr = new com.krawler.utils.json.base.JSONObject(tasks).getJSONArray("data"); for (int c = 0; c < taskArr.length(); c++) { com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c); taskIdIndex.put(temp.getString("taskid"), temp.getInt("taskindex")); } taskIdIndex.put("0", 0); for (int c = 0; c < taskArr.length(); c++) { com.krawler.utils.json.base.JSONObject temp = taskArr.getJSONObject(c); String pred = ""; if (!StringUtil.isNullOrEmpty(temp.getString("predecessor"))) { String[] p = temp.getString("predecessor").split(","); for (int i = 0; i < p.length; i++) { pred += taskIdIndex.get(p[i]).toString() + ","; } pred = pred.substring(0, (pred.length() - 1)); } String taskResourceNames = projdb.getTaskResourcesNames(conn, temp.getString("taskid"), projid); for (int i = 0; i < tabArr.size(); i++) { int lvl = 0; if (i == 0) { lvl = temp.getInt("level"); } String[] colArr = (String[]) tabCols.get(i); String[] values = getPDFCellOfRec(colArr, temp, pred, taskResourceNames); Font fnt = new Font(); if (temp.getBoolean("isparent")) { fnt.setStyle(Font.BOLD); } else { fnt.setStyle(Font.NORMAL); } addPdfRowToTable(values, (PdfPTable) tabArr.get(i), fnt, lvl); } } document.open(); getCompanyDetails(request); addComponyLogo(document); for (int i = 0; i < tabArr.size(); i++) { PdfPTable temp = (PdfPTable) tabArr.get(i); temp.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); document.add(temp); document.newPage(); } document.close(); os.close(); String fname = request.getParameter("filename"); os.close(); response.setHeader("Content-Disposition", "attachment; filename=\"" + fname + ".pdf\""); response.setContentType("application/octet-stream"); response.setContentLength(os.size()); response.getOutputStream().write(os.toByteArray()); response.getOutputStream().flush(); String type = "[PDF]"; AddToAuditTrail(conn, request, projid, type); conn.commit(); } catch (ServiceException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException e) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e); } catch (SessionExpiredException e) { Logger.getLogger(ExportMPXServlet.class.getName()).log(Level.SEVERE, null, e); } }
From source file:com.mirth.connect.connectors.doc.DocumentDispatcher.java
License:Open Source License
private void createRTF(InputStream inputStream, OutputStream outputStream, DocumentDispatcherProperties props) throws Exception { com.lowagie.text.Document document = null; try {/* w w w .java 2 s .c o m*/ document = new com.lowagie.text.Document(); //TODO verify the character encoding RtfWriter2.getInstance(document, outputStream); document.open(); try { double width = Double.parseDouble(props.getPageWidth()); double height = Double.parseDouble(props.getPageHeight()); Unit unit = props.getPageUnit(); /* * The version of iText being used only accepts points, so we need to convert to * twips first and then convert to points (1 point = 20 twips). */ if (unit != Unit.TWIPS) { width = unit.convertTo(width, Unit.TWIPS); height = unit.convertTo(height, Unit.TWIPS); unit = Unit.TWIPS; } width = Math.max(width, 1); height = Math.max(height, 1); document.setPageSize(new Rectangle((float) (Math.round(width) / RtfBasicElement.TWIPS_FACTOR), (float) (Math.round(height) / RtfBasicElement.TWIPS_FACTOR))); } catch (Exception e) { } HtmlParser parser = new HtmlParser(); parser.go(document, inputStream); } finally { if (document != null) { document.close(); } } }
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 ww w .j a v a 2s . c o m*/ 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.mycompany.devman.domain.Raport.java
public static void main(String[] args) { Document document = new Document(); // Tworzymy dokument //* Ustawianie rozmiarw dokumentu Rectangle rect = new Rectangle(PageSize.A4); //Tworzenie elementu - rozmiaru dokumentu, ktry bdzie kwadratem o rozmiarze 210mm x 297mm - format a4 // Utilities.millimetersToPoints(210), Utilities.millimetersToPoints(297) document.setPageSize(rect); Font[] fonts = { new Font(), new Font(Font.HELVETICA, 14, Font.NORMAL) }; try { //Blok Try jest po to poniewa nie zawsze moemy mie miejsce tam gdzie chcemy zapisa pdf PdfWriter.getInstance(document, new FileOutputStream("raport.pdf")); document.open(); //Otwarcie dokumentu - teraz moemy do niego wsadza co kolwiek chcemy Paragraph paragraph = new Paragraph(); paragraph.add("Raport"); document.add(paragraph); //dodanie paragrafu do dokumentu document.close();//from ww w .java2 s. c o m } catch (Exception e) { e.printStackTrace(); // Wywietli error } }
From source file:com.opst.adminBean.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();/* w w w . j a va 2 s .c om*/ pdf.setPageSize(PageSize.A4); String string = "CTP Leaderboard - " + adminBean.firstandlast + " Week: " + adminBean.week; Chunk ch = new Chunk(); pdf.add(new Chunk(string)); pdf.add(Chunk.NEWLINE); pdf.add(Chunk.NEWLINE); pdf.add(new Chunk(" ")); }
From source file:com.pfe.web.UtilisateurControler.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; pdf.open();// w ww . j a v a 2s . co m pdf.setPageSize(PageSize.A4); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images" + File.separator + "pdfs.png"; pdf.add(Image.getInstance(logo)); }
From source file:com.qcadoo.mes.workPlans.controller.WorkPlansController.java
License:Open Source License
private void printImageToPdf(final Entity attachment, HttpServletResponse response) { Document document = new Document(); try {//from ww w .j a v a 2 s . co m PdfWriter.getInstance(document, response.getOutputStream()); document.open(); document.setPageSize(PageSize.A4); pdfHelper.addMetaData(document); pdfHelper.addImage(document, attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT)); document.close(); } catch (Exception e) { LOG.error("Problem with printing document - " + e.getMessage()); document.close(); e.printStackTrace(); } }
From source file:com.safire.bean.Ingreso_recibosBean.java
public void preProcessPDF(Object document) { Document pdf = (Document) document; pdf.setPageSize(PageSize.A4.rotate()); pdf.open(); }
From source file:com.siacra.beans.ExporterBean.java
public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException { Document pdf = (Document) document; HeaderFooter header = new HeaderFooter(new Phrase(this.getTitle()), false); pdf.setHeader(header);// ww w.j ava 2 s. c o m HeaderFooter footer = new HeaderFooter(new Phrase("Pagina"), new Phrase("")); pdf.setFooter(footer); pdf.open(); pdf.setPageSize(PageSize.LETTER); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "img" + File.separator + "minerva.png"; pdf.add(Image.getInstance(logo)); }