List of usage examples for com.itextpdf.text Document setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
From source file:pdfcompressor.PDFCompressor.java
public void getFileSize() throws DocumentException, IOException { com.itextpdf.text.Image itextImg; Document outDocument = new Document(); outDocument.setMargins(0f, 0f, 0f, 0f); ByteArrayOutputStream memoryOutput = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(outDocument, memoryOutput); writer.setFullCompression();// w w w. ja v a2 s . com writer.open(); outDocument.open(); for (java.awt.Image img : getBuffedImg()) { itextImg = Image.getInstance(getImageByteArray(img, compressRate)); itextImg.scaleToFit(595f, 842f); outDocument.add(itextImg); } outDocument.close(); writer.close(); for (ProgressListener listener : sizeEstimateListener) { listener.finished(memoryOutput.toByteArray().length); } }
From source file:pdfcreator.PDFCreator.java
License:Open Source License
@SuppressWarnings("static-access") protected void createPdf(String filename, String[] images) throws Exception { Document doc = new Document(); PdfWriter writer;//from w ww . j av a 2s .co m if (pdfxConformance.equals("PDFA1A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1A); } else if (pdfxConformance.equals("PDFA1B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_1B); } else if (pdfxConformance.equals("PDFA2A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2A); } else if (pdfxConformance.equals("PDFA2B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_2B); } else if (pdfxConformance.equals("PDFA3A")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3A); } else if (pdfxConformance.equals("PDFA3B")) { writer = PdfAWriter.getInstance(doc, new FileOutputStream(filename), PdfAConformanceLevel.PDF_A_3B); } else { writer = PdfWriter.getInstance(doc, new FileOutputStream(filename)); } if (pdfVersion.equals("1.4")) { writer.setPdfVersion(PdfWriter.VERSION_1_4); } else if (pdfVersion.equals("1.5")) { writer.setPdfVersion(PdfWriter.VERSION_1_5); } else if (pdfVersion.equals("1.6")) { writer.setPdfVersion(PdfWriter.VERSION_1_6); } else if (pdfVersion.equals("1.7")) { writer.setPdfVersion(PdfWriter.VERSION_1_7); } else { writer.setPdfVersion(PdfWriter.VERSION_1_4); } verbose(filename + ": open"); doc.addCreationDate(); doc.addCreator(creator); if (title != null) { doc.addTitle(title); } for (int i = 0; i < images.length; i++) { verbose(" +" + images[i]); Image img = Image.getInstance(images[i]); doc.setPageSize(new Rectangle(img.getWidth(), img.getHeight())); doc.setMargins(0, 0, 0, 0); if (doc.isOpen()) { doc.newPage(); } else { doc.open(); } doc.add(img); doc.newPage(); } ICC_Profile icc = getImageColorProfile(images[0]); if (icc == null) { System.err.println("warning: no color profile available in " + images[0] + " using " + profileName); icc = getDefaultColorProfile(); } writer.setOutputIntents("Custom", "", null, null, icc); writer.createXmpMetadata(); doc.close(); verbose(filename + ": close"); }
From source file:pdfpruefbericht.PdfPruefbericht.java
License:Open Source License
public static void main(String[] args) throws IOException, DocumentException, SAXException, ParserConfigurationException, URISyntaxException { String RESULT = args[1];//from w w w .ja va2s. c o m String RESOURCE = args[0]; ContentParser cp; float compression; try { compression = Float.parseFloat(args[2]); } catch (NumberFormatException e) { System.out.println("Kompresion konnte nicht geparsed werden ... : " + e.getMessage()); compression = 0.5f; } try { Document document = new Document(PageSize.A4); document.setMargins(36, 72, 36, 144); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setTagged(); document.open(); PdfStructureTreeRoot root = writer.getStructureTreeRoot(); root.mapRole(new PdfName("Report"), PdfName.ROOT); root.mapRole(new PdfName("Norm"), PdfName.SECT); root.mapRole(new PdfName("Test"), PdfName.SEPARATION); root.mapRole(new PdfName("Comment"), PdfName.CO); root.mapRole(new PdfName("img"), PdfName.PI); root.mapRole(new PdfName("log"), PdfName.L); root.mapRole(new PdfName("Setup"), PdfName.SETTINGS); root.mapRole(new PdfName("device"), PdfName.D); root.mapRole(new PdfName("parameter"), PdfName.P); PdfStructureElement top = new PdfStructureElement(root, new PdfName("Report")); SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); List<PdfStructureElement> elements = new ArrayList<>(); cp = new ContentParser(document, writer, elements); parser.parse(new InputSource(new FileInputStream(RESOURCE)), new StructureParser(top, elements)); parser.parse(new InputSource(new FileInputStream(RESOURCE)), cp); PdfBuilder pdf = new PdfBuilder(document, writer, cp.getReport(), compression); pdf.build(); document.close(); } catch (IOException | DocumentException | SAXException | ParserConfigurationException e) { System.out.println(e.getMessage()); } //watermark watermark = new watermark(); }
From source file:privilege.mouchard.MouchardCtrl.java
@Override public void imprimerTraceurPdf() { try {/*from w w w .j ava 2s .c om*/ } catch (Exception e) { Personnel user = UtilitaireSession.getInstance().getuser(); if (user != null) { String fichier = "Liste_actionUtilisateur du " + new Date() + "_.pdf"; Document mouchard = new Document(); try { PdfWriter.getInstance(mouchard, new FileOutputStream(Utilitaires.path + "/" + fichier)); mouchard.setMargins(5, 5, 5, 5); mouchard.addCreator("School Manager"); mouchard.setPageSize(PageSize.A4); mouchard.open(); if (!getTraceurs().isEmpty()) { PdfPTable table = new PdfPTable(6); table.setComplete(true); table.addCell(PrintUtils.createPdfPCell("Liste des actions utilisateur", 6, detail)); table.addCell(new Paragraph("Nom")); table.addCell(PrintUtils.createPdfPCell("Prnom ", true)); table.addCell(PrintUtils.createPdfPCell("Action ", 3, true)); table.addCell(PrintUtils.createPdfPCell("Date", true)); for (int i = 0; i < getTraceurs().size(); i++) { } JsfUtil.addSuccessMessage("Liste cre avec succs !"); } mouchard.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(MouchardCtrl.class.getName()).log(Level.SEVERE, null, ex); } } else { JsfUtil.addWarningMessage("Aucune session utilisateur initie !"); } } }
From source file:py.com.palermo.imprimeetiquetas.web.ProductoController.java
public String createPdf() throws IOException, DocumentException { if (hayParaImprimir()) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("application/x-pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\""); // step 1 Document document = new Document(new Rectangle(86, 35)); // step 2 document.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // step 3 document.open();//from www . jav a 2 s . com // step 4 PdfContentByte cb = writer.getDirectContent(); for (ProductoCantidad p : productos) { if (p.getCantidad() > 0) { BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCode(p.getCodigo()); codeEAN.setCodeType(Barcode.EAN13); codeEAN.setBarHeight(10f); codeEAN.setX(0.7f); codeEAN.setSize(4f); NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("es", "py")); Font fontbold = FontFactory.getFont("Times-Roman", 5, Font.NORMAL); Chunk productTitle = new Chunk(p.getNombre() + "," + " " + nf.format(p.getPrecio()), fontbold); // EAN 13 Paragraph pTitile = new Paragraph(productTitle); pTitile.setAlignment(Element.ALIGN_CENTER); pTitile.setLeading(0, 1); PdfPTable table = new PdfPTable(1); table.setPaddingTop(0f); table.setWidthPercentage(96); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); cell.addElement(codeEAN.createImageWithBarcode(cb, null, BaseColor.BLACK)); table.addCell(cell); PdfPCell cell2 = new PdfPCell(); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBorder(Rectangle.NO_BORDER); cell2.addElement(pTitile); table.addCell(cell2); for (int i = 0; i < p.getCantidad(); 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:sc.emea.tools.image.Tiff2PDF.java
License:Apache License
public static void main(String args[]) { int page_counter = 0; try {/* w w w. j a v a2 s . c o m*/ // Read the Tiff File FileList myFileList = new FileList("C:\\DEV\\Eclipse-Workspace\\Luna-J\\Tiff2PdfConverter\\TIFF\\"); myFileList.setFilterPreMiddleSuffix("", "", ".tiff"); myFileList.sort(ComparableAttribute.dateLastModified, SortingDirection.asc); File[] myTiffFileFiles = myFileList.getFilesArray(); if (myTiffFileFiles.length < 1) return; else for (File file : myTiffFileFiles) System.out.println(file.getName()); Document myDocument = new Document(); myDocument.setMargins(0, 0, 0, 0); PdfWriter.getInstance(myDocument, new FileOutputStream("C:\\DEV\\Eclipse-Workspace\\Luna-J\\Tiff2PdfConverter\\PDF\\test.pdf")); myDocument.open(); RandomAccessSourceFactory rasFactory = new RandomAccessSourceFactory(); for (File file : myTiffFileFiles) { FileInputStream _fis = new FileInputStream(file.getAbsolutePath()); RandomAccessSource _ra_source = rasFactory.createSource(_fis); RandomAccessFileOrArray _ra_file = new RandomAccessFileOrArray(_ra_source); int numberOfPages = TiffImage.getNumberOfPages(_ra_file); for (int i = 1; i <= numberOfPages; i++) { Image _image = TiffImage.getTiffImage(_ra_file, i); _image.scaleAbsolute(myDocument.getPageSize()); myDocument.add(_image); page_counter++; } } myDocument.close(); System.out.println("Tiff to PDF conversion completed for " + page_counter); } catch (Exception i1) { i1.printStackTrace(); } }
From source file:se.inera.intyg.rehabstod.service.export.pdf.PdfExportServiceImpl.java
License:Open Source License
@Override public byte[] export(List<SjukfallEnhet> sjukfallList, PrintSjukfallRequest printSjukfallRequest, RehabstodUser user, int total) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {//from ww w. j a va 2 s . com unicodeCapableFont = new Font( BaseFont.createFont(UNICODE_CAPABLE_FONT_PATH, BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 9, Font.NORMAL); Document document = new Document(); document.setPageSize(PageSize.A4); document.setMargins(20, 20, 60, 20); PdfWriter writer = PdfWriter.getInstance(document, bos); // Add handlers for page events writer.setPageEvent(new HeaderEventHandler( Image.getInstance( IOUtils.toByteArray(resourcePatternResolver.getResource(LOGO_PATH).getInputStream())), user.getNamn(), user.getValdVardenhet().getNamn())); writer.setPageEvent(new PageNumberingEventHandler()); document.open(); // Add the front page with meta info document.add(createFrontPage(printSjukfallRequest, user, sjukfallList.size(), total)); // Switch to landscape mode document.setPageSize(PageSize.A4.rotate()); document.newPage(); // Add table with all sjukfall (could span several pages) document.add(createSjukfallTable(sjukfallList, user.getUrval(), printSjukfallRequest.isShowPatientId(), isSrsFeatureActive(user))); // Finish off by closing the document (will invoke the event handlers) document.close(); } catch (DocumentException | IOException | RuntimeException e) { throw new PdfExportServiceException("Failed to create PDF export!", e); } return bos.toByteArray(); }
From source file:Servlets.ReportsServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . ja v a 2 s.c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Paragraph pp; Paragraph palaglapgh, signParagraph, dateParagrapgh; Chunk chk; Paragraph underText; Chunk chuk1; Chunk chuk2; Paragraph regionText; String x; ResultSet dir; Paragraph regionTexts; String repLot; repLot = request.getParameter("report"); String repNum = request.getParameter("ITLot"); Paragraph newDate; response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); //Create document for pdf Document doc = new Document(); //PDF writer to write into document PdfWriter docwriter = null; DecimalFormat df = new DecimalFormat("0.00"); switch (repLot) { default: break; case "IT Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(20f, 20f, 10f, 10f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .25f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "TR Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); //doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); // 0.1 thickness and -2 position chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFdemos(repNum); try { if (dir.next()) { x = dir.getString(12); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum, repLot, .1f)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "RP Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(30f, 30f, 20f, 20f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", forTitle2); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum.toUpperCase(), forTitle2); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFreplants(repNum); try { if (dir.next()) { x = dir.getString(22); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(RPreport(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); break; case "Rehab Report": //Copied code start from here try { // //file path //String path = "docs/" + "Name"; docwriter = PdfWriter.getInstance(doc, out); } catch (DocumentException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } //document header attributes doc.addAuthor("CHED CU"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Grant Monitor"); doc.addTitle(repLot); doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape //doc.setPageSize(PageSize.A4); doc.setMargins(5f, 5f, 3f, 3f); //open document doc.open(); //Creating a paragraphs and chunks pp = new Paragraph("Cocoa Health And Extension Division", forTitle); pp.setAlignment(Element.ALIGN_CENTER); palaglapgh = new Paragraph("(Cocobod)", bfBold12); palaglapgh.setAlignment(Element.ALIGN_CENTER); signParagraph = new Paragraph("Sign: ..............", bfBold12); signParagraph.setAlignment(Element.ALIGN_LEFT); dateParagrapgh = new Paragraph("Date: ...........", bfBold12); chk = new Chunk("Component 1 Rehabilitation Tree Removal Cost From GIS Office, Accra", bfBold12); chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position underText = new Paragraph(chk); underText.setAlignment(Element.ALIGN_CENTER); chuk1 = new Chunk("RP Lot No:", bfBold12); chuk1.setUnderline(.1f, -2f); chuk2 = new Chunk(repNum, bfBold12); regionText = new Paragraph(repLot, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); x = ""; dir = manager.PDFRehab(repNum);//SHOULD BE CHANGED!!!! try { if (dir.next()) { x = dir.getString(21); } } catch (SQLException ex) { Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex); } regionTexts = new Paragraph(x, forTitle2); regionText.setAlignment(Element.ALIGN_CENTER); //add the PDF table to the paragraph //palaglapgh.add(table); //Table Generation block regionText.add(reports(repNum)); //SECTION TO ADD ELEMENTS TO PDF // add the paragraph to the document doc.add(pp); //doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(palaglapgh); doc.add(underText); doc.add(chuk1); doc.add(chuk2); //Current Date and time insertion newDate = new Paragraph(date, bf12); newDate.setAlignment(Element.ALIGN_RIGHT); doc.add(newDate); doc.add(regionTexts); doc.add(regionText); doc.add(Chunk.NEWLINE); //Adds a new blank line doc.add(Chunk.NEWLINE); doc.add(signParagraph); doc.add(dateParagrapgh); //close the document doc.close(); //close the writer docwriter.close(); out.close(); //Copied CODES break; } } catch (DocumentException ex) { Logger.getLogger(ReportsServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:sipl.recursos.GenerarPDFGrafica.java
public void generarPDF(String titulo, String imagen, Usuario usu, String dir, String Fecha1, String Fecha2, String Rango, String Filex) throws BadElementException, IOException { FILE = "";// w ww .ja v a 2 s .co m Titulo = ""; direc = ""; fecha1 = ""; fecha2 = ""; rango = ""; imgG = ""; imgG = imagen; fecha1 = Fecha1; fecha2 = Fecha2; rango = Rango; user = usu; direc += dir; Titulo = titulo; FILE = Filex; try { Document document = new Document(); FileOutputStream file = new FileOutputStream(dir + "PDF//" + FILE); PdfWriter.getInstance(document, file); document.open(); document.setMargins(10, 10, 10, 10); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (FileNotFoundException | DocumentException e) { } try { con.Close_DB(); } catch (SQLException e) { System.out.print("No cerr"); } }
From source file:sipl.recursos.GenerarPDFListar.java
public void generarPDF(String titulo, String imagen, Usuario usu, String dir, String Filex) throws BadElementException, IOException { FILE = "";//from w w w. ja v a 2s.c o m direc = ""; Titulo = ""; user = usu; direc += dir; Titulo = titulo; FILE = Filex; try { Document document = new Document(); FileOutputStream file = new FileOutputStream(dir + "PDF//" + FILE); PdfWriter.getInstance(document, file); document.open(); document.setMargins(10, 10, 10, 10); addMetaData(document); addTitlePage(document); addContent(document); document.close(); } catch (FileNotFoundException | DocumentException e) { } try { con.Close_DB(); } catch (SQLException e) { System.out.print("No cerr"); } }