List of usage examples for com.lowagie.text Utilities millimetersToPoints
public static final float millimetersToPoints(float value)
From source file:classroom.filmfestival_c.Movies25.java
public static void createTemplate() { // our template will be 35 x 50 mm Document document = new Document( new Rectangle(Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(50))); try {/* w w w . j a v a2 s .com*/ // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(TEMPLATE)); writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage); // step 3 document.open(); // step 4 // space reserved for the film poster PushbuttonField foto = new PushbuttonField(writer, new Rectangle(Utilities.millimetersToPoints(0), Utilities.millimetersToPoints(25), Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(50)), POSTER); foto.setBackgroundColor(Color.BLUE); writer.addAnnotation(foto.getField()); // space reserved for the text TextField tekst = new TextField(writer, new Rectangle(Utilities.millimetersToPoints(0), Utilities.millimetersToPoints(7), Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(25)), TEXT); tekst.setOptions(TextField.MULTILINE); writer.addAnnotation(tekst.getTextField()); // space reserved for the year TextField prijs = new TextField(writer, new Rectangle(Utilities.millimetersToPoints(0), Utilities.millimetersToPoints(0), Utilities.millimetersToPoints(35), Utilities.millimetersToPoints(7)), YEAR); prijs.setAlignment(Element.ALIGN_CENTER); prijs.setBackgroundColor(Color.BLUE); prijs.setTextColor(Color.WHITE); writer.addAnnotation(prijs.getTextField()); } catch (IOException ioe) { ioe.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } // step 5 document.close(); }
From source file:com.ideaspymes.proyecttemplate.stock.web.ProductoConsultaBean.java
public String createPdf() throws IOException, DocumentException { EtiquetaConf conf = etiquetaConfDAO.getEtiquetaConfDefault(); if (hayParaImprimir() && conf != null) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("application/x-pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\""); float ancho = Utilities.millimetersToPoints(conf.getAnchoHoja().floatValue()); System.out.println("Ancho: " + ancho); float largo = Utilities.millimetersToPoints(conf.getLargoHoja().floatValue()); System.out.println("Alto: " + largo); // step 1 Document document = new Document(new Rectangle(ancho, largo)); // step 2 document.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // step 3 document.open();/*from ww w . ja v a2s .c om*/ // step 4 PdfContentByte cb = writer.getDirectContent(); for (Producto p : getLista()) { if (p.getCantidadEtiquetas() > 0) { PdfPTable table = new PdfPTable(2); table.setWidthPercentage(96); Font fontbold = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); Chunk productTitle = new Chunk("HC", fontbold); Paragraph pTitile = new Paragraph(productTitle); pTitile.setAlignment(Element.ALIGN_LEFT); pTitile.setLeading(6, 0); PdfPCell cellTitle = new PdfPCell(); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); cellTitle.setVerticalAlignment(Element.ALIGN_TOP); cellTitle.setBorder(Rectangle.NO_BORDER); cellTitle.addElement(pTitile); Font font2 = FontFactory.getFont("Times-Roman", conf.getTamDescripcion().floatValue(), Font.NORMAL); Chunk productName = new Chunk(p.getNombre(), font2); Paragraph pName = new Paragraph(productName); pName.setAlignment(Element.ALIGN_CENTER); //pTitile.setLeading(0, 1); cellTitle.addElement(pName); table.addCell(cellTitle); Barcode39 code39 = new Barcode39(); code39.setCode(p.getCodigo()); //code39.setCodeType(Barcode.EAN13); code39.setBarHeight(conf.getAltoCodBarra().floatValue()); //codeEan.setX(0.7f); code39.setSize(conf.getTamDescripcion().floatValue()); //code39.setAltText("HC - " + p.getNombre()); PdfPCell cellBarcode = new PdfPCell(); cellBarcode.setHorizontalAlignment(Element.ALIGN_CENTER); cellBarcode.setBorder(Rectangle.NO_BORDER); cellBarcode.addElement(code39.createImageWithBarcode(cb, null, Color.BLACK)); table.addCell(cellBarcode); for (int i = 0; i < p.getCantidadEtiquetas(); i++) { document.add(table); document.newPage(); } } } // step 5 document.close(); response.getOutputStream().flush(); response.getOutputStream().close(); FacesContext.getCurrentInstance().responseComplete(); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No hay nada que imprimir", "")); } return null; }
From source file:de.cuseb.bilderbuch.pdf.PdfController.java
License:Open Source License
@RequestMapping(value = "/pdf", method = RequestMethod.GET) public void generatePdf(HttpSession session, HttpServletResponse httpServletResponse) { try {/* ww w .j a v a2 s .c o m*/ PdfRequest pdfRequest = (PdfRequest) session.getAttribute("pdfRequest"); httpServletResponse.setContentType("application/pdf"); Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, httpServletResponse.getOutputStream()); writer.setDefaultColorspace(PdfName.COLORSPACE, PdfName.DEFAULTRGB); //document.addAuthor(pdfRequest.getAuthor()); //document.addTitle(pdfRequest.getTitle()); document.setPageSize( new Rectangle(Utilities.millimetersToPoints(156), Utilities.millimetersToPoints(148))); document.open(); FontFactory.defaultEmbedding = true; FontFactory.register("IndieRock.ttf", "IndieRock"); Font font = FontFactory.getFont("IndieRock"); BaseFont baseFont = font.getBaseFont(); PdfContentByte cb = writer.getDirectContent(); Iterator<PdfPage> pages = pdfRequest.getPages().iterator(); while (pages.hasNext()) { PdfPage page = pages.next(); if (page.getImage() != null) { Image image = Image.getInstance(new URL(page.getImage().getUrl())); image.setDpi(300, 300); image.setAbsolutePosition(0f, 0f); image.scaleAbsolute(document.getPageSize().getWidth(), document.getPageSize().getHeight()); document.add(image); cb.saveState(); cb.beginText(); cb.setColorFill(Color.WHITE); cb.moveText(10f, 10f); cb.setFontAndSize(baseFont, 18); cb.showText(page.getSentence()); cb.endText(); cb.restoreState(); if (pages.hasNext()) { document.newPage(); } } } document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:questions.importpages.NameCard.java
public static void createOneCard() throws DocumentException, IOException { Rectangle rect = new Rectangle(Utilities.millimetersToPoints(86.5f), Utilities.millimetersToPoints(55)); Document document = new Document(rect); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(CARD)); writer.setViewerPreferences(PdfWriter.PrintScalingNone); document.open();//from w w w .j a v a 2 s. c om PdfReader reader = new PdfReader(LOGO); Image img = Image.getInstance(writer.getImportedPage(reader, 1)); img.scaleToFit(rect.getWidth() / 1.5f, rect.getHeight() / 1.5f); img.setAbsolutePosition((rect.getWidth() - img.getScaledWidth()) / 2, (rect.getHeight() - img.getScaledHeight()) / 2); document.add(img); document.newPage(); BaseFont bf = BaseFont.createFont(FONT, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); Font font = new Font(bf, 12); font.setColor(new CMYKColor(1, 0.5f, 0, 0.467f)); ColumnText column = new ColumnText(writer.getDirectContent()); Paragraph p; p = new Paragraph("Bruno Lowagie\n1T3XT\nbruno@1t3xt.com", font); p.setAlignment(Element.ALIGN_CENTER); column.addElement(p); column.setSimpleColumn(0, 0, rect.getWidth(), rect.getHeight() * 0.75f); column.go(); document.close(); }