List of usage examples for com.lowagie.text.pdf PdfStamper close
public void close() throws DocumentException, IOException
From source file:net.sf.jsignpdf.UncompressPdf.java
License:Mozilla Public License
/** * The main 'main'.//from w w w . jav a 2 s . c o m * * @param args */ public static void main(String[] args) { if (args == null || args.length == 0) { System.out.println("Usage:\njava " + UncompressPdf.class.getName() + " file.pdf [file2.pdf [...]]"); return; } Document.compress = false; for (String tmpFile : args) { String newFileName = null; if (tmpFile.toLowerCase().endsWith(".pdf")) { newFileName = tmpFile.substring(0, tmpFile.length() - 4) + "_uncompressed.pdf"; } else { newFileName = tmpFile + "_uncompressed.pdf"; } System.out.println("Uncompressing " + tmpFile + " to " + newFileName); try { PdfReader reader = new PdfReader(tmpFile); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(newFileName), '\0'); int total = reader.getNumberOfPages() + 1; for (int i = 1; i < total; i++) { reader.setPageContent(i, reader.getPageContent(i)); } stamper.close(); } catch (NullPointerException npe) { npe.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java
License:Open Source License
static public byte[] stampPdfAt(byte[] originalPdf, byte[] toStampPdf, int positionX, int positionY) { try {//from w w w. ja va2 s. c o m PdfReader originalPdfReader = new PdfReader(originalPdf); PdfReader toStampPdfReader = new PdfReader(toStampPdf); ByteArrayOutputStream stream = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(originalPdfReader, stream); PdfImportedPage importedPage = stamper.getImportedPage(toStampPdfReader, 1); PdfContentByte overContent = stamper.getOverContent(1); Rectangle pageSizeWithRotation = originalPdfReader.getPageSizeWithRotation(1); Rectangle pageSizeWithRotationStamper = toStampPdfReader.getPageSizeWithRotation(1); logger.info( String.format("[ %s, %s]", pageSizeWithRotation.getWidth(), pageSizeWithRotation.getHeight())); logger.info(String.format("[ %s, %s]", pageSizeWithRotationStamper.getWidth(), pageSizeWithRotationStamper.getHeight())); Image image = Image.getInstance(importedPage); overContent.addImage(image, image.getWidth(), 0f, 0f, image.getHeight(), positionX, positionY); stamper.close(); originalPdfReader.close(); toStampPdfReader.close(); return stream.toByteArray(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:net.sqs2.translator.impl.SQSToPDFTranslator.java
License:Apache License
private void combinePDFData(FOUserAgent userAgent, byte[] sqsSourceBytes, byte[] pdfRawDataBytes, OutputStream pdfOutputStream, String basename) throws IOException { try {//from w w w .ja v a 2 s . com PdfReader reader = new PdfReader(pdfRawDataBytes); int numPages = reader.getNumberOfPages(); userAgent.getRendererOptions().get("pageWidth"); byte[] svgBytes = createSVGPrint(userAgent, numPages); PdfStamper stamp = new PdfStamper(reader, pdfOutputStream); stamp.addFileAttachment("SQS Source", sqsSourceBytes, null, basename + ".sqs"); stamp.addFileAttachment("SQS Master", svgBytes, null, basename + ".sqm"); stamp.close(); reader.close(); } catch (DocumentException ex) { ex.printStackTrace(); } }
From source file:open.dolphin.hiro.PrescriptionPDFMaker.java
/** * ??//from w ww. ja v a2 s .c o m */ public String output() { BufferedOutputStream bos; PdfWriter pw = null; Document document = null; try { Date dateNow = new Date(); // ID String patientId = pkg.getPatientId(); // ??? String name = pkg.getPatientName(); name = name.replaceAll(" ", ""); name = name.replaceAll("", ""); String iNum; // ?? String piNum = null; // ? String rNum = null; // ?? String piNum2 = null; // ? String rNum2 = null; // ?? String div = ""; // ? String payRatio = ""; // ? String mNum = ""; // ??? char[] iNumC = new char[8]; // ??? char[] piNumC = new char[8]; // ?? char[] rNumC = new char[7]; // ?? char[] piNumC2 = new char[8]; // ?? char[] rNumC2 = new char[7]; // ?? DecimalFormat df = new DecimalFormat("#0.#"); // ?? String paymentRatio = ""; // ? String paymentRatio2 = ""; // ? if (pkg.getApplyedInsurance().getInsuranceNumber() != null) { // ?? iNum = pkg.getApplyedInsurance().getInsuranceNumber(); // ? null ?? if (iNum.toLowerCase().startsWith("z") || iNum.equals("9999")) { iNum = null; } // if (pkg.getApplyedInsurance().getPVTPublicInsuranceItem() != null) { PVTPublicInsuranceItemModel[] pubItems = pkg.getApplyedInsurance().getPVTPublicInsuranceItem(); for (int i = 0; i < pubItems.length; i++) { PVTPublicInsuranceItemModel pm = pubItems[i]; if (i == 0) { // ? piNum = pm.getProvider(); piNum = ("mikinyu".equals(piNum)) ? "" : piNum; // ?? rNum = pm.getRecipient(); rNum = ("mikinyu".equals(rNum)) ? "" : rNum; // ??? paymentRatio = pm.getPaymentRatio(); } else if (i == 1) { piNum2 = pm.getProvider(); piNum2 = ("mikinyu".equals(piNum2)) ? "" : piNum2; rNum2 = pm.getRecipient(); rNum2 = ("mikinyu".equals(rNum2)) ? "" : rNum2; paymentRatio2 = pm.getPaymentRatio(); break; } } } // ? ?? ? StringBuilder sb = new StringBuilder(); // ? ? if (pkg.getApplyedInsurance().getClientGroup() != null && !pkg.getApplyedInsurance().getClientGroup().equals("??")) { sb.append(pkg.getApplyedInsurance().getClientGroup()).append(""); } // ?? if (pkg.getApplyedInsurance().getClientNumber() != null && !pkg.getApplyedInsurance().getClientNumber().equals("??")) { sb.append(pkg.getApplyedInsurance().getClientNumber()); } mNum = sb.length() > 0 ? sb.toString() : ""; // if ("?".equals(pkg.getApplyedInsurance().getInsuranceClass())) { div = ""; payRatio = paymentRatio; } else { // ? div = "true".equals(pkg.getApplyedInsurance().getFamilyClass()) ? "?" : ""; payRatio = pkg.getApplyedInsurance().getPayOutRatio(); } if (payRatio != null && !("".equals(payRatio))) { payRatio = df.format(Double.valueOf(payRatio) * 10); } if (DEBUG) { System.err.println("iNum=" + iNum); System.err.println("piNum=" + piNum); System.err.println("rNum=" + rNum); System.err.println("piNum2=" + piNum2); System.err.println("rNum2=" + rNum2); System.err.println("mNum=" + mNum); System.err.println("?=" + div); System.err.println("=" + payRatio); } // ??? iNumC = partitionPadRL(iNum, 8, "R"); // ?? piNumC = partitionPadRL(piNum, 8, "L"); // ? rNumC = partitionPadRL(rNum, 7, "L"); // ?? piNumC2 = partitionPadRL(piNum2, 8, "L"); // ?2 rNumC2 = partitionPadRL(rNum2, 7, "L"); // ??2 } /***** *****/ document = new Document(PageSize.A5, 10, 10, 2, 2); // @002 2009/11/17 // ?PDF???????? if (getDocumentDir() == null) { StringBuilder sb = new StringBuilder(); sb.append(System.getProperty("user.dir")); sb.append(File.separator); sb.append(DIR_NAME); setDocumentDir(sb.toString()); } File dir = new File(getDocumentDir()); dir.mkdir(); // ??(?-ID_???_.pdf) StringBuilder sb = new StringBuilder(); sb.append(FILE_NAME_PRE); sb.append(patientId).append("_").append(name).append("_"); sb.append(new SimpleDateFormat("yyyyMMddHHmmss").format(dateNow)); sb.append(FILE_EXTENTION); setFileName(sb.toString()); sb = new StringBuilder(); if (getDocumentDir() != null) { sb.append(getDocumentDir()); sb.append(File.separator); } sb.append(getFileName()); pathToPDF = sb.toString(); //minagawa^ ???water mark?????????? byte[]??? ByteArrayOutputStream byteo = new ByteArrayOutputStream(); bos = new BufferedOutputStream(byteo); //minagawa$ pw = PdfWriter.getInstance(document, bos); // font setting bfm = BaseFont.createFont(FONT_HEISEI_MIN3, CODE_UNIJIS_H, BaseFont.NOT_EMBEDDED); bfg = BaseFont.createFont(FONT_HEISEI_KAKU5, CODE_UNIJIS_H, BaseFont.NOT_EMBEDDED); min_6 = new Font(bfm, 6); min_7 = new Font(bfm, 7); min_8 = new Font(bfm, 8); min_9 = new Font(bfm, 9); min_10 = new Font(bfm, 10); min_12 = new Font(bfm, 12); min_14 = new Font(bfm, 14); min_15 = new Font(bfm, 15); min_4 = new Font(bfm, 4); // @009 // document.open(); document.addAuthor(pkg.getPhysicianName()); document.addTitle(PROPERTY_TITLE); document.addSubject(PROPERTY_SUB_TITLE); // ??? List<PdfPTable> list = createPrescriptionTbl2(); Iterator<PdfPTable> ite = list.iterator(); // ? int pageNo = 0; int totalPageNo = list.size(); // ????????? do { PdfPTable ptbl = new PdfPTable(1); ptbl.setWidthPercentage(100f); ptbl.getDefaultCell().setPadding(0f); PdfPCell pcell = new PdfPCell(new Paragraph(REPORT_TITLE, min_15)); pcell.setBorder(Table.NO_BORDER); setAlignCenter(pcell); ptbl.addCell(pcell); pcell = new PdfPCell(new Paragraph(REPORT_SUB_TITLE, min_7)); pcell.setBorder(Table.NO_BORDER); setAlignCenter(pcell); ptbl.addCell(pcell); document.add(ptbl); ptbl = new PdfPTable(3); ptbl.setWidthPercentage(100f); ptbl.getDefaultCell().setPadding(0f); ptbl.getDefaultCell().setBorder(Table.NO_BORDER); float[] widths = { 43.5f, 2f, 54.5f }; ptbl.setWidths(widths); // ? pcell = new PdfPCell(new Paragraph(patientId, min_9)); pcell.setBorder(Table.NO_BORDER); pcell.setColspan(10); ptbl.addCell(pcell); PdfPTable ptblL = new PdfPTable(9); ptblL.setSpacingBefore(10f); ptblL.setWidthPercentage(100f); float[] widthsL = { 33, 8, 8, 8, 8, 8, 8, 8, 8 }; ptblL.setWidths(widthsL); ptblL.getDefaultCell().setPadding(0f); pcell = new PdfPCell(new Paragraph("?", min_7)); pcell.setMinimumHeight(CELL_HIGHT_0); setAlignJustifiedAll(pcell); setAlignMiddle(pcell); pcell.setBorderWidth(LINE_WIDTH_1); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[0]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[1]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthRight(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[2]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthLeft(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[3]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthRight(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[4]), min_14)); pcell.setBorderWidth(LINE_WIDTH_2); pcell.setBorderWidthRight(LINE_WIDTH_1); pcell.setBorderWidthLeft(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[5]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthTop(LINE_WIDTH_2); pcell.setBorderWidthBottom(LINE_WIDTH_2); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[6]), min_14)); pcell.setBorderWidth(LINE_WIDTH_2); pcell.setBorderWidthRight(LINE_WIDTH_3); pcell.setBorderWidthLeft(LINE_WIDTH_1); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(piNumC[7]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthLeft(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph("???", min_7)); pcell.setPaddingTop(0.3f); setAlignJustifiedAll(pcell); pcell.setBorderWidth(LINE_WIDTH_1); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[0]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[1]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[2]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthRight(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[3]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthLeft(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[4]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[5]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthRight(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(rNumC[6]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthLeft(LINE_WIDTH_3); pcell.setPadding(0f); setAlignCenterMiddle(pcell); ptblL.addCell(pcell); pcell = new PdfPCell(); pcell.setBorderWidth(LINE_WIDTH_0); ptblL.addCell(pcell); PdfPTable patientTbl = new PdfPTable(2); patientTbl.setWidthPercentage(100f); float[] widthsPa = { 7.8f, 92.2f }; patientTbl.setWidths(widthsPa); patientTbl.getDefaultCell().setPadding(0f); patientTbl.getDefaultCell().setBorder(Table.NO_BORDER); PdfPCell pcellP = new PdfPCell(new Paragraph("", min_7)); pcellP.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pcellP); patientTbl.addCell(pcellP); // PdfPTable desc = new PdfPTable(5); desc.setWidthPercentage(100f); float[] widthsD = { 28.5f, 41.5f, 7, 16, 7 }; desc.setWidths(widthsD); // ???(??) PdfPCell patientInfo = new PdfPCell(new Paragraph("???", min_7)); patientInfo.setBorderWidth(LINE_WIDTH_1); setAlignJustifiedAll(patientInfo); setAlignMiddle(patientInfo); desc.addCell(patientInfo); PdfPTable nameTbl = new PdfPTable(1); nameTbl.setWidthPercentage(100f); nameTbl.setSpacingAfter(3f); PdfPCell nameCell = new PdfPCell(new Paragraph(pkg.getPatientKana(), min_7)); nameCell.setBorderWidth(LINE_WIDTH_0); nameTbl.addCell(nameCell); nameCell = new PdfPCell(new Paragraph(pkg.getPatientName(), min_9)); nameCell.setBorderWidth(LINE_WIDTH_0); nameTbl.addCell(nameCell); patientInfo = new PdfPCell(nameTbl); patientInfo.setColspan(4); patientInfo.setBorderWidth(LINE_WIDTH_1); desc.addCell(patientInfo); // patientInfo = new PdfPCell(new Paragraph("", min_7)); patientInfo.setBorderWidth(LINE_WIDTH_1); setAlignJustifiedAll(patientInfo); desc.addCell(patientInfo); String birthDay = ModelUtils.convertToGengo(pkg.getPatientBirthday()); patientInfo = new PdfPCell(new Paragraph(birthDay, min_9)); patientInfo.setBorderWidth(LINE_WIDTH_1); patientInfo.setColspan(3); patientInfo.setPaddingTop(0.5f); setAlignMiddle(patientInfo); desc.addCell(patientInfo); patientInfo = new PdfPCell(new Paragraph(pkg.getPatientSex(), min_8)); patientInfo.setBorderWidth(LINE_WIDTH_1); setAlignCenter(patientInfo); desc.addCell(patientInfo); // patientInfo = new PdfPCell(new Paragraph("", min_7)); patientInfo.setBorderWidth(LINE_WIDTH_1); setAlignJustifiedAll(patientInfo); setAlignMiddle(patientInfo); desc.addCell(patientInfo); patientInfo = new PdfPCell(new Paragraph(div, min_8)); patientInfo.setBorderWidth(LINE_WIDTH_1); setAlignMiddle(patientInfo); desc.addCell(patientInfo); patientInfo = new PdfPCell(new Paragraph("?", min_7)); patientInfo.setBorderWidth(LINE_WIDTH_1); setAlignMiddle(patientInfo); desc.addCell(patientInfo); patientInfo = new PdfPCell(new Paragraph(payRatio, min_9)); setAlignRightMiddle(patientInfo); patientInfo.setBorderWidth(LINE_WIDTH_0); desc.addCell(patientInfo); patientInfo = new PdfPCell(new Paragraph("", min_7)); patientInfo.setBorderWidth(LINE_WIDTH_0); patientInfo.setVerticalAlignment(Element.ALIGN_BOTTOM); setAlignRight(patientInfo); desc.addCell(patientInfo); patientTbl.addCell(desc); pcell = new PdfPCell(patientTbl); pcell.setColspan(9); pcell.setBorderWidth(LINE_WIDTH_1); ptblL.addCell(pcell); // pcell = new PdfPCell(new Paragraph("", min_7)); pcell.setBorderWidth(LINE_WIDTH_1); setAlignJustifiedAll(pcell); setAlignMiddle(pcell); ptblL.addCell(pcell); // @003 2010/02/15 ??????????????? String issueDate = ModelUtils.convertToGengo( ModelUtils.getDateAsFormatString(pkg.getIssuanceDate(), IInfoModel.DATE_WITHOUT_TIME)); pcell = new PdfPCell(new Paragraph(issueDate, min_9)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPaddingTop(0.5f); setAlignMiddle(pcell); pcell.setColspan(8); ptblL.addCell(pcell); ptbl.addCell(ptblL); ptbl.addCell(""); PdfPTable ptblR = new PdfPTable(10); ptblR.setSpacingBefore(10f); ptblR.setWidthPercentage(100f); float[] widthsR = { 30, 7, 7, 7, 7, 7, 7, 7, 7, 14 }; ptblR.setWidths(widthsR); pcell = new PdfPCell(new Paragraph("??", min_7)); pcell.setMinimumHeight(CELL_HIGHT_0); pcell.setBorderWidth(LINE_WIDTH_1); setAlignJustifiedAll(pcell); setAlignMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[0]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[1]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthRight(LINE_WIDTH_2); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[2]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[3]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthRight(LINE_WIDTH_2); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[4]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthTop(LINE_WIDTH_2); pcell.setBorderWidthBottom(LINE_WIDTH_2); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[5]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setBorderWidthTop(LINE_WIDTH_2); pcell.setBorderWidthBottom(LINE_WIDTH_2); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[6]), min_14)); pcell.setBorderWidth(LINE_WIDTH_2); pcell.setBorderWidthLeft(LINE_WIDTH_1); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(String.valueOf(iNumC[7]), min_14)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setPadding(CELL_PADDING_0); setAlignCenterMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(); pcell.setBorderWidth(LINE_WIDTH_0); ptblR.addCell(pcell); pcell = new PdfPCell( new Paragraph("?????", min_7)); pcell.setPaddingTop(0.3f); pcell.setBorderWidth(LINE_WIDTH_1); setAlignJustifiedAll(pcell); setAlignMiddle(pcell); ptblR.addCell(pcell); pcell = new PdfPCell(new Paragraph(mNum, min_9)); pcell.setBorderWidth(LINE_WIDTH_1); pcell.setColspan(9); setAlignMiddle(pcell); ptblR.addCell(pcell); //FacilityModel facility = getPhysician().getFacilityModel(); String facilityName = pkg.getInstitutionName(); // ?? //String facilityZipCode = facility.getZipCode(); // ? String facilityAddress = pkg.getInstitutionAddress(); // ? String facilityTelNo = pkg.getInstitutionTelephone(); // ? //minagawa^ ????? String drName = pkg.getPhysicianName(); //minagawa$ if (pkg.isChkUseDrugInfo()) { // ?? drName = pkg.getPhysicianName(); } // ********** @008 2010/06/18 ********** // 20104? String prefNo = " "; // ?? 2? String grade = " "; // ? 1? String institution = " "; // 7? if ((pkg.getInstitutionNumber() != null) && (pkg.getInstitutionNumber().length() > 9)) { prefNo = pkg.getInstitutionNumber().substring(0, 2); grade = pkg.getInstitutionNumber().substring(2, 3); institution = pkg.getInstitutionNumber().substring(3, 10); } // ********** @008 2010/06/18 ********** PdfPTable medOrgTbl = new PdfPTable(3); medOrgTbl.setWidthPercentage(100f); float[] widthsM = { 30, 55, 15 }; medOrgTbl.setWidths(widthsM); PdfPCell medOrgCell = new PdfPCell(new Paragraph("??\n", min_7)); medOrgCell.setBorderWidth(LINE_WIDTH_0); setAlignJustifiedAll(medOrgCell); medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph(facilityAddress, min_8)); medOrgCell.setBorderWidth(LINE_WIDTH_0); medOrgCell.setColspan(2); setAlignMiddle(medOrgCell); medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph("????", min_7)); medOrgCell.setBorderWidth(LINE_WIDTH_0); setAlignJustifiedAll(medOrgCell); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph(facilityName, min_8)); medOrgCell.setBorderWidth(LINE_WIDTH_0); medOrgCell.setColspan(2); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(); medOrgCell.setBorder(Table.NO_BORDER); medOrgCell.setColspan(3); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgCell.setPaddingBottom(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph("?", min_7)); medOrgCell.setBorderWidth(LINE_WIDTH_0); setAlignJustifiedAll(medOrgCell); setAlignMiddle(medOrgCell); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph(facilityTelNo, min_9)); medOrgCell.setBorderWidth(LINE_WIDTH_0); setAlignMiddle(medOrgCell); medOrgCell.setColspan(2); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph("????", min_7)); medOrgCell.setBorderWidth(LINE_WIDTH_0); setAlignJustifiedAll(medOrgCell); setAlignMiddle(medOrgCell); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph(drName, min_10)); medOrgCell.setBorderWidth(LINE_WIDTH_0); setAlignMiddle(medOrgCell); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); medOrgCell = new PdfPCell(new Paragraph("?", min_8)); medOrgCell.setBorderWidth(LINE_WIDTH_0); setAlignMiddle(medOrgCell); medOrgCell.setPaddingTop(CELL_PADDING_0); // @008 medOrgTbl.addCell(medOrgCell); pcell = new PdfPCell(medOrgTbl); pcell.setBorder(Table.NO_BORDER); pcell.setColspan(10); pcell.setPaddingBottom(CELL_PADDING_1); ptblR.addCell(pcell); // ********** @008 2010/06/18 ********** // 20104? PdfPTable medCodeTbl = new PdfPTable(13); medCodeTbl.setWidthPercentage(100f); float[] widthsCode = { 17, 8, 8, 15, 8, 17, 8, 8, 8, 8, 8, 8, 8 }; medCodeTbl.setWidths(widthsCode); // ?? PdfPCell medCodeCell = new PdfPCell(new Paragraph("?\n?", min_6)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(prefNo.charAt(0)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(prefNo.charAt(1)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph("\n?", min_6)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(grade.charAt(0)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph("", min_6)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(0)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(1)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(2)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(3)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(4)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(5)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); medCodeCell = new PdfPCell(new Paragraph(String.valueOf(institution.charAt(6)), min_14)); medCodeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(medCodeCell); medCodeCell.setPaddingTop(CELL_PADDING_0); medCodeTbl.addCell(medCodeCell); pcell = new PdfPCell(medCodeTbl); pcell.setBorder(Table.NO_BORDER); pcell.setColspan(10); pcell.setPaddingBottom(CELL_PADDING_1); ptblR.addCell(pcell); // ********** @008 2010/06/18 ********** ptbl.addCell(ptblR); // ?? PdfPTable termTbl = new PdfPTable(3); termTbl.setWidthPercentage(100f); float[] widthsT = { 14.8f, 26, 59.2f }; termTbl.setWidths(widthsT); termTbl.getDefaultCell().setPadding(0f); PdfPCell termCell = new PdfPCell(new Paragraph("??\n", min_7)); termCell.setBorderWidth(LINE_WIDTH_1); termCell.setPaddingTop(0.3f); setAlignJustifiedAll(termCell); termTbl.addCell(termCell); // ********* @009 2010/07/01 ********* String periodDate = "?"; if (pkg.getPeriod() != null) { periodDate = ModelUtils.convertToGengo( ModelUtils.getDateAsFormatString(pkg.getPeriod(), IInfoModel.DATE_WITHOUT_TIME)); } termCell = new PdfPCell(new Paragraph(periodDate, min_8)); // ********* @009 2010/07/01 ********* termCell.setBorderWidth(LINE_WIDTH_1); termCell.setBorderWidthRight(LINE_WIDTH_0); setAlignMiddle(termCell); termTbl.addCell(termCell); termCell = new PdfPCell(new Paragraph( "???????????????????", min_6)); termCell.setBorderWidth(LINE_WIDTH_1); termCell.setBorderWidthLeft(LINE_WIDTH_0); setAlignMiddle(termCell); termTbl.addCell(termCell); pcell = new PdfPCell(termTbl); pcell.setBorder(Table.NO_BORDER); pcell.setColspan(3); ptbl.addCell(pcell); document.add(ptbl); // ptbl = new PdfPTable(2); ptbl.setWidthPercentage(100f); ptbl.getDefaultCell().setPadding(0f); ptbl.getDefaultCell().setBorder(Table.NO_BORDER); float[] widthsPre = { 3.5f, 96.5f }; ptbl.setWidths(widthsPre); pcell = new PdfPCell( new Paragraph("", min_7)); pcell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pcell); ptbl.addCell(pcell); // @005 2010/02/26 // ?? // PdfPTable outLineTbl = new PdfPTable(1); PdfPCell outLineCell; // ? // @005 2010/02/26 // PdfPTable prescriptionTbl; // if (ite.hasNext()) { prescriptionTbl = ite.next(); } else { prescriptionTbl = new PdfPTable(1); } // @005 2010/02/26 // ?? outLineCell = new PdfPCell(prescriptionTbl); outLineCell.setFixedHeight(200f); outLineCell.setBorderWidth(LINE_WIDTH_0); outLineTbl.addCell(outLineCell); if (totalPageNo > 1) { pageNo++; outLineCell = new PdfPCell( new Paragraph((String.valueOf(pageNo) + "?" + String.valueOf(totalPageNo)), min_10)); setAlignRight(outLineCell); outLineCell.setFixedHeight(12f); // @010 outLineCell.setBorderWidth(LINE_WIDTH_1); // @010 outLineTbl.addCell(outLineCell); } // @005 2010/02/26 PdfPCell prescriptionCell = new PdfPCell(outLineTbl); prescriptionCell.setFixedHeight(215f); prescriptionCell.setBorderWidth(LINE_WIDTH_1); ptbl.addCell(prescriptionCell); // pcell = new PdfPCell(new Paragraph("", min_7)); pcell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pcell); ptbl.addCell(pcell); // PdfPTable noteTbl = new PdfPTable(5); // @010 noteTbl.setWidthPercentage(100f); float[] widthsN = { 11, 4, 34, 4, 47 }; // @010 noteTbl.setWidths(widthsN); noteTbl.getDefaultCell().setPadding(0f); noteTbl.getDefaultCell().setBorder(Table.NO_BORDER); String address = (pkg.getPatientAddress() == null) ? "" : pkg.getPatientAddress(); String patientName = pkg.getPatientName(); String addressName = "?" + address + "\n???" + patientName; String useDrugInfo = "??" + pkg.getDrugLicenseNumber() + "(" + pkg.getPhysicianName() + ")"; StringBuilder postInfo = new StringBuilder(); // if (pkg.isChkHomeMedical()) { postInfo.append(NOTES_HOME_MEDICAL + "\n"); } if (pkg.isChkPatientInfo()) { // ????? postInfo.append(addressName); } if (postInfo.length() > 0) { // postInfo.append("\n"); } if (pkg.isChkUseDrugInfo()) { // ?? postInfo.append(useDrugInfo); } // @010 20124 --> PdfPCell noteCell = new PdfPCell(new Paragraph("???", min_7)); noteCell.setBorderWidth(LINE_WIDTH_0); noteCell.setBorderWidthBottom(LINE_WIDTH_1); noteCell.setMinimumHeight(CELL_HIGHT_2); setAlignTop(noteCell); noteTbl.addCell(noteCell); noteCell = new PdfPCell(new Paragraph("", min_15));//min_15 noteCell.setBorderWidth(LINE_WIDTH_0); noteCell.setBorderWidthBottom(LINE_WIDTH_1); noteCell.setPadding(0f); setAlignRight(noteCell); noteTbl.addCell(noteCell); noteCell = new PdfPCell(new Paragraph( "??????????\n?????????????", min_6)); noteCell.setBorderWidth(LINE_WIDTH_0); noteCell.setBorderWidthBottom(LINE_WIDTH_1); noteTbl.addCell(noteCell); noteCell = new PdfPCell(new Paragraph("", min_15));//min_15 noteCell.setBorderWidth(LINE_WIDTH_0); noteCell.setBorderWidthBottom(LINE_WIDTH_1); noteCell.setBorderWidthRight(LINE_WIDTH_1); noteCell.setPadding(0f); setAlignLeft(noteCell); noteTbl.addCell(noteCell); //minagawa^ ???? 47 noteCell = new PdfPCell(); noteCell.setBorderWidth(LINE_WIDTH_0); noteTbl.addCell(noteCell); //minagawa noteCell = new PdfPCell(new Paragraph(postInfo.toString(), min_7)); // ???????? noteCell.setColspan(widthsN.length); noteCell.setMinimumHeight(40f); noteCell.setBorderWidth(LINE_WIDTH_0); noteTbl.addCell(noteCell); // <-- 20124 @010 pcell = new PdfPCell(noteTbl); pcell.setBorderWidth(LINE_WIDTH_1); ptbl.addCell(pcell); document.add(ptbl); // ?? ptbl = new PdfPTable(2); ptbl.setWidthPercentage(100f); float[] widthsOther = { 58, 42 }; ptbl.setWidths(widthsOther); ptbl.getDefaultCell().setPadding(0f); ptbl.getDefaultCell().setBorder(Table.NO_BORDER); // ptblL = new PdfPTable(3); ptblL.setWidthPercentage(100f); float[] widthsPh = { 28, 65, 7 }; ptblL.setWidths(widthsPh); ptblL.getDefaultCell().setPadding(0f); ptblL.getDefaultCell().setBorder(Table.NO_BORDER); PdfPCell pcellL = new PdfPCell(new Paragraph("", min_7)); pcellL.setMinimumHeight(CELL_HIGHT_0); pcellL.setBorderWidth(LINE_WIDTH_1); setAlignJustifiedAll(pcellL); setAlignMiddle(pcellL); ptblL.addCell(pcellL); pcellL = new PdfPCell(new Paragraph("?", min_8)); pcellL.setBorderWidth(LINE_WIDTH_1); setAlignMiddle(pcellL); pcellL.setColspan(2); ptblL.addCell(pcellL); pcellL = new PdfPCell(new Paragraph("??\n??\n??", min_7)); pcellL.setPaddingTop(0.2f); pcellL.setBorderWidth(LINE_WIDTH_1); pcellL.setBorderWidthBottom(LINE_WIDTH_0); setAlignJustifiedAll(pcellL); ptblL.addCell(pcellL); pcellL = new PdfPCell(); pcellL.setBorderWidth(LINE_WIDTH_0); pcellL.setBorderWidthRight(LINE_WIDTH_1); pcellL.setColspan(2); ptblL.addCell(pcellL); pcellL = new PdfPCell(new Paragraph("?\n???", min_7)); pcellL.setPaddingTop(0.2f); pcellL.setBorderWidth(LINE_WIDTH_1); pcellL.setBorderWidthTop(LINE_WIDTH_0); setAlignJustifiedAll(pcellL); ptblL.addCell(pcellL); pcellL = new PdfPCell(); pcellL.setBorderWidth(LINE_WIDTH_0); pcellL.setBorderWidthBottom(LINE_WIDTH_1); ptblL.addCell(pcellL); pcellL = new PdfPCell(new Paragraph("?", min_8)); pcellL.setBorderWidth(LINE_WIDTH_1); pcellL.setBorderWidthTop(LINE_WIDTH_0); pcellL.setBorderWidthLeft(LINE_WIDTH_0); setAlignJustifiedAll(pcellL); setAlignMiddle(pcellL); ptblL.addCell(pcellL); ptbl.addCell(ptblL); ptblR = new PdfPTable(9); ptblR.setWidthPercentage(100f); float[] widthsPu = { 33, 8, 8, 8, 8, 8, 8, 8, 8 }; ptblR.setWidths(widthsPu); ptblR.getDefaultCell().setPadding(0f); PdfPCell pcellR = new PdfPCell(new Paragraph("?", min_7)); pcellR.setMinimumHeight(CELL_HIGHT_0); setAlignJustifiedAll(pcellR); setAlignMiddle(pcellR); pcellR.setBorderWidth(LINE_WIDTH_1); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[0]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[1]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthRight(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[2]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthLeft(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[3]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthRight(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[4]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_2); pcellR.setBorderWidthRight(LINE_WIDTH_1); pcellR.setBorderWidthLeft(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[5]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthTop(LINE_WIDTH_2); pcellR.setBorderWidthBottom(LINE_WIDTH_2); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[6]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_2); pcellR.setBorderWidthRight(LINE_WIDTH_3); pcellR.setBorderWidthLeft(LINE_WIDTH_1); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(piNumC2[7]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthLeft(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph("???", min_7)); pcellR.setPaddingTop(0.3f); setAlignJustifiedAll(pcellR); pcellR.setBorderWidth(LINE_WIDTH_1); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[0]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[1]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[2]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthRight(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[3]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthLeft(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[4]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[5]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthRight(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(new Paragraph(String.valueOf(rNumC2[6]), min_14)); // @006 pcellR.setBorderWidth(LINE_WIDTH_1); pcellR.setBorderWidthLeft(LINE_WIDTH_3); pcellR.setPadding(0f); setAlignCenterMiddle(pcellR); ptblR.addCell(pcellR); pcellR = new PdfPCell(); pcellR.setBorderWidth(LINE_WIDTH_0); ptblR.addCell(pcellR); pcellR = new PdfPCell(); pcellR.setBorderWidth(LINE_WIDTH_0); pcellR.setColspan(9); ptblR.addCell(pcellR); ptbl.addCell(ptblR); document.add(ptbl); ptbl = new PdfPTable(2); ptbl.setWidthPercentage(100f); float[] widthsMed = { 3.5f, 96.5f }; ptbl.setWidths(widthsMed); ptbl.setSpacingBefore(3f); ptbl.getDefaultCell().setPadding(0f); ptbl.getDefaultCell().setBorder(Table.NO_BORDER); pcell = new PdfPCell(new Paragraph("????", min_7)); pcell.setBorderWidth(LINE_WIDTH_1); setAlignCenter(pcell); ptbl.addCell(pcell); ptblR = new PdfPTable(3); ptblR.setWidthPercentage(100f); float[] widthsPm = { 60, 20, 20 }; ptblR.setWidths(widthsPm); ptblR.getDefaultCell().setPadding(0f); ptblR.getDefaultCell().setBorder(Table.NO_BORDER); // ???????? PdfPTable pointTbl = new PdfPTable(7); pointTbl.setWidthPercentage(100f); float[] widthsPo = { 7, 15.5f, 15.5f, 15.5f, 15.5f, 15.5f, 15.5f }; pointTbl.setWidths(widthsPo); pointTbl.getDefaultCell().setPadding(0f); pointTbl.getDefaultCell().setBorder(Table.NO_BORDER); PdfPCell pointCell = new PdfPCell(new Paragraph("", min_7)); pointCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pointCell); pointTbl.addCell(pointCell); pointCell = new PdfPCell(new Paragraph("", min_7)); pointCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pointCell); pointTbl.addCell(pointCell); pointCell = new PdfPCell(new Paragraph("", min_7)); pointCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pointCell); pointTbl.addCell(pointCell); pointCell = new PdfPCell(new Paragraph("?", min_7)); pointCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pointCell); pointTbl.addCell(pointCell); pointCell = new PdfPCell(new Paragraph("", min_7)); pointCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pointCell); pointTbl.addCell(pointCell); pointCell = new PdfPCell(new Paragraph("?", min_7)); pointCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pointCell); pointTbl.addCell(pointCell); pointCell = new PdfPCell(new Paragraph("", min_7)); pointCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(pointCell); pointTbl.addCell(pointCell); // ? PdfPCell blankCell = new PdfPCell(); blankCell.setBorderWidth(LINE_WIDTH_1); pointTbl.addCell(blankCell); pointTbl.addCell(blankCell); pointTbl.addCell(blankCell); pointTbl.addCell(blankCell); pointTbl.addCell(blankCell); pointTbl.addCell(blankCell); pointTbl.addCell(blankCell); ptblR.addCell(pointTbl); // ? PdfPTable feeTbl = new PdfPTable(2); feeTbl.setWidthPercentage(100f); float[] widthsF = { 50, 50 }; feeTbl.setWidths(widthsF); feeTbl.getDefaultCell().setPadding(0f); feeTbl.getDefaultCell().setBorder(Table.NO_BORDER); PdfPCell feeCell = new PdfPCell(new Paragraph(" ", min_7)); feeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenter(feeCell); feeTbl.addCell(feeCell); feeCell = new PdfPCell(new Paragraph(" ", min_7)); feeCell.setBorderWidth(LINE_WIDTH_1); setAlignCenter(feeCell); feeTbl.addCell(feeCell); feeCell = new PdfPCell(); feeCell.setBorderWidth(LINE_WIDTH_1); feeCell.setMinimumHeight(CELL_HIGHT_1); feeTbl.addCell(feeCell); feeTbl.addCell(feeCell); // ?etc.. PdfPTable feeTblSub = new PdfPTable(4); feeTblSub.setWidthPercentage(100f); float[] widthsSub = { 28, 16, 28, 28 }; feeTblSub.setWidths(widthsSub); feeTblSub.getDefaultCell().setPadding(0f); feeTblSub.getDefaultCell().setBorder(Table.NO_BORDER); PdfPCell feeCellSub = new PdfPCell(new Paragraph("?", min_7)); feeCellSub.setBorderWidth(LINE_WIDTH_1); setAlignCenter(feeCellSub); feeTblSub.addCell(feeCellSub); feeCellSub = new PdfPCell(new Paragraph("", min_7)); feeCellSub.setBorderWidth(LINE_WIDTH_1); setAlignCenter(feeCellSub); feeTblSub.addCell(feeCellSub); feeCellSub = new PdfPCell(new Paragraph(" ", min_7)); feeCellSub.setBorderWidth(LINE_WIDTH_1); setAlignCenter(feeCellSub); feeTblSub.addCell(feeCellSub); feeCellSub = new PdfPCell(new Paragraph("? ", min_7)); feeCellSub.setBorderWidth(LINE_WIDTH_1); setAlignCenter(feeCellSub); feeTblSub.addCell(feeCellSub); // ? feeCellSub = new PdfPCell(); feeCellSub.setBorderWidth(LINE_WIDTH_1); feeCellSub.setMinimumHeight(CELL_HIGHT_1); feeTblSub.addCell(feeCellSub); feeTblSub.addCell(feeCellSub); feeTblSub.addCell(feeCellSub); feeTblSub.addCell(feeCellSub); feeCell = new PdfPCell(feeTblSub); feeCell.setBorder(Table.NO_BORDER); feeCell.setColspan(2); feeTbl.addCell(feeCell); // etc..? pcellR = new PdfPCell(feeTbl); pcellR.setPadding(0f); pcellR.setColspan(2); pcellR.setBorder(Table.NO_BORDER); ptblR.addCell(pcellR); // noteTbl = new PdfPTable(2); noteTbl.setWidthPercentage(100f); float[] widthsNote = { 5.3f, 94.7f }; noteTbl.setWidths(widthsNote); noteTbl.getDefaultCell().setPadding(0f); noteTbl.getDefaultCell().setBorder(Table.NO_BORDER); noteCell = new PdfPCell(new Paragraph("", min_7)); noteCell.setBorderWidth(LINE_WIDTH_1); setAlignCenterMiddle(noteCell); noteTbl.addCell(noteCell); noteCell = new PdfPCell(); noteCell.setBorderWidth(LINE_WIDTH_1); noteTbl.addCell(noteCell); pcell = new PdfPCell(noteTbl); pcell.setBorderWidth(LINE_WIDTH_0); pcell.setPadding(0f); pcell.setColspan(2); ptblR.addCell(pcell); // ? PdfPTable sumTbl = new PdfPTable(1); sumTbl.setWidthPercentage(100f); sumTbl.getDefaultCell().setPadding(0f); sumTbl.getDefaultCell().setBorder(Table.NO_BORDER); PdfPCell sumCell = new PdfPCell(new Paragraph("?", min_7)); sumCell.setBorderWidth(LINE_WIDTH_1); setAlignCenter(sumCell); sumTbl.addCell(sumCell); sumCell = new PdfPCell(); sumCell.setBorderWidth(LINE_WIDTH_1); sumCell.setMinimumHeight(CELL_HIGHT_1); sumTbl.addCell(sumCell); ptblR.addCell(sumTbl); pcell = new PdfPCell(ptblR); pcell.setBorderWidth(LINE_WIDTH_0); pcell.setPadding(0f); ptbl.addCell(pcell); document.add(ptbl); // if (ite.hasNext()) { document.newPage(); } } while (ite.hasNext()); document.close(); bos.close(); // pdf content bytes byte[] pdfbytes = byteo.toByteArray(); // ????? File???? //if (!ClientContext.is5mTest()) { if (!Project.isTester()) { FileOutputStream fout = new FileOutputStream(pathToPDF); FileChannel channel = fout.getChannel(); ByteBuffer bytebuff = ByteBuffer.wrap(pdfbytes); while (bytebuff.hasRemaining()) { channel.write(bytebuff); } channel.close(); return pathToPDF; } // ??? water Mark ?? PdfReader pdfReader = new PdfReader(pdfbytes); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(pathToPDF)); Image image = Image.getInstance(ClientContext.getImageResource("water-mark.png")); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getUnderContent(i); image.scaleAbsolute(PageSize.A5.getWidth(), PageSize.A5.getHeight()); image.setAbsolutePosition(0.0f, 0.0f); content.addImage(image); } pdfStamper.close(); return pathToPDF; } catch (DocumentException e) { e.printStackTrace(System.err); throw new RuntimeException(e.getMessage()); } catch (IOException e) { e.printStackTrace(System.err); throw new RuntimeException(e.getMessage()); } catch (Exception e) { e.printStackTrace(System.err); throw new RuntimeException(e.getMessage()); } finally { if (document != null && document.isOpen()) { document.close(); } } }
From source file:org.allcolor.yahp.cl.converter.CDocumentReconstructor.java
License:Open Source License
/** * construct a pdf document from pdf parts. * /*from w w w . ja v a 2 s . c o m*/ * @param files * list containing the pdf to assemble * @param properties * converter properties * @param fout * outputstream to write the new pdf * @param base_url * base url of the document * @param producer * producer of the pdf * * @throws CConvertException * if an error occured while reconstruct. */ public static void reconstruct(final List files, final Map properties, final OutputStream fout, final String base_url, final String producer, final PageSize[] size, final List hf) throws CConvertException { OutputStream out = fout; OutputStream out2 = fout; boolean signed = false; OutputStream oldOut = null; File tmp = null; File tmp2 = null; try { tmp = File.createTempFile("yahp", "pdf"); tmp2 = File.createTempFile("yahp", "pdf"); oldOut = out; if ("true".equals(properties.get(IHtmlToPdfTransformer.USE_PDF_SIGNING))) { signed = true; out2 = new FileOutputStream(tmp2); } // end if else { out2 = oldOut; } out = new FileOutputStream(tmp); com.lowagie.text.Document document = null; PdfCopy writer = null; boolean first = true; Map mapSizeDoc = new HashMap(); int totalPage = 0; for (int i = 0; i < files.size(); i++) { final File fPDF = (File) files.get(i); final PdfReader reader = new PdfReader(fPDF.getAbsolutePath()); reader.consolidateNamedDestinations(); final int n = reader.getNumberOfPages(); if (first) { first = false; // step 1: creation of a document-object // set title/creator/author document = new com.lowagie.text.Document(reader.getPageSizeWithRotation(1)); // step 2: we create a writer that listens to the document writer = new PdfCopy(document, out); // use pdf version 1.5 writer.setPdfVersion(PdfWriter.VERSION_1_3); // compress the pdf writer.setFullCompression(); // check if encryption is needed if ("true".equals(properties.get(IHtmlToPdfTransformer.USE_PDF_ENCRYPTION))) { final String password = (String) properties .get(IHtmlToPdfTransformer.PDF_ENCRYPTION_PASSWORD); final int securityType = CDocumentReconstructor.getSecurityFlags(properties); writer.setEncryption(PdfWriter.STANDARD_ENCRYPTION_128, password, null, securityType); } // end if final String title = (String) properties.get(IHtmlToPdfTransformer.PDF_TITLE); if (title != null) { document.addTitle(title); } // end if else if (base_url != null) { document.addTitle(base_url); } // end else if final String creator = (String) properties.get(IHtmlToPdfTransformer.PDF_CREATOR); if (creator != null) { document.addCreator(creator); } // end if else { document.addCreator(IHtmlToPdfTransformer.VERSION); } // end else final String author = (String) properties.get(IHtmlToPdfTransformer.PDF_AUTHOR); if (author != null) { document.addAuthor(author); } // end if final String sproducer = (String) properties.get(IHtmlToPdfTransformer.PDF_PRODUCER); if (sproducer != null) { document.add(new Meta("Producer", sproducer)); } // end if else { document.add(new Meta("Producer", (IHtmlToPdfTransformer.VERSION + " - http://www.allcolor.org/YaHPConverter/ - " + producer))); } // end else // step 3: we open the document document.open(); } // end if PdfImportedPage page; for (int j = 0; j < n;) { ++j; totalPage++; mapSizeDoc.put("" + totalPage, "" + i); page = writer.getImportedPage(reader, j); writer.addPage(page); } // end for } // end for document.close(); out.flush(); out.close(); { final PdfReader reader = new PdfReader(tmp.getAbsolutePath()); ; final int n = reader.getNumberOfPages(); final PdfStamper stp = new PdfStamper(reader, out2); int i = 0; BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED); final CHtmlToPdfFlyingSaucerTransformer trans = new CHtmlToPdfFlyingSaucerTransformer(); while (i < n) { i++; int indexSize = Integer.parseInt((String) mapSizeDoc.get("" + i)); final int[] dsize = size[indexSize].getSize(); final int[] dmargin = size[indexSize].getMargin(); for (final Iterator it = hf.iterator(); it.hasNext();) { final CHeaderFooter chf = (CHeaderFooter) it.next(); if (chf.getSfor().equals(CHeaderFooter.ODD_PAGES) && (i % 2 == 0)) { continue; } else if (chf.getSfor().equals(CHeaderFooter.EVEN_PAGES) && (i % 2 != 0)) { continue; } final String text = chf.getContent().replaceAll("<pagenumber>", "" + i) .replaceAll("<pagecount>", "" + n); // text over the existing page final PdfContentByte over = stp.getOverContent(i); final ByteArrayOutputStream bbout = new ByteArrayOutputStream(); if (chf.getType().equals(CHeaderFooter.HEADER)) { trans.transform(new ByteArrayInputStream(text.getBytes("utf-8")), base_url, new PageSize(dsize[0] - (dmargin[0] + dmargin[1]), dmargin[3]), new ArrayList(), properties, bbout); } else if (chf.getType().equals(CHeaderFooter.FOOTER)) { trans.transform(new ByteArrayInputStream(text.getBytes("utf-8")), base_url, new PageSize(dsize[0] - (dmargin[0] + dmargin[1]), dmargin[2]), new ArrayList(), properties, bbout); } final PdfReader readerHF = new PdfReader(bbout.toByteArray()); if (chf.getType().equals(CHeaderFooter.HEADER)) { over.addTemplate(stp.getImportedPage(readerHF, 1), dmargin[0], dsize[1] - dmargin[3]); } else if (chf.getType().equals(CHeaderFooter.FOOTER)) { over.addTemplate(stp.getImportedPage(readerHF, 1), dmargin[0], 0); } readerHF.close(); } } stp.close(); } try { out2.flush(); } catch (Exception ignore) { } finally { try { out2.close(); } catch (Exception ignore) { } } if (signed) { final String keypassword = (String) properties .get(IHtmlToPdfTransformer.PDF_SIGNING_PRIVATE_KEY_PASSWORD); final String password = (String) properties.get(IHtmlToPdfTransformer.PDF_ENCRYPTION_PASSWORD); final String keyStorepassword = (String) properties .get(IHtmlToPdfTransformer.PDF_SIGNING_KEYSTORE_PASSWORD); final String privateKeyFile = (String) properties .get(IHtmlToPdfTransformer.PDF_SIGNING_PRIVATE_KEY_FILE); final String reason = (String) properties.get(IHtmlToPdfTransformer.PDF_SIGNING_REASON); final String location = (String) properties.get(IHtmlToPdfTransformer.PDF_SIGNING_LOCATION); final boolean selfSigned = !"false" .equals(properties.get(IHtmlToPdfTransformer.USE_PDF_SELF_SIGNING)); PdfReader reader = null; if (password != null) { reader = new PdfReader(tmp2.getAbsolutePath(), password.getBytes()); } // end if else { reader = new PdfReader(tmp2.getAbsolutePath()); } // end else final KeyStore ks = selfSigned ? KeyStore.getInstance(KeyStore.getDefaultType()) : KeyStore.getInstance("pkcs12"); ks.load(new FileInputStream(privateKeyFile), keyStorepassword.toCharArray()); final String alias = (String) ks.aliases().nextElement(); final PrivateKey key = (PrivateKey) ks.getKey(alias, keypassword.toCharArray()); final Certificate chain[] = ks.getCertificateChain(alias); final PdfStamper stp = PdfStamper.createSignature(reader, oldOut, '\0'); if ("true".equals(properties.get(IHtmlToPdfTransformer.USE_PDF_ENCRYPTION))) { stp.setEncryption(PdfWriter.STANDARD_ENCRYPTION_128, password, null, CDocumentReconstructor.getSecurityFlags(properties)); } // end if final PdfSignatureAppearance sap = stp.getSignatureAppearance(); if (selfSigned) { sap.setCrypto(key, chain, null, PdfSignatureAppearance.SELF_SIGNED); } // end if else { sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); } // end else if (reason != null) { sap.setReason(reason); } // end if if (location != null) { sap.setLocation(location); } // end if stp.close(); oldOut.flush(); } // end if } // end try catch (final Exception e) { throw new CConvertException( "ERROR: An Exception occured while reconstructing the pdf document: " + e.getMessage(), e); } // end catch finally { try { tmp.delete(); } // end try catch (final Exception ignore) { } try { tmp2.delete(); } // end try catch (final Exception ignore) { } } // end finally }
From source file:org.apache.ofbiz.content.survey.PdfSurveyServices.java
License:Apache License
/** * *///from w w w. j a v a 2 s . com public static Map<String, Object> buildSurveyFromPdf(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); String surveyId = null; try { String surveyName = (String) context.get("surveyName"); ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteBuffer byteBuffer = getInputByteBuffer(context, delegator); PdfReader pdfReader = new PdfReader(byteBuffer.array()); PdfStamper pdfStamper = new PdfStamper(pdfReader, os); AcroFields acroFields = pdfStamper.getAcroFields(); Map<String, Object> acroFieldMap = UtilGenerics.checkMap(acroFields.getFields()); String contentId = (String) context.get("contentId"); GenericValue survey = null; surveyId = (String) context.get("surveyId"); if (UtilValidate.isEmpty(surveyId)) { survey = delegator.makeValue("Survey", UtilMisc.toMap("surveyName", surveyName)); survey.set("surveyId", surveyId); survey.set("allowMultiple", "Y"); survey.set("allowUpdate", "Y"); survey = delegator.createSetNextSeqId(survey); surveyId = survey.getString("surveyId"); } // create a SurveyQuestionCategory to put the questions in Map<String, Object> createCategoryResultMap = dispatcher.runSync("createSurveyQuestionCategory", UtilMisc.<String, Object>toMap("description", "From AcroForm in Content [" + contentId + "] for Survey [" + surveyId + "]", "userLogin", userLogin)); String surveyQuestionCategoryId = (String) createCategoryResultMap.get("surveyQuestionCategoryId"); pdfStamper.setFormFlattening(true); for (String fieldName : acroFieldMap.keySet()) { AcroFields.Item item = acroFields.getFieldItem(fieldName); int type = acroFields.getFieldType(fieldName); String value = acroFields.getField(fieldName); Debug.logInfo("fieldName:" + fieldName + "; item: " + item + "; value: " + value, module); GenericValue surveyQuestion = delegator.makeValue("SurveyQuestion", UtilMisc.toMap("question", fieldName)); String surveyQuestionId = delegator.getNextSeqId("SurveyQuestion"); surveyQuestion.set("surveyQuestionId", surveyQuestionId); surveyQuestion.set("surveyQuestionCategoryId", surveyQuestionCategoryId); if (type == AcroFields.FIELD_TYPE_TEXT) { surveyQuestion.set("surveyQuestionTypeId", "TEXT_SHORT"); } else if (type == AcroFields.FIELD_TYPE_RADIOBUTTON) { surveyQuestion.set("surveyQuestionTypeId", "OPTION"); } else if (type == AcroFields.FIELD_TYPE_LIST || type == AcroFields.FIELD_TYPE_COMBO) { surveyQuestion.set("surveyQuestionTypeId", "OPTION"); // TODO: handle these specially with the acroFields.getListOptionDisplay (and getListOptionExport?) } else { surveyQuestion.set("surveyQuestionTypeId", "TEXT_SHORT"); Debug.logWarning("Building Survey from PDF, fieldName=[" + fieldName + "]: don't know how to handle field type: " + type + "; defaulting to short text", module); } // ==== create a good sequenceNum based on tab order or if no tab order then the page location Integer tabPage = item.getPage(0); Integer tabOrder = item.getTabOrder(0); Debug.logInfo("tabPage=" + tabPage + ", tabOrder=" + tabOrder, module); //array of float multiple of 5. For each of this groups the values are: [page, llx, lly, urx, ury] float[] fieldPositions = acroFields.getFieldPositions(fieldName); float fieldPage = fieldPositions[0]; float fieldLlx = fieldPositions[1]; float fieldLly = fieldPositions[2]; float fieldUrx = fieldPositions[3]; float fieldUry = fieldPositions[4]; Debug.logInfo("fieldPage=" + fieldPage + ", fieldLlx=" + fieldLlx + ", fieldLly=" + fieldLly + ", fieldUrx=" + fieldUrx + ", fieldUry=" + fieldUry, module); Long sequenceNum = null; if (tabPage != null && tabOrder != null) { sequenceNum = Long.valueOf(tabPage.intValue() * 1000 + tabOrder.intValue()); Debug.logInfo("tabPage=" + tabPage + ", tabOrder=" + tabOrder + ", sequenceNum=" + sequenceNum, module); } else if (fieldPositions.length > 0) { sequenceNum = Long.valueOf((long) fieldPage * 10000 + (long) fieldLly * 1000 + (long) fieldLlx); Debug.logInfo("fieldPage=" + fieldPage + ", fieldLlx=" + fieldLlx + ", fieldLly=" + fieldLly + ", fieldUrx=" + fieldUrx + ", fieldUry=" + fieldUry + ", sequenceNum=" + sequenceNum, module); } // TODO: need to find something better to put into these fields... String annotation = null; for (int k = 0; k < item.size(); ++k) { PdfDictionary dict = item.getWidget(k); // if the "/Type" value is "/Annot", then get the value of "/TU" for the annotation PdfObject typeValue = null; PdfObject tuValue = null; Set<PdfName> dictKeys = UtilGenerics.checkSet(dict.getKeys()); for (PdfName dictKeyName : dictKeys) { PdfObject dictObject = dict.get(dictKeyName); if ("/Type".equals(dictKeyName.toString())) { typeValue = dictObject; } else if ("/TU".equals(dictKeyName.toString())) { tuValue = dictObject; } } if (tuValue != null && typeValue != null && "/Annot".equals(typeValue.toString())) { annotation = tuValue.toString(); } } surveyQuestion.set("description", fieldName); if (UtilValidate.isNotEmpty(annotation)) { surveyQuestion.set("question", annotation); } else { surveyQuestion.set("question", fieldName); } GenericValue surveyQuestionAppl = delegator.makeValue("SurveyQuestionAppl", UtilMisc.toMap("surveyId", surveyId, "surveyQuestionId", surveyQuestionId)); surveyQuestionAppl.set("fromDate", nowTimestamp); surveyQuestionAppl.set("externalFieldRef", fieldName); if (sequenceNum != null) { surveyQuestionAppl.set("sequenceNum", sequenceNum); } surveyQuestion.create(); surveyQuestionAppl.create(); } pdfStamper.close(); if (UtilValidate.isNotEmpty(contentId)) { survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId).queryOne(); survey.set("acroFormContentId", contentId); survey.store(); } } catch (GenericEntityException e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } catch (GeneralException e) { Debug.logError(e, "Error generating PDF: " + e.getMessage(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } catch (Exception e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("surveyId", surveyId); return results; }
From source file:org.apache.ofbiz.content.survey.PdfSurveyServices.java
License:Apache License
/** * */// www .ja v a 2s . c o m public static Map<String, Object> buildSurveyResponseFromPdf(DispatchContext dctx, Map<String, ? extends Object> context) { String surveyResponseId = null; Locale locale = (Locale) context.get("locale"); try { Delegator delegator = dctx.getDelegator(); String partyId = (String) context.get("partyId"); String surveyId = (String) context.get("surveyId"); surveyResponseId = (String) context.get("surveyResponseId"); if (UtilValidate.isNotEmpty(surveyResponseId)) { GenericValue surveyResponse = EntityQuery.use(delegator).from("SurveyResponse") .where("surveyResponseId", surveyResponseId).queryOne(); if (surveyResponse != null) { surveyId = surveyResponse.getString("surveyId"); } } else { surveyResponseId = delegator.getNextSeqId("SurveyResponse"); GenericValue surveyResponse = delegator.makeValue("SurveyResponse", UtilMisc .toMap("surveyResponseId", surveyResponseId, "surveyId", surveyId, "partyId", partyId)); surveyResponse.set("responseDate", UtilDateTime.nowTimestamp()); surveyResponse.set("lastModifiedDate", UtilDateTime.nowTimestamp()); surveyResponse.create(); } ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteBuffer byteBuffer = getInputByteBuffer(context, delegator); PdfReader r = new PdfReader(byteBuffer.array()); PdfStamper s = new PdfStamper(r, os); AcroFields fs = s.getAcroFields(); Map<String, Object> hm = UtilGenerics.checkMap(fs.getFields()); s.setFormFlattening(true); for (String fieldName : hm.keySet()) { //AcroFields.Item item = fs.getFieldItem(fieldName); String value = fs.getField(fieldName); GenericValue surveyQuestionAndAppl = EntityQuery.use(delegator).from("SurveyQuestionAndAppl") .where("surveyId", surveyId, "externalFieldRef", fieldName).queryFirst(); if (surveyQuestionAndAppl == null) { Debug.logInfo( "No question found for surveyId:" + surveyId + " and externalFieldRef:" + fieldName, module); continue; } String surveyQuestionId = (String) surveyQuestionAndAppl.get("surveyQuestionId"); String surveyQuestionTypeId = (String) surveyQuestionAndAppl.get("surveyQuestionTypeId"); GenericValue surveyResponseAnswer = delegator.makeValue("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId, "surveyQuestionId", surveyQuestionId)); if (surveyQuestionTypeId == null || surveyQuestionTypeId.equals("TEXT_SHORT")) { surveyResponseAnswer.set("textResponse", value); } delegator.create(surveyResponseAnswer); } s.close(); } catch (GenericEntityException e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } catch (GeneralException e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } catch (Exception e) { Debug.logError(e, "Error generating PDF: " + e.toString(), module); return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPDFGeneratingError", UtilMisc.toMap("errorString", e.toString()), locale)); } Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("surveyResponseId", surveyResponseId); return results; }
From source file:org.apache.ofbiz.content.survey.PdfSurveyServices.java
License:Apache License
/** *//*from www . j a v a2s. c o m*/ public static Map<String, Object> setAcroFields(DispatchContext dctx, Map<String, ? extends Object> context) { Map<String, Object> results = ServiceUtil.returnSuccess(); Delegator delegator = dctx.getDelegator(); try { Map<String, Object> acroFieldMap = UtilGenerics.checkMap(context.get("acroFieldMap")); ByteBuffer byteBuffer = getInputByteBuffer(context, delegator); PdfReader r = new PdfReader(byteBuffer.array()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfStamper s = new PdfStamper(r, baos); AcroFields fs = s.getAcroFields(); Map<String, Object> map = UtilGenerics.checkMap(fs.getFields()); s.setFormFlattening(true); for (String fieldName : map.keySet()) { String fieldValue = fs.getField(fieldName); Object obj = acroFieldMap.get(fieldName); if (obj instanceof Date) { Date d = (Date) obj; fieldValue = UtilDateTime.toDateString(d); } else if (obj instanceof Long) { Long lg = (Long) obj; fieldValue = lg.toString(); } else if (obj instanceof Integer) { Integer ii = (Integer) obj; fieldValue = ii.toString(); } else { fieldValue = (String) obj; } if (UtilValidate.isNotEmpty(fieldValue)) { fs.setField(fieldName, fieldValue); } } s.close(); baos.close(); ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray()); results.put("outByteBuffer", outByteBuffer); } catch (DocumentException e) { System.err.println(e.getMessage()); results = ServiceUtil.returnError(e.getMessage()); } catch (GeneralException e) { System.err.println(e.getMessage()); results = ServiceUtil.returnError(e.getMessage()); } catch (FileNotFoundException e) { System.err.println(e.getMessage()); results = ServiceUtil.returnError(e.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); results = ServiceUtil.returnError(ioe.getMessage()); } catch (Exception ioe) { System.err.println(ioe.getMessage()); results = ServiceUtil.returnError(ioe.getMessage()); } return results; }
From source file:org.fenixedu.idcards.ui.candidacydocfiller.BPIPdfFiller.java
License:Open Source License
private ByteArrayOutputStream getFilledPdfBPICardAEIST(Person person) throws IOException, DocumentException { InputStream istream = getClass().getResourceAsStream(BPI_AEIST_CARD_PDF_PATH); PdfReader reader = new PdfReader(istream); reader.getAcroForm().remove(PdfName.SIGFLAGS); ByteArrayOutputStream output = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, output); form = stamper.getAcroFields();/*from w w w .j a va 2s .c o m*/ setField("BI/CC", person.getDocumentIdNumber()); setField("Nome", person.getName()); setField("topmostSubform[0].Page1[0].Datavalidade[0]", person.getExpirationDateOfDocumentIdYearMonthDay() .toString(DateTimeFormat.forPattern("dd/MM/yyyy"))); setField("dia", String.format("%02d", person.getExpirationDateOfDocumentIdYearMonthDay().getDayOfMonth())); setField("Ms", String.format("%02d", person.getExpirationDateOfDocumentIdYearMonthDay().getMonthOfYear())); setField("Ano", String.valueOf(person.getExpirationDateOfDocumentIdYearMonthDay().getYear())); stamper.setFormFlattening(true); stamper.close(); return output; }
From source file:org.fenixedu.idcards.ui.candidacydocfiller.BPIPdfFiller.java
License:Open Source License
private ByteArrayOutputStream getFilledPdfBPIDigitalDoc(Person person) throws IOException, DocumentException { InputStream istream = getClass().getResourceAsStream(BPI_DIGITAL_DOCUMENTATION_PDF_PATH); PdfReader reader = new PdfReader(istream); reader.getAcroForm().remove(PdfName.SIGFLAGS); //reader.selectPages("1"); ByteArrayOutputStream output = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, output); form = stamper.getAcroFields();//from www .j a v a2 s .co m setField("Text1", person.getName()); stamper.setFormFlattening(true); stamper.close(); return output; }