List of usage examples for com.itextpdf.text PageSize A4
Rectangle A4
To view the source code for com.itextpdf.text PageSize A4.
Click Source Link
From source file:app.logica.gestores.GestorPDF.java
License:Open Source License
/** * Mtodo para crear un PDF a partir de una pantalla. */*from w w w.j av a 2s.c o m*/ * @param pantallaAPDF * pantalla que se imprimir en PDF * @return PDF de una captura de la pantalla pasada */ private PDF generarPDF(Node pantallaAPDF) throws Exception { //Se imprime la pantalla en una imagen new Scene((Parent) pantallaAPDF); WritableImage image = pantallaAPDF.snapshot(new SnapshotParameters(), null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", baos); byte[] imageInByte = baos.toByteArray(); baos.flush(); baos.close(); //Se carga la imagen en un PDF Image imagen = Image.getInstance(imageInByte); Document document = new Document(); ByteArrayOutputStream pdfbaos = new ByteArrayOutputStream(); PdfWriter escritor = PdfWriter.getInstance(document, pdfbaos); document.open(); imagen.setAbsolutePosition(0, 0); imagen.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); document.add(imagen); document.close(); //Se obtiene el archivo PDF byte[] pdfBytes = pdfbaos.toByteArray(); pdfbaos.flush(); escritor.close(); pdfbaos.close(); //Se genera un objeto PDF return (PDF) new PDF().setArchivo(pdfBytes); }
From source file:app.logica.gestores.GestorPDF.java
License:Open Source License
/** * Mtodo para crear un PDF a partir de varias pantalla. */*from w w w .j a v a2 s . c o m*/ * @param pantallaAPDF * pantalla que se imprimir en PDF * @return PDF de una captura de la pantalla pasada */ private PDF generarPDF(ArrayList<Node> pantallasAPDF) throws Exception { Document document = new Document(); ByteArrayOutputStream pdfbaos = new ByteArrayOutputStream(); PdfWriter escritor = PdfWriter.getInstance(document, pdfbaos); document.open(); for (Node pantalla : pantallasAPDF) { new Scene((Parent) pantalla); WritableImage image = pantalla.snapshot(new SnapshotParameters(), null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", baos); byte[] imageInByte = baos.toByteArray(); baos.flush(); baos.close(); Image imagen = Image.getInstance(imageInByte); imagen.setAbsolutePosition(0, 0); imagen.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight()); document.add(imagen); document.newPage(); } document.close(); byte[] pdfBytes = pdfbaos.toByteArray(); pdfbaos.flush(); escritor.close(); pdfbaos.close(); return (PDF) new PDF().setArchivo(pdfBytes); }
From source file:architecture.ee.web.view.document.AbstractPdfView.java
License:Apache License
/** * Create a new document to hold the PDF contents. * <p>By default returns an A4 document, but the subclass can specify any * Document, possibly parameterized via bean properties defined on the View. * @return the newly created iText Document instance * @see com.lowagie.text.Document#Document(com.lowagie.text.Rectangle) *///from ww w . ja v a2 s . co m protected Document newDocument() { return new Document(PageSize.A4); }
From source file:automatedbillingsoftware.helper.HtmlToPdf.java
public void createPdf(String file, HashMap<String, Object> scopes) throws IOException, DocumentException { // step 1//from ww w .j av a2 s . c o m Document document = new Document(PageSize.A4); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); writer.setTagged(); // step 3 document.open(); // step 4 // String readHtml = readHtml(HTML); System.out.println("challan" + DEST.contains("Challan-")); String readHtml = DEST.contains("Challan-") ? getDefaultTempProperties().getProperty("challan") : getDefaultTempProperties().getProperty("invoice"); System.out.println("readHtml=>" + readHtml); String testTemplate = getTestTemplate(readHtml, scopes); XMLWorkerHelper.getInstance().parseXHtml(writer, document, new StringReader(testTemplate)); // XMLWorkerHelper.getInstance().parseXHtml(writer, ); // step 5 document.close(); }
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private void createPdf(File file, List<Sponsor> sponsors) throws IOException, DocumentException { System.out.println("Generating PDF file " + file.getAbsolutePath()); Layout layout = new Layout(sponsors); System.out.println("Layout = " + layout); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.setPageSize(PageSize.A4.rotate()); document.setMargins(PADDING_DOC, PADDING_DOC, PADDING_DOC, PADDING_DOC); document.open();//from w w w .j a v a 2s .c o m PdfPTable table = new PdfPTable(layout.getColumnCount()); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); for (int i = 0; i < sponsors.size(); i++) { table.addCell(generateCell(sponsors.get(i), layout.getCellHeight())); } for (int i = 0; i < layout.getEmptyCellCount(); i++) { table.addCell(generateCell(new Sponsor(), layout.getCellHeight())); } document.add(table); document.close(); }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
public ByteArrayOutputStream generatePDFDocumentBytes(final HttpServletRequest req, ServletContext application, boolean filterApplied, int partsOfTransactionToPrint) throws DocumentException { ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = null;/*from w ww.j av a 2 s . c o m*/ this.req = req; this.application = application; sContextPath = req.getContextPath(); try { docWriter = PdfWriter.getInstance(doc, baosPDF); //*** META TAGS *********************************************************************** doc.addProducer(); doc.addAuthor(user.person.firstname + " " + user.person.lastname); doc.addCreationDate(); doc.addCreator("OpenClinic Software for Hospital Management"); doc.addTitle("Medical Record Data for " + patient.firstname + " " + patient.lastname); doc.addKeywords(patient.firstname + ", " + patient.lastname); doc.setPageSize(PageSize.A4); //*** FOOTER ************************************************************************** PDFFooter footer = new PDFFooter("OpenClinic pdf engine (c)2007, Post-Factum bvba\n" + MedwanQuery.getInstance().getLabel("web.occup", "medwan.common.patientrecord", sPrintLanguage) + " " + patient.getID("immatnew") + " " + patient.firstname + " " + patient.lastname); docWriter.setPageEvent(footer); doc.open(); //*** HEADER ************************************************************************** printDocumentHeader(req); //*** TITLE *************************************************************************** String title = getTran("Web.Occup", "medwan.common.occupational-health-record").toUpperCase(); // add date restriction to document title title += "\n(" + getTran("web", "printdate") + ": " + dateFormat.format(new Date()) + ")"; /* if(dateFrom!=null && dateTo!=null){ if(dateFrom.getTime() == dateTo.getTime()){ title+= "\n("+getTran("web","on")+" "+dateFormat.format(dateTo)+")"; } else{ title+= "\n("+getTran("pdf","date.from")+" "+dateFormat.format(dateFrom)+" "+getTran("pdf","date.to")+" "+dateFormat.format(dateTo)+")"; } } else if(dateFrom!=null){ title+= "\n("+getTran("web","since")+" "+dateFormat.format(dateFrom)+")"; } else if(dateTo!=null){ title+= "\n("+getTran("pdf","date.to")+" "+dateFormat.format(dateTo)+")"; }*/ Paragraph par = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par); //*** OTHER DOCUMENT ELEMENTS ********************************************************* printAdminHeader(patient); //printKeyData(sessionContainerWO); printMedication(sessionContainerWO); printActiveDiagnosis(sessionContainerWO); printWarnings(sessionContainerWO); doc.add(new Paragraph(" ")); //*** VACCINATION CARD **************************************************************** new be.mxs.common.util.pdf.general.oc.examinations.PDFVaccinationCard().printCard(doc, sessionContainerWO, transactionVO, patient, req, sProject, sPrintLanguage, new Integer(partsOfTransactionToPrint)); //*** TRANSACTIONS ******************************************************************** Enumeration e = req.getParameterNames(); String paramName, paramValue, sTranID, sServerID; boolean transactionIDsSpecified = false; while (e.hasMoreElements()) { paramName = (String) e.nextElement(); // transactionIDs were specified as request-parameters if (paramName.startsWith("tranAndServerID_")) { transactionIDsSpecified = true; paramValue = checkString(req.getParameter(paramName)); sTranID = paramValue.substring(0, paramValue.indexOf("_")); sServerID = paramValue.substring(paramValue.indexOf("_") + 1); this.transactionVO = MedwanQuery.getInstance().loadTransaction(Integer.parseInt(sServerID), Integer.parseInt(sTranID)); loadTransaction(transactionVO, 2); // 2 = print whole transaction } } if (!transactionIDsSpecified) { printTransactions(filterApplied, partsOfTransactionToPrint); } doc.add(new Paragraph(" ")); printSignature(); } catch (DocumentException dex) { baosPDF.reset(); throw dex; } catch (Exception e) { e.printStackTrace(); } finally { if (doc != null) doc.close(); if (docWriter != null) docWriter.close(); } if (baosPDF.size() < 1) { throw new DocumentException("document has " + baosPDF.size() + " bytes"); } return baosPDF; }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
public ByteArrayOutputStream generatePDFDocumentBytes(final HttpServletRequest req, ServletContext application) throws DocumentException { this.req = req; this.application = application; this.baosPDF = new ByteArrayOutputStream(); String sURL = req.getRequestURL().toString(); if (sURL.indexOf("openclinic", 10) > 0) { sURL = sURL.substring(0, sURL.indexOf("openclinic", 10)); }//from www.j av a 2 s . c o m if (sURL.indexOf("openinsurance", 10) > 0) { sURL = sURL.substring(0, sURL.indexOf("openinsurance", 10)); } String sContextPath = req.getContextPath() + "/"; HttpSession session = req.getSession(); String sProjectDir = (String) session.getAttribute("activeProjectDir"); // if request from Chuk, project = chuk if (sContextPath.indexOf("chuk") > -1) { sContextPath = "openclinic/"; sProjectDir = "projects/chuk/"; } this.url = sURL; this.contextPath = sContextPath; this.projectDir = sProjectDir; try { docWriter = PdfWriter.getInstance(doc, baosPDF); //*** META TAGS *********************************************************************** doc.addProducer(); doc.addAuthor(user.person.firstname + " " + user.person.lastname); doc.addCreationDate(); doc.addCreator("OpenClinic Software for Hospital Management"); doc.addTitle("Medical Record Data for " + patient.firstname + " " + patient.lastname); doc.addKeywords(patient.firstname + ", " + patient.lastname); doc.setPageSize(PageSize.A4); doc.open(); //*** HEADER ************************************************************************** printDocumentHeader(req); //*** TITLE *************************************************************************** String sTitle = getTran("web", "staffDossier").toUpperCase(); printDocumentTitle(req, sTitle); //*** SECTIONS ************************************************************************ /* - 1 : Administratie persoonlijk - 2 : Administratie priv - 3 : Human resources contracten - 4 : Human resources Competenties - 5 : Human resources carrire - 6 : Human resources disciplinair dossier - 7 : Human resources verlof en afwezigheden - 8 : Human resources salaris - 9 : Human resources uurrooster */ boolean[] sections = new boolean[17]; // which sections are chosen ? Enumeration parameters = req.getParameterNames(); Vector paramNames = new Vector(); String sParamName, sParamValue; // sort the parameternames while (parameters.hasMoreElements()) { sParamName = (String) parameters.nextElement(); if (sParamName.startsWith("section_")) { paramNames.add(new Integer(sParamName.substring("section_".length()))); } } Collections.sort(paramNames); // on number int sectionIdx = 0; for (int i = 0; i < paramNames.size(); i++) { sectionIdx = ((Integer) paramNames.get(i)).intValue() - 1; sections[sectionIdx] = checkString(req.getParameter("section_" + (sectionIdx + 1))) .equalsIgnoreCase("on"); Debug.println("Adding section[" + sectionIdx + "] to document : " + sections[sectionIdx]); } sectionIdx = 0; if (sections[sectionIdx++]) { printPatientCard(patient, sections[1]); // 0, showPhoto printAdminData(patient); } if (sections[sectionIdx++]) { //printPhoto(patient); // 1 } if (sections[sectionIdx++]) { printAdminPrivateData(patient); // 2 } if (sections[sectionIdx++]) { printHRContracts(sessionContainerWO, patient); // 3 } if (sections[sectionIdx++]) { printHRSkills(sessionContainerWO, patient); // 4 } if (sections[sectionIdx++]) { printHRCareer(sessionContainerWO, patient); // 5 } if (sections[sectionIdx++]) { printHRDisciplinaryRecord(sessionContainerWO, patient); // 6 } if (sections[sectionIdx++]) { printHRLeaves(sessionContainerWO, patient); // 8 } if (sections[sectionIdx++]) { printHRSalary(sessionContainerWO, patient); // 9 } if (sections[sectionIdx++]) { printHRWorkSchedules(sessionContainerWO, patient); // 10 } if (sections[sectionIdx++]) { printHRTraining(sessionContainerWO, patient); // 11 } if (sections[sectionIdx++]) { printSignature(); // 12 : not in jsp } } catch (DocumentException dex) { baosPDF.reset(); throw dex; } catch (Exception e) { e.printStackTrace(); } finally { if (doc != null) doc.close(); if (docWriter != null) docWriter.close(); } if (baosPDF.size() < 1) { throw new DocumentException("ERROR : The pdf-document has " + baosPDF.size() + " bytes"); } return baosPDF; }
From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java
License:Open Source License
protected void buildSheet() throws DocumentException { Rectangle pageSize = configuration.isLandscape(AbstractPoolSheetConfiguration.TITLE_PAGE) ? PageSize.A4.rotate() : PageSize.A4;/*from www . ja v a 2s .c o m*/ Document document = new Document(pageSize); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); document.addTitle(configuration.getTitle()); document.addCreator(CREATOR); buildTitle(document); buildTable(document); if (configuration.includeOrderOfBouts()) { if (configuration.putBoutOrderOnNewPage()) { pageSize = configuration.isLandscape(AbstractPoolSheetConfiguration.BOUT_ORDER_PAGE) ? PageSize.A4.rotate() : PageSize.A4; document.setPageSize(pageSize); document.newPage(); } buildBoutOrder(document); } document.close(); sheet = baos.toByteArray(); }
From source file:be.zenodotus.creatie.GeneratePDF.java
License:Open Source License
public String vakantieAfdruk(Context context, String name, int jaar) { this.context = context; PdfWriter w = null;/* www . j a v a2 s.c o m*/ Document d = new Document(PageSize.A4.rotate(), 5, 5, 10, 10); d.setPageCount(3); String fileName = name; String file = name; GregorianCalendar datum = new GregorianCalendar(); datum.set(GregorianCalendar.YEAR, jaar); String[] maanden = { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December" }; int[] dagen = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; VerlofDao dao = new VerlofDao(context); FeestdagDao feestdagDao = new FeestdagDao(context); WerkdagDao werkdagDao = new WerkdagDao(context); File folder = new File(context.getFilesDir(), "pdfs"); folder.mkdirs(); if (datum.isLeapYear(jaar)) { dagen[1] = 29; } File temp = null; temp = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Jacqueline" + jaar + ".pdf"); fileName = temp.toString(); try { dao.open(); ArrayList<Verlof> verloflijst = dao.getAlleVerlovenPerJaar(jaar); w = PdfWriter.getInstance(d, new FileOutputStream(temp)); d.open(); d.addAuthor("Jacqueline Vandenbroecke"); d.addCreationDate(); d.addCreator("Verlofplanner"); d.addTitle("Vakantie " + jaar + " van Jacqueline Vandenbroecke"); Font standaard = FontFactory.getFont(FontFactory.HELVETICA, 8); Font standaardBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD); Paragraph gegeven = new Paragraph("Jacqueline Vandenbroecke Verlof " + jaar + "\n", standaardBold); gegeven.setAlignment(Paragraph.ALIGN_CENTER); d.add(gegeven); for (int paginas = 0; paginas < 2; paginas++) { int aantal = 0; if (paginas == 1) { d.newPage(); aantal = 6; } PdfPTable table = new PdfPTable(6); for (int i = aantal; i < (aantal + 6); i++) { PdfPCell cell = new PdfPCell(new Paragraph(maanden[i], standaardBold)); cell.setBorder(1); table.addCell(cell); } int dag = 1; int k = aantal; for (int i = aantal; i < (aantal + 6); i++) { for (int j = 0; j < 32; j++) { if (k > ((aantal + 6) - 1)) { k = aantal; dag++; } if (dag > dagen[k]) { PdfPCell cell = new PdfPCell(new Paragraph("", standaard)); table.addCell(cell); k++; } else { SimpleDateFormat formatterDag = new SimpleDateFormat("dd"); SimpleDateFormat formatterWeek = new SimpleDateFormat("EEE"); datum.set(jaar, k, dag); PdfPTable dagTabel = new PdfPTable(4); PdfPCell cellDag = new PdfPCell( new Paragraph(formatterDag.format(datum.getTime()), standaard)); PdfPCell cellWeek = new PdfPCell( new Paragraph(formatterWeek.format(datum.getTime()), standaard)); ArrayList<Verlof> verlof = new ArrayList<Verlof>(); for (int z = 0; z < verloflijst.size(); z++) { if (((verloflijst.get(z).getDag() + 1) == dag) && (verloflijst.get(z).getMaand() == k)) { verlof.add(verloflijst.get(z)); } } feestdagDao.open(); Feestdag feestdag = feestdagDao.getFeestdag(jaar, datum.get(GregorianCalendar.MONTH), datum.get(GregorianCalendar.DATE)); feestdagDao.close(); werkdagDao.open(); java.util.List<Werkdag> weekend = werkdagDao.getWeekend(); werkdagDao.close(); String Verlof = ""; String uur = ""; if (verlof.size() > 0) { if (verlof.size() > 1) { Verlof = verlof.get(0).getVerlofsoort() + "\n" + verlof.get(1).getVerlofsoort(); uur = verlof.get(0).getUrental() + "\n" + verlof.get(1).getUrental(); } else { Verlof = verlof.get(0).getVerlofsoort(); uur = verlof.get(0).getUrental(); } } PdfPCell cellVerlof = new PdfPCell(new Paragraph(Verlof, standaard)); PdfPCell uren = new PdfPCell(new Paragraph(uur, standaard)); if (verlof.size() > 0) { BaseColor kleur = new BaseColor(Color.GRAY); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } for (int z = 0; z < weekend.size(); z++) { if ((formatterWeek.format(datum.getTime())).equals(weekend.get(z).getDag())) { BaseColor kleur = new BaseColor(Color.LTGRAY); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } } if (feestdag != null) { BaseColor kleur = new BaseColor(Color.GREEN); uren.setBackgroundColor(kleur); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } dagTabel.addCell(cellDag); dagTabel.addCell(cellWeek); dagTabel.addCell(cellVerlof); dagTabel.addCell(uren); table.addCell(dagTabel); k++; } } } d.add(table); dao.close(); } } catch (Exception ex) { ex.printStackTrace(); } finally { d.close(); w.close(); } return fileName; }
From source file:beans.ManagedBeanReportes.java
public void inventario() throws DocumentException, IOException { FacesContext facexcontext = FacesContext.getCurrentInstance(); ValueExpression vex = facexcontext.getApplication().getExpressionFactory() .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class); ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext()); FacesContext context = FacesContext.getCurrentInstance(); Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft, int marginRight, int marginTop, int marginBottom ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new ManagedBeanReportes.Watermark("")); if (!document.isOpen()) { document.open();/*w w w . j a va2s. c o m*/ } try { ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext(); //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png"); //Image welladigital = Image.getInstance(imageUrl1); //welladigital.setAbsolutePosition(377f, 760f); //welladigital.scalePercent(40); //document.add(welladigital); //crear tabla PARA NOMBRE DEL AO PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.setTotalWidth(450f); // table.setTotalWidth(540f); table.setLockedWidth(true); float[] headerWidths = { 120, 20, 310 }; table.setWidths(headerWidths); table.getDefaultCell(); SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY"); StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio)); Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12); underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location PdfPCell table5 = new PdfPCell(new Paragraph(underline)); table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER); table5.setColspan(3); table5.setBorder(Rectangle.NO_BORDER); table.addCell(table5); document.add(table); document.add(new Paragraph("\n", pequeFont)); PdfPCell table2 = new PdfPCell(); table2 = new PdfPCell( new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont)); table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER); table2.setColspan(3); table2.setBorder(Rectangle.NO_BORDER); table = new PdfPTable(3); table.setWidthPercentage(100); table.setTotalWidth(450f); table.setLockedWidth(true); table.setWidths(headerWidths); table.getDefaultCell(); table.addCell(table2); document.add(table); document.add(new Paragraph("\n", pequeFont)); document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda())); formato = new SimpleDateFormat("yyyy-MM-dd"); cadena = new StringBuilder(formato.format(fecha_inicio)); //document.add(traerSubtabla02(cadena.toString())); document.add(new Paragraph("\n", pequeFont)); ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext(); String ctxPath = ((ServletContext) ctx.getContext()).getContextPath(); document.close(); formato = new SimpleDateFormat("dd_MM_yyyy"); cadena = new StringBuilder(formato.format(fecha_inicio)); String fileName = cadena.toString(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception de) { de.printStackTrace(); } }