List of usage examples for com.lowagie.text.pdf PdfWriter getInstance
public static PdfWriter getInstance(Document document, OutputStream os) throws DocumentException
PdfWriter
. From source file:gestioninscription.FenSessions.java
private void btnFeuilleMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnFeuilleMouseClicked String req;/*from www . j a v a2 s . com*/ req = "select numero, libelleform, niveauform, datedebut, nb_places, nb_inscrits, c.matricule, nom, typestatut, rue, cp, ville "; req += "from session_form s, inscription i, client c where s.numero = i.num_session and i.matricule = c.matricule and s.numero =" + tableSession.getValueAt(tableSession.getSelectedRow(), 0); stmt1 = GestionBdd.connexionBdd(GestionBdd.TYPE_MYSQL, "formarmor", "localhost", "root", ""); ResultSet rs2 = GestionBdd.envoiRequeteLMD(stmt1, req); Document document = new Document(PageSize.A4); System.out.println(req); try { // etape 2: // creation du writer -> PDF ou HTML PdfWriter.getInstance(document, new FileOutputStream(out)); // etape 3: Ouverture du document document.open(); // etape 4: Ajout du contenu au document document.add(new Phrase("texte dans le pdf")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // etape 5: Fermeture du document document.close(); System.out.println("Document '" + out + "' generated"); }
From source file:gov.medicaid.services.impl.ExportServiceBean.java
License:Apache License
/** * Exports the search results into PDF./* w w w .j av a 2s . c om*/ * * @param requests * the list to be exported * @param status * the status filter * @param outputStream * the stream to export to * @throws PortalServiceException * for any errors encountered */ public void export(List<UserRequest> requests, String status, OutputStream outputStream) throws PortalServiceException { PdfPTable resultTable; try { Document document = new Document(); PdfWriter.getInstance(document, outputStream); document.open(); resultTable = new PdfPTable(new float[] { 3, 8, 8, 8, 10, 25, 8, 8, 8 }); resultTable.getDefaultCell().setBorder(0); resultTable.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER); resultTable.setTotalWidth(72 * 7); resultTable.setLockedWidth(true); resultTable.addCell(createHeaderCell("Enrollments", 9)); resultTable.completeRow(); addCenterCell(resultTable, "#"); addCenterCell(resultTable, "NPI/UMPI"); addCenterCell(resultTable, "Date Created"); addCenterCell(resultTable, "Request Type"); addCenterCell(resultTable, "Provider Type"); addCenterCell(resultTable, "Provider Name"); addCenterCell(resultTable, "Risk Level"); addCenterCell(resultTable, "Status"); addCenterCell(resultTable, "Status Date"); resultTable.completeRow(); int i = 0; for (UserRequest userRequest : requests) { addCenterCell(resultTable, String.valueOf(++i)); addCenterCell(resultTable, userRequest.getNpi()); addCenterCell(resultTable, BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getCreateDate()))); addCenterCell(resultTable, userRequest.getRequestType()); addCenterCell(resultTable, userRequest.getProviderType()); addCenterCell(resultTable, userRequest.getProviderName()); addCenterCell(resultTable, userRequest.getRiskLevel()); addCenterCell(resultTable, userRequest.getStatus()); addCenterCell(resultTable, BinderUtils.formatCalendar(BinderUtils.toCalendar(userRequest.getStatusDate()))); } resultTable.setSpacingAfter(20); document.add(resultTable); document.close(); } catch (DocumentException e) { throw new PortalServiceException("Export failed, see log for additional details.", e); } }
From source file:gov.medicaid.services.impl.ExportServiceBean.java
License:Apache License
/** * Exports the profile into PDF.//www . j ava 2 s . c om * * @param currentUser * the current user * @param enrollment * the enrollment model * @param model * the view model * @param outputStream * the stream to export to * @throws IOException * for read/write errors * @throws PortalServiceException * for any other errors encountered */ public void export(CMSUser currentUser, EnrollmentType enrollment, Map<String, Object> model, OutputStream outputStream) throws PortalServiceException, IOException { try { Document document = new Document(); PdfWriter.getInstance(document, outputStream); document.open(); renderTicket(enrollment, document, model); document.close(); } catch (DocumentException e) { throw new PortalServiceException("Export failed, see log for additional details.", e); } }
From source file:gov.noaa.pfel.coastwatch.sgt.SgtUtil.java
License:Open Source License
/** * This creates a file to capture the pdf output generated by calls to * graphics2D (e.g., use makeMap)./*from w w w .j a v a2s .c o m*/ * This will overwrite an existing file. * * @param pageSize e.g, PageSize.LETTER or PageSize.LETTER.rotate() (or A4, or, ...) * @param width the bounding box width, in 1/144ths of an inch * @param height the bounding box height, in 1/144ths of an inch * @param outputStream * @return an object[] with 0=g2D, 1=document, 2=pdfContentByte, 3=pdfTemplate * @throws Exception if trouble */ public static Object[] createPdf(com.lowagie.text.Rectangle pageSize, int bbWidth, int bbHeight, OutputStream outputStream) throws Exception { //currently, this uses itext //see the sample program: // file://localhost/C:/programs/iText/examples/com/lowagie/examples/directcontent/graphics2D/G2D.java //Document.compress = false; //for test purposes only Document document = new Document(pageSize); document.addCreationDate(); document.addCreator("gov.noaa.pfel.coastwatch.SgtUtil.createPdf"); document.setPageSize(pageSize); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); //create contentByte and template and Graphics2D objects PdfContentByte pdfContentByte = writer.getDirectContent(); PdfTemplate pdfTemplate = pdfContentByte.createTemplate(bbWidth, bbHeight); Graphics2D g2D = pdfTemplate.createGraphics(bbWidth, bbHeight); return new Object[] { g2D, document, pdfContentByte, pdfTemplate }; }
From source file:gov.utah.dts.det.ccl.documents.templating.templates.AbstractCaseloadTemplate.java
@Override public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor descriptor) throws TemplateException { Long specialistId = (Long) context.get("specId"); if (specialistId == null) { throw new TemplateException("Specialist id is required."); }/*from w w w . j a va2s . co m*/ CaseloadSortBy sortBy = CaseloadSortBy.getDefaultSortBy(); String sortByStr = (String) context.get("sortBy"); if (sortByStr != null) { sortBy = CaseloadSortBy.valueOf(sortByStr); } Person specialist = personService.getPerson(specialistId); context.put(SPECIALIST_KEY, specialist); List<FacilityCaseloadView> caseload = getCaseload(specialistId, sortBy); setFileName(context, descriptor); try { Document document = new Document(PageSize.LETTER.rotate(), MARGIN, MARGIN, MARGIN, MARGIN); PdfWriter.getInstance(document, outputStream); document.open(); document.add(new Paragraph(getReportTitle() + " for " + specialist.getFirstAndLastName(), FONT)); //columns: name, facility id, address, phone, 1st director(s), status, type, capacity (<2) PdfPTable table = new PdfPTable(8); table.setWidths(new float[] { 23f, 25f, 11f, 13f, 5f, 9f, 7f, 7f }); table.setWidthPercentage(100); table.setSpacingBefore(FONT_SIZE); table.getDefaultCell().setPadding(TABLE_CELL_PADDING); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setBorderWidthBottom(.5f); table.setHeaderRows(1); table.addCell(new Phrase("Facility Name", HEADER_FONT)); table.addCell(new Phrase("Address", HEADER_FONT)); table.addCell(new Phrase("Phone", HEADER_FONT)); table.addCell(new Phrase("1st Director(s)", HEADER_FONT)); table.addCell(new Phrase("Type", HEADER_FONT)); table.addCell(new Phrase("Exp Dt", HEADER_FONT)); table.addCell(new Phrase("Adult Cap", HEADER_FONT)); table.addCell(new Phrase("Youth Cap", HEADER_FONT)); boolean hasInProcess = false; for (FacilityCaseloadView fcv : caseload) { if (fcv.getStatus() == FacilityStatus.REGULATED || fcv.getStatus() == FacilityStatus.IN_PROCESS) { StringBuilder name = new StringBuilder(); if (fcv.getStatus() == FacilityStatus.IN_PROCESS) { hasInProcess = true; name.append("* "); } name.append(fcv.getName()); table.addCell(new Phrase(name.toString(), FONT)); table.addCell(new Phrase(fcv.getLocationAddress().toString(), FONT)); table.addCell(new Phrase(fcv.getPrimaryPhone().getFormattedPhoneNumber(), FONT)); table.addCell(new Phrase(fcv.getDirectorNames(), FONT)); String typeAbbrev = null; /* if (fcv.getLicenseType() != null) { typeAbbrev = applicationService.getApplicationPropertyValue("facility.license.type." + fcv.getLicenseType().getId()+ ".abbrev"); } */ table.addCell(new Phrase(typeAbbrev != null ? typeAbbrev : "", FONT)); // table.addCell(new Phrase(fcv.getExpirationDate() != null ? DATE_FORMATTER.format(fcv.getExpirationDate()) : "", FONT)); table.addCell(new Phrase("", FONT)); // if (fcv.getAdultTotalSlots() == null) { table.addCell(new Phrase("")); // } else { // table.addCell(new Phrase(fcv.getAdultTotalSlots().toString(), FONT)); // } // if (fcv.getYouthTotalSlots() == null) { table.addCell(new Phrase("")); // } else { // table.addCell(new Phrase(fcv.getYouthTotalSlots().toString(), FONT)); // } } } document.add(table); if (hasInProcess) { document.add(new Paragraph( "* - Facility is in the process of becoming a regulated child care facility.", FONT)); } document.close(); } catch (DocumentException de) { throw new TemplateException(de); } }
From source file:gui.TransHistory.java
public void Convertpdf() throws Exception { display();/*from ww w. j a va 2 s . co m*/ Document document = new Document(PageSize.A4.rotate()); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Table.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); Graphics2D g2 = cb.createGraphics(500, 500); Shape oldClip = g2.getClip(); g2.clipRect(20, 20, 500, 500); jTable1.print(g2); jTable1.getTableHeader().paint(g2); g2.setClip(oldClip); g2.dispose(); cb.restoreState(); cb.saveState(); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); //send mail query = "select email from profile_id where user_id = ?"; psmt = con.prepareStatement(query); psmt.setString(1, t.user); rs = psmt.executeQuery(); rs.next(); SendMailWithAttachment smail = new SendMailWithAttachment(); String message = "hereby is the requested transction report of account " + "no. = " + t.accNo + " from date " + fDate + " to " + toDate; smail.send(rs.getString(1), "Table.pdf", message); }
From source file:ilarkesto.integration.itext.PdfBuilder.java
License:Open Source License
public void write(OutputStream out) { Document document = new Document(); try {/*from ww w . j a v a 2 s . c o m*/ PdfWriter.getInstance(document, out); } catch (DocumentException ex) { throw new RuntimeException(ex); } document.setMargins(mmToPoints(marginLeft), mmToPoints(marginRight), mmToPoints(marginTop), mmToPoints(marginBottom)); document.open(); for (ItextElement element : elements) { try { if (element instanceof PageBreak) { document.newPage(); } else { Element iTextElement = element.getITextElement(); if (iTextElement != null) document.add(iTextElement); } } catch (DocumentException ex) { throw new RuntimeException(ex); } } document.close(); }
From source file:include.nseer_cookie.MakePdf.java
License:Open Source License
public void make(String database, String tablename, String sql1, String sql2, String filename, int everypage, HttpSession session) {// w ww . j ava2s . c o m try { nseer_db aaa = new nseer_db(database); nseer_db demo_db = new nseer_db(database); ServletContext context = session.getServletContext(); String path = context.getRealPath("/"); Masking reader = new Masking(configFile); Vector columnNames = new Vector(); Vector tables = reader.getTableNicks(); Iterator loop = tables.iterator(); while (loop.hasNext()) { String tablenick = (String) loop.next(); columnNames = reader.getColumnNames(tablenick); } int cpage = 1; //? int spage = 1; int ipage = everypage; String pagesql = sql1; //? ResultSet pagers = demo_db.executeQuery(pagesql); pagers.next(); int allCol = pagers.getInt("A"); allpage = (int) Math.ceil((allCol + ipage - 1) / ipage); // for (int m = 1; m <= allpage; m++) { spage = (m - 1) * ipage; String sql = sql2 + " limit " + spage + "," + ipage; ResultSet bbb = aaa.executeQuery(sql); //ResultSetMetaData tt=bbb.getMetaData(); // int b = columnNames.size(); // int a = 0; while (bbb.next()) { a++; } // bbb.first(); // ?? Rectangle rectPageSize = new Rectangle(PageSize.A4);// rectPageSize = rectPageSize.rotate(); Document document = new Document(rectPageSize, 20, 20, 20, 20); //? Document PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path + filename + m + ".pdf")); //?PDF?? document.open(); // BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); //? com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 8, com.lowagie.text.Font.NORMAL); // Paragraph title1 = new Paragraph("nseer ERP", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC)); Chapter chapter1 = new Chapter(title1, 1); // ? chapter1.setNumberDepth(0); Paragraph title11 = new Paragraph(tablename, FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD)); Section section1 = chapter1.addSection(title11); //? Table t = new Table(b, a); // ? t.setPadding(1); // t.setSpacing(0); // ? t.setBorderWidth(1); // do { // // for (int k = 0; k < b; k++) { // Cell cell = new Cell( new Paragraph(bbb.getString((String) columnNames.elementAt(k)), FontChinese)); //? // t.addCell(cell); // ? // } // } while (bbb.next()); // section1.add(t); // document.add(chapter1); // document.close(); } // ? } catch (Exception pp) { pp.printStackTrace(); } }
From source file:io.github.autsia.crowly.controllers.DashboardController.java
License:Apache License
@RequestMapping(value = "/campaigns/export/{campaignId}", method = RequestMethod.GET) public ResponseEntity<byte[]> export(@PathVariable("campaignId") String campaignId, ModelMap model) throws DocumentException { Document document = new Document(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); PdfWriter.getInstance(document, byteArrayOutputStream); document.open();/* w w w .ja va 2 s. c om*/ Gson gson = new Gson(); String json = gson.toJson(mentionRepository.findByCampaignId(campaignId)); document.add(new Paragraph(json)); document.close(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.parseMediaType("application/pdf")); String filename = "output.pdf"; headers.setContentDispositionFormData(filename, filename); headers.setCacheControl("must-revalidate, post-check=0, pre-check=0"); ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(), headers, HttpStatus.OK); return response; }
From source file:io.vertigo.dynamo.plugins.export.pdf.PDFExporter.java
License:Apache License
/** {@inheritDoc} */ @Override/*from w w w . j a v a 2 s .c o m*/ protected void createWriter(final Document document, final OutputStream out) throws DocumentException { final PdfWriter writer = PdfWriter.getInstance(document, out); // writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); // simple page numbers : x // HeaderFooter footer = new HeaderFooter(new Phrase(), true); // footer.setAlignment(Element.ALIGN_RIGHT); // footer.setBorder(Rectangle.TOP); // document.setFooter(footer); // add the event handler for advanced page numbers : x/y writer.setPageEvent(new PDFAdvancedPageNumberEvents()); }