List of usage examples for com.itextpdf.text Document newPage
public boolean newPage()
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * /* w ww . j a v a 2s . c o m*/ * PDF Title Page * * @param doc * @param writer */ public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload) throws Exception { Font fnTitle = new Font(bfKorean, 20, Font.BOLD); Font fnLabel = new Font(bfKorean, 11, Font.BOLD); Font fnText = new Font(bfKorean, 11); LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5); doc.newPage(); doc.add(Chunk.NEWLINE); event.setTitleFlag(true); int toc = writer.getPageNumber(); Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif")); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); img.scalePercent(80, 80); doc.add(img); Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle); titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); titlePh.setSpacingBefore(50); titlePh.setSpacingAfter(30); doc.add(titlePh); doc.add(UNDERLINE); PdfPTable t1 = new PdfPTable(2); t1.setSpacingBefore(20); t1.setWidths(new int[] { 110, 290 }); t1.getDefaultCell().setBorder(0); t1.getDefaultCell().setFixedHeight(32); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel)); t1.addCell(new Phrase(upload.getProjectNm(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel)); t1.addCell(new Phrase(upload.getDepartment(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(), upload.getAfterWas()), fnText)); doc.add(t1); doc.add(UNDERLINE); Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel); executedPh.setSpacingBefore(30); executedPh.setSpacingAfter(15); executedPh.setIndentationLeft(50); doc.add(executedPh); PdfPTable t2 = new PdfPTable(2); t2.getDefaultCell().setFixedHeight(28); t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel)); t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); t2.addCell(new Phrase(upload.getPerson(), fnText)); t2.addCell(new Phrase(upload.getOrgRole(), fnText)); doc.add(t2); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * ?//from www . j a v a 2 s .c o m * * @param doc * @param writer * @param event * @throws Exception */ public static void setChapterSectionTOC(Document doc, PdfWriter writer, PDFCommonEventHelper event) throws Exception { doc.newPage(); event.setPagingFlag(false); Paragraph title = new Paragraph(MessageUtil.getMessage("pdf.message.toc.title"), new Font(bfKorean, 13, Font.BOLD)); title.setSpacingAfter(8); doc.add(title); int toc = writer.getPageNumber(); for (Paragraph p : event.titles) doc.add(p); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.auskeny.ems.print.PdfCreator.java
public static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);// w ww . java2 s .c o m // Lets write a big header preface.add(new Paragraph("Title of the document", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:com.bdaum.zoom.email.internal.job.PdfJob.java
License:Open Source License
private void printPage(Document document, int pageNo, MultiStatus status, IProgressMonitor monitor) throws DocumentException, IOException { if (pageNo > 1) document.newPage(); document.setPageCount(pageNo);// w w w . j a v a2s .c om final Display display = Display.getDefault(); int pageItem = 0; if (!layout.getTitle().isEmpty()) { String title = PageProcessor.computeTitle(layout.getTitle(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, titleSize, Font.BOLD, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(layout.getSubtitle().isEmpty() ? titleLead + upperWaste : titleLead); document.add(p); } if (!layout.getSubtitle().isEmpty()) { String subtitle = PageProcessor.computeTitle(layout.getSubtitle(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(subtitle, FontFactory.getFont(FontFactory.HELVETICA, subtitleSize, Font.NORMAL, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(subtitleLead + upperWaste); document.add(p); } IVolumeManager vm = Core.getCore().getVolumeManager(); PdfPTable table = new PdfPTable(layout.getColumns()); try (Assetbox box = new Assetbox(null, status, false)) { for (int i = 0; i < rows; i++) { int ni = i * layout.getColumns(); for (int j = 0; j < layout.getColumns(); j++) { int a = (pageNo - 1) * imagesPerPage + ni + j; PdfPCell cell; if (a >= assets.size() || monitor.isCanceled()) cell = new PdfPCell(); else { final int dpi = quality == Constants.SCREEN_QUALITY ? SCREENDPI : PRINTERDPI; final int pixelWidth = (int) (imageWidth * dpi / 72); final int pixelHeight = (int) (imageHeight * dpi / 72); Asset asset = assets.get(a); zimage = new ZImage(ImageUtilities.loadThumbnail(display, asset.getJpegThumbnail(), cms, SWT.IMAGE_JPEG, true), null); org.eclipse.swt.graphics.Rectangle bounds = zimage.getBounds(); URI uri = vm.findExistingFile(asset, false); if (uri != null) { boolean r = asset.getRotation() % 180 != 0; double w = r ? asset.getHeight() : asset.getWidth(); double h = r ? asset.getWidth() : asset.getHeight(); double scale = w == 0 || h == 0 ? 1d : Math.min(pixelWidth / w, pixelHeight / h); scale = (scale <= 0.5d) ? 0.5d : 1d; File file = box.obtainFile(uri); if (file != null) try { ZImage hzimage = CoreActivator.getDefault().getHighresImageLoader().loadImage( null, status, file, asset.getRotation(), asset.getFocalLengthIn35MmFilm(), null, scale, Double.MAX_VALUE, true, ImageConstants.SRGB, null, unsharpMask, null, fileWatcher, opId, null); if (hzimage != null) { zimage.dispose(); zimage = hzimage; } } catch (UnsupportedOperationException e) { // do nothing } } display.syncExec(() -> { int kl = (keyLine > 0) ? (int) Math.max(1, (keyLine * dpi / 144)) : 0; org.eclipse.swt.graphics.Rectangle ibounds = zimage.getBounds(); double factor = Math.min((double) pixelWidth / ibounds.width, (double) pixelHeight / ibounds.height); int lw = pixelWidth + 2 * kl; int lh = pixelHeight + 2 * kl; Image newImage = new Image(display, lw, lh); GC gc = new GC(newImage); try { gc.setAntialias(SWT.ON); gc.setInterpolation(SWT.HIGH); gc.setAdvanced(true); gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); gc.fillRectangle(0, 0, lw, lh); int width = (int) (ibounds.width * factor + 2 * kl); int height = (int) (ibounds.height * factor + 2 * kl); int xoff = (lw - width) / 2; int yoff = (lh - height) / 2; if (kl > 0) { gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); gc.fillRectangle(xoff, yoff, width, height); } zimage.draw(gc, 0, 0, ibounds.width, ibounds.height, xoff + kl, yoff + kl, width - 2 * kl, height - 2 * kl, ZImage.CROPPED, pixelWidth, pixelHeight, false); } finally { gc.dispose(); zimage.dispose(); zimage = new ZImage(newImage, null); } }); bounds = zimage.getBounds(); File jpegFile = ImageActivator.getDefault().createTempFile("PdfImg", ".jpg"); //$NON-NLS-1$//$NON-NLS-2$ tempFiles.add(jpegFile); try (FileOutputStream out = new FileOutputStream(jpegFile)) { zimage.saveToStream(monitor, true, ZImage.UNCROPPED, SWT.DEFAULT, SWT.DEFAULT, out, SWT.IMAGE_JPEG, jpegQuality); } zimage.dispose(); com.itextpdf.text.Image pdfImage = com.itextpdf.text.Image.getInstance(jpegFile.getPath()); double factor = Math.min(imageWidth / bounds.width, imageHeight / bounds.height); pdfImage.setInterpolation(true); pdfImage.scaleToFit((float) (bounds.width * factor), (float) (bounds.height * factor)); cell = new PdfPCell(pdfImage, false); cell.setHorizontalAlignment(Element.ALIGN_CENTER); monitor.worked(1); } cell.setFixedHeight((float) imageHeight); cell.setBorderWidth(0); table.addCell(cell); } renderCaptions(pageNo, seqNo, pageItem, table, ni, layout.getCaption1()); renderCaptions(pageNo, seqNo, pageItem, table, ni, layout.getCaption2()); pageItem += layout.getColumns(); seqNo += layout.getColumns(); if (verticalGap > 0 && i < rows - 1) for (int j = 0; j < layout.getColumns(); j++) { PdfPCell cell = new PdfPCell(); cell.setFixedHeight(verticalGap); cell.setBorderWidth(0); table.addCell(cell); } } table.setWidthPercentage(100f); document.add(table); if (!layout.getFooter().isEmpty()) { String footer = PageProcessor.computeTitle(layout.getFooter(), fileName, now, assets.size(), pageNo, pages, collection, meta); Paragraph p = new Paragraph(footer, FontFactory.getFont(FontFactory.HELVETICA, subtitleSize, Font.NORMAL, BaseColor.DARK_GRAY)); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(upperWaste / 2 + footerLead); document.add(p); } } }
From source file:com.carfinance.module.common.controller.DocumentDownloadController.java
/** * ???PDF//ww w . jav a2 s . c o m * @param model * @param request * @param response */ @RequestMapping(value = "/pdfcontrace", method = RequestMethod.GET) public void pdfContrace(Model model, HttpServletRequest request, HttpServletResponse response) { String contrace_id_str = request.getParameter("contrace_id"); long contrace_type = Long.valueOf(request.getParameter("contrace_type"));//??1-2-? long vehicle_contrace_id = Long.valueOf(request.getParameter("vehicle_contrace_id")); String org_id = ""; String contrace_no = ""; String customer_name = ""; String license_plate = ""; String vehicle_model = ""; String engine_no = ""; String carframe_no = ""; double guide_price = 0; String color = ""; String begin_time = ""; String end_time = ""; String driving_user_name = ""; String driving_user_license_no = ""; String daily_price = ""; String daily_available_km = ""; String over_km_price = ""; String over_hour_price = ""; String month_price = ""; String month_available_km = ""; String pre_payment = ""; String deposit = ""; String monthly_day = ""; String vehicle_id = ""; if (contrace_type == 1) { VehicleContraceInfo vehicleContraceInfo = this.vehicleServiceManageService .getVehicleContraceInfoById(Long.valueOf(contrace_id_str)); if (vehicleContraceInfo != null) { org_id = String.valueOf(vehicleContraceInfo.getOrg_id()); contrace_no = vehicleContraceInfo.getContrace_no(); customer_name = vehicleContraceInfo.getCustomer_name(); // List<VehicleContraceVehsInfo> vehsList = this.vehicleServiceManageService.getVehicleContraceVehsListByContraceId(vehicleContraceInfo.getId()); // if(vehsList != null) { // VehicleContraceVehsInfo vehsInfo = vehsList.get(0); VehicleContraceVehsInfo vehsInfo = this.vehicleServiceManageService .getContraceVehicleByid(vehicle_contrace_id); VehicleInfo vehicleInfo = this.vehicleManageService.getVehicleInfoByid(vehsInfo.getVehicle_id()); license_plate = vehicleInfo.getLicense_plate(); vehicle_model = vehicleInfo.getModel(); engine_no = vehicleInfo.getEngine_no(); carframe_no = vehicleInfo.getCarframe_no(); guide_price = vehicleInfo.getGuide_price(); color = vehicleInfo.getColor(); driving_user_name = vehsInfo.getDriving_user_name(); driving_user_license_no = vehsInfo.getDriving_user_license_no(); daily_price = vehicleInfo.getDaily_price() + ""; vehicle_id = vehicleInfo.getId() + ""; // } begin_time = vehicleContraceInfo.getUse_begin(); end_time = vehicleContraceInfo.getUse_end(); daily_available_km = vehicleContraceInfo.getDaily_available_km() + ""; over_km_price = vehicleContraceInfo.getOver_km_price() + ""; over_hour_price = vehicleContraceInfo.getOver_hour_price() + ""; month_price = vehicleContraceInfo.getMonth_price() + ""; month_available_km = vehicleContraceInfo.getMonth_available_km() + ""; pre_payment = vehicleContraceInfo.getPre_payment() + ""; deposit = vehicleContraceInfo.getDeposit() + ""; monthly_day = vehicleContraceInfo.getMonthly_day() + ""; } } else if (contrace_type == 2) { PropertyContraceInfo propertyContraceInfo = this.vehicleServiceManageService .getPropertyContraceInfoById(Long.valueOf(contrace_id_str)); if (propertyContraceInfo != null) { org_id = String.valueOf(propertyContraceInfo.getOrg_id()); contrace_no = propertyContraceInfo.getContrace_no(); customer_name = propertyContraceInfo.getCustomer_name(); } } //1.ContentType response.setContentType("multipart/form-data"); //2.????(??a.pdf) response.setHeader("Content-Disposition", "attachment;fileName=" + contrace_no + "_" + vehicle_id + ".pdf"); Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50); // ?? pdf ? try { BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false); Font bold_fontChinese = new Font(bfChinese, 18, Font.BOLD, BaseColor.BLACK); Font normal_fontChinese = new Font(bfChinese, 12, Font.NORMAL, BaseColor.BLACK); Font normal_desc_fontChinese = new Font(bfChinese, 6, Font.NORMAL, BaseColor.BLACK); FileOutputStream pdfFile = new FileOutputStream(new File( appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf")); // pdf ? Paragraph paragraph1 = new Paragraph("???", bold_fontChinese); paragraph1.setAlignment(Element.ALIGN_CENTER); Chunk customer_name_underline = new Chunk(customer_name); customer_name_underline.setUnderline(1f, 3f); Chunk license_plate_underline = new Chunk(license_plate); license_plate_underline.setUnderline(1f, 3f); Chunk vehicle_model_underline = new Chunk(vehicle_model); vehicle_model_underline.setUnderline(1f, 3f); Chunk engine_no_underline = new Chunk(engine_no); engine_no_underline.setUnderline(1f, 3f); Chunk carframe_no_underline = new Chunk(carframe_no); carframe_no_underline.setUnderline(1f, 3f); Chunk guide_price_underline = new Chunk(guide_price / 10000 + ""); guide_price_underline.setUnderline(1f, 3f); Chunk color_underline = new Chunk(color); color_underline.setUnderline(1f, 3f); Chunk begin_time_underline = new Chunk(begin_time); begin_time_underline.setUnderline(1f, 3f); Chunk end_time_underline = new Chunk(end_time); end_time_underline.setUnderline(1f, 3f); Chunk driving_user_name_underline = new Chunk( driving_user_name == null ? "___/___" : driving_user_name); driving_user_name_underline.setUnderline(1f, 3f); Chunk driving_user_license_no_underline = new Chunk( driving_user_license_no == null ? "_____/_____" : driving_user_license_no); driving_user_license_no_underline.setUnderline(1f, 3f); Chunk daily_price_underline = new Chunk(daily_price); daily_price_underline.setUnderline(1f, 3f); Chunk daily_available_km_underline = new Chunk(daily_available_km); daily_available_km_underline.setUnderline(1f, 3f); Chunk over_km_price_underline = new Chunk(over_km_price); over_km_price_underline.setUnderline(1f, 3f); Chunk over_hour_price_underline = new Chunk(over_hour_price); over_hour_price_underline.setUnderline(1f, 3f); Chunk month_price_underline = new Chunk(month_price == null ? "_____/_____" : month_price); month_price_underline.setUnderline(1f, 3f); Chunk month_available_km_underline = new Chunk( month_available_km == null ? "_____/_____" : month_available_km); month_available_km_underline.setUnderline(1f, 3f); Chunk pre_payment_underline = new Chunk(pre_payment); pre_payment_underline.setUnderline(1f, 3f); Chunk deposit_underline = new Chunk(deposit); deposit_underline.setUnderline(1f, 3f); Chunk monthly_day_underline = new Chunk(monthly_day == null ? "___/___" : monthly_day); monthly_day_underline.setUnderline(1f, 3f); Paragraph paragraph2 = new Paragraph( "??? ???" + contrace_no, normal_fontChinese); Paragraph paragraph3 = new Paragraph("" + customer_name_underline + " ( 20____________", normal_fontChinese); Paragraph paragraph4 = new Paragraph( "??? ??????????", normal_fontChinese); Paragraph paragraph5 = new Paragraph("???____" + license_plate_underline + "____?____" + vehicle_model_underline + "________" + color_underline + "____??____" + engine_no_underline + "____?____" + carframe_no_underline + "____??____" + guide_price_underline + "____", normal_fontChinese); Paragraph paragraph6 = new Paragraph("?____" + begin_time_underline + "____?____" + end_time_underline + "____", normal_fontChinese); Paragraph paragraph7 = new Paragraph("??____" + driving_user_name_underline + "____??____" + driving_user_license_no_underline + "____?", normal_fontChinese); Paragraph paragraph8 = new Paragraph("????", normal_fontChinese); Paragraph paragraph9 = new Paragraph("1????____" + daily_price_underline + "____??____" + daily_available_km_underline + "____??____" + over_km_price_underline + "____??____" + over_hour_price_underline + "____??30????____" + month_price_underline + "____??____" + month_available_km_underline + "____30", normal_fontChinese); Paragraph paragraph10 = new Paragraph( "2??????8:00---20:00", normal_fontChinese); Paragraph paragraph11 = new Paragraph( "3??????", normal_fontChinese); Paragraph paragraph12 = new Paragraph( "4????____" + pre_payment_underline + "____??____" + monthly_day_underline + "____?", normal_fontChinese); Paragraph paragraph13 = new Paragraph("5???____" + deposit_underline + "____(???)???????", normal_fontChinese); Paragraph paragraph14 = new Paragraph( "6????1%????????", normal_fontChinese); Image image = Image.getInstance(appProps.get("normal.contrace.download.path") + "chekuang.jpg"); Paragraph paragraph15 = new Paragraph("?", normal_desc_fontChinese); Paragraph paragraph16 = new Paragraph( "1?????????", normal_desc_fontChinese); Paragraph paragraph17 = new Paragraph( "2????5000?200", normal_desc_fontChinese); Paragraph paragraph18 = new Paragraph( "3????", normal_desc_fontChinese); Paragraph paragraph19 = new Paragraph( "4???????????????", normal_desc_fontChinese); Paragraph paragraph20 = new Paragraph( "5?????????", normal_desc_fontChinese); Paragraph paragraph21 = new Paragraph( "6????????????", normal_desc_fontChinese); Paragraph paragraph22 = new Paragraph("?", normal_desc_fontChinese); Paragraph paragraph23 = new Paragraph( "1???????", normal_desc_fontChinese); Paragraph paragraph24 = new Paragraph( "2?????????????????????????", normal_desc_fontChinese); Paragraph paragraph25 = new Paragraph( "3????????????????????????", normal_desc_fontChinese); Paragraph paragraph26 = new Paragraph( "4?????????????????", normal_desc_fontChinese); Paragraph paragraph27 = new Paragraph( "5????????????????????", normal_desc_fontChinese); Paragraph paragraph28 = new Paragraph( "6?????????????????????620%?30%??????????????????????", normal_desc_fontChinese); Paragraph paragraph29 = new Paragraph( "7???????????", normal_desc_fontChinese); Paragraph paragraph30 = new Paragraph( "8????????", normal_desc_fontChinese); Paragraph paragraph31 = new Paragraph( "9??????????????????????", normal_desc_fontChinese); Paragraph paragraph32 = new Paragraph( "10????????????", normal_desc_fontChinese); Paragraph paragraph33 = new Paragraph( "11???????????500-1000", normal_desc_fontChinese); Paragraph paragraph34 = new Paragraph( "12??????????", normal_desc_fontChinese); Paragraph paragraph35 = new Paragraph( "13?????_________________________________7??????????\n", normal_desc_fontChinese); Paragraph paragraph36 = new Paragraph( "14?????????????????", normal_desc_fontChinese); Paragraph paragraph37 = new Paragraph( "15?????????5000????????????????400?500100????", normal_desc_fontChinese); Paragraph paragraph38 = new Paragraph( "16???????????????????????????", normal_desc_fontChinese); Paragraph paragraph39 = new Paragraph("?", normal_desc_fontChinese); Paragraph paragraph40 = new Paragraph( "1??????????????", normal_desc_fontChinese); Paragraph paragraph41 = new Paragraph( "2????????????", normal_desc_fontChinese); Paragraph paragraph42 = new Paragraph( "3????", normal_desc_fontChinese); Paragraph paragraph43 = new Paragraph( "4??????????50%?????????", normal_desc_fontChinese); Paragraph paragraph44 = new Paragraph( "5???????????????????", normal_desc_fontChinese); Paragraph paragraph45 = new Paragraph( "6???????????????", normal_desc_fontChinese); Paragraph paragraph46 = new Paragraph( "7?????????50%", normal_desc_fontChinese); Paragraph paragraph47 = new Paragraph( "8???7????????????", normal_desc_fontChinese); Paragraph paragraph48 = new Paragraph( "9???_____/?40??8????_____??", normal_desc_fontChinese); Paragraph paragraph49 = new Paragraph( "10?????___?????", normal_desc_fontChinese); Paragraph paragraph50 = new Paragraph( "11????", normal_desc_fontChinese); Paragraph paragraph51 = new Paragraph("??", normal_desc_fontChinese); Paragraph paragraph52 = new Paragraph( "1?????????20%????", normal_desc_fontChinese); Paragraph paragraph53 = new Paragraph( "2???????????????????", normal_desc_fontChinese); Paragraph paragraph54 = new Paragraph( "?????___________________\n", normal_desc_fontChinese); Paragraph paragraph55 = new Paragraph( "???????????????", normal_desc_fontChinese); Paragraph paragraph56 = new Paragraph( "???????", normal_desc_fontChinese); Paragraph paragraph57 = new Paragraph("?????????", normal_desc_fontChinese); Paragraph paragraph58 = new Paragraph( "??? ?", normal_desc_fontChinese); Paragraph paragraph59 = new Paragraph( " ??? ??", normal_desc_fontChinese); // Document ?File PdfWriter ? PdfWriter.getInstance(pdfDoc, pdfFile); pdfDoc.open(); // Document // ?? pdfDoc.add(paragraph1); pdfDoc.add(new Chunk("\n\n")); pdfDoc.add(paragraph2); pdfDoc.add(paragraph3); pdfDoc.add(paragraph4); pdfDoc.add(paragraph5); pdfDoc.add(paragraph6); pdfDoc.add(paragraph7); pdfDoc.add(paragraph8); pdfDoc.add(paragraph9); pdfDoc.add(paragraph10); pdfDoc.add(paragraph11); pdfDoc.add(paragraph12); pdfDoc.add(paragraph13); pdfDoc.add(paragraph14); pdfDoc.add(image); pdfDoc.newPage(); pdfDoc.add(paragraph15); pdfDoc.add(paragraph16); pdfDoc.add(paragraph17); pdfDoc.add(paragraph18); pdfDoc.add(paragraph19); pdfDoc.add(paragraph20); pdfDoc.add(paragraph21); pdfDoc.add(paragraph22); pdfDoc.add(paragraph23); pdfDoc.add(paragraph24); pdfDoc.add(paragraph25); pdfDoc.add(paragraph26); pdfDoc.add(paragraph27); pdfDoc.add(paragraph28); pdfDoc.add(paragraph29); pdfDoc.add(paragraph30); pdfDoc.add(paragraph31); pdfDoc.add(paragraph32); pdfDoc.add(paragraph33); pdfDoc.add(paragraph34); pdfDoc.add(paragraph35); pdfDoc.add(paragraph36); pdfDoc.add(paragraph37); pdfDoc.add(paragraph38); pdfDoc.add(paragraph39); pdfDoc.add(paragraph40); pdfDoc.add(paragraph41); pdfDoc.add(paragraph42); pdfDoc.add(paragraph43); pdfDoc.add(paragraph44); pdfDoc.add(paragraph45); pdfDoc.add(paragraph46); pdfDoc.add(paragraph47); pdfDoc.add(paragraph48); pdfDoc.add(paragraph49); pdfDoc.add(paragraph50); pdfDoc.add(paragraph51); pdfDoc.add(paragraph52); pdfDoc.add(paragraph53); pdfDoc.add(paragraph54); pdfDoc.add(paragraph55); pdfDoc.add(paragraph56); pdfDoc.add(paragraph57); pdfDoc.add(paragraph58); pdfDoc.add(paragraph59); pdfDoc.close(); ServletOutputStream out; //File(?download.pdf) File file = new File( appProps.get("normal.contrace.download.path") + contrace_no + "_" + vehicle_id + ".pdf"); try { FileInputStream inputStream = new FileInputStream(file); //3.response?ServletOutputStream(out) out = response.getOutputStream(); int b = 0; byte[] buffer = new byte[512]; while (b != -1) { b = inputStream.read(buffer); //4.?(out) out.write(buffer, 0, b); } inputStream.close(); out.close(); out.flush(); } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.chaschev.itext.TwoColumnsSectionBuilder.java
License:Apache License
public TwoColumnsSectionBuilder addToDocument(float pageTop, float pageBottom) { Document document = b.getDocument(); int pageCount = 0; for (; !tryAdding() && pageCount < MAX_PAGE_COUNT; pageCount++) { document.newPage(); newPage(pageTop, pageBottom).tryAdding(); }//w ww . ja va2 s . c om if (pageCount == MAX_PAGE_COUNT) { throw new IllegalStateException("two columns took more than " + MAX_PAGE_COUNT + " pages"); } return this; }
From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java
License:Open Source License
protected ByteArrayOutputStream doStamper(ByteArrayOutputStream baos) throws IOException, DocumentException { map.clear();//from www . j a v a 2 s .com ByteArrayOutputStream baosFinal = new ByteArrayOutputStream(); PdfReader reader = new PdfReader(baos.toByteArray()); PdfContentStreamProcessor processor = new PdfContentStreamProcessor(this); for (int i = 1; i <= reader.getNumberOfPages(); i++) { actualPage = i; PdfDictionary pageDic = reader.getPageN(i); PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES); processor.processContent(ContentByteUtils.getContentBytesForPage(reader, i), resourcesDic); } Document newDocument = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(newDocument, baosFinal); newDocument.open(); PdfContentByte canvas = writer.getDirectContent(); // Font myFont = FontFactory.getFont(FontFactory.COURIER, 7, Font.BOLD); Iterator<Entry<Integer, Map<Float, StringBuffer>>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, Map<Float, StringBuffer>> pairs = (Map.Entry<Integer, Map<Float, StringBuffer>>) it .next(); Iterator<Entry<Float, StringBuffer>> iter = pairs.getValue().entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Float, StringBuffer> actualEntry = iter.next(); canvas.beginText(); canvas.setFontAndSize(myFontBase, 7); canvas.showTextAligned(Element.ALIGN_LEFT, actualEntry.getValue().toString(), 25, actualEntry.getKey() + 60, 0); canvas.endText(); } newDocument.newPage(); } newDocument.close(); reader = new PdfReader(baosFinal.toByteArray()); PdfReaderContentParser parser = new PdfReaderContentParser(reader); TextMarginFinder finder; for (int i = 1; i <= reader.getNumberOfPages(); i++) { finder = parser.processContent(i, new TextMarginFinder()); if (finder.getLly() <= 68) { getWindow().showNotification("Hiba", "A(z) " + i + ".ik oldalon tl sok a szveg !!!", Notification.TYPE_ERROR_MESSAGE); return null; } } reader = new PdfReader(baosFinal.toByteArray()); PdfStamper stamper = new PdfStamper(reader, baosFinal); int n = reader.getNumberOfPages(); for (int i = 1; i <= n; i++) { PdfContentByte overContent = stamper.getOverContent(i); overContent.addImage(logo, 131, 0, 0, 32, 44, 775); getFooterTable(i, n).writeSelectedRows(0, -1, 27, 68, stamper.getOverContent(i)); // ez a jo getIspLogoTable(i, n).writeSelectedRows(0, -1, 425, 45, stamper.getOverContent(i)); } stamper.close(); reader.close(); return baosFinal; }
From source file:com.debashubham.dumpy.ChainageCalcActivity.java
private void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);//w ww. j ava 2s . c o m // Lets write a big header preface.add(new Paragraph("SURVEY REPORT", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + surveyor_name + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add( new Paragraph("This document is the report of a survey conducted on " + date_of_survey, smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document is the report of a survey with the work named as: " + work_name, smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with the user.", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:com.dev.saurabh.TiffToPdf.java
License:Open Source License
/** * @param args/*from w w w.j av a 2 s. co m*/ * @throws DocumentException * @throws IOException */ public static void main(String[] args) throws DocumentException, IOException { String imgeFilename = "/home/saurabh/Downloads/image.tif"; Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/saurabh/Desktop/out" + Math.random() + ".pdf")); writer.setStrictImageSequence(true); document.open(); document.add(new Paragraph("Multipages tiff file")); Image image; RandomAccessFileOrArray ra = new RandomAccessFileOrArray(imgeFilename); int pages = TiffImage.getNumberOfPages(ra); for (int i = 1; i <= pages; i++) { image = TiffImage.getTiffImage(ra, i); Rectangle pageSize = new Rectangle(image.getWidth(), image.getHeight()); document.setPageSize(pageSize); document.add(image); document.newPage(); } document.close(); }
From source file:com.devox.GUI.PDF.CrearReportePorEstado.java
@Override public void crear(File file) { try {//w ww .java 2 s . c o m Document document = new Document(PageSize.A4, 50f, 50f, 65f, 100f); file.createNewFile(); PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); setLogo(); CabeceraPieDePagina event = new CabeceraPieDePagina(); w.setPageEvent(event); document.newPage(); document.add(configurarInformacion()); document.add(new Paragraph("\n")); PdfPTable table = crearTabla(); agregarProductos(table); document.add(table); document.add(new Paragraph("\n")); document.add(new Paragraph("TOTAL: " + data.length + "FOLIOS.", FUENTE_FOLIO_CHICA)); document.close(); } catch (Exception ex) { Log.print(ex); } Object[] options = { "Abrir PDF", "No" }; int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options, options[0]); if (open == JOptionPane.YES_OPTION) { try { Desktop.getDesktop().open(file); } catch (IOException ex) { Log.print("No se encontr la ruta"); JOptionPane.showMessageDialog(null, "Error en el archivo"); } } }