List of usage examples for com.lowagie.text Image getInstance
public static Image getInstance(Image image)
From source file:net.sf.jsignpdf.SignerLogic.java
License:Mozilla Public License
/** * Signs a single file.//from w w w . j a v a2 s. c om * * @return true when signing is finished succesfully, false otherwise */ public boolean signFile() { final String outFile = options.getOutFileX(); if (!validateInOutFiles(options.getInFile(), outFile)) { LOGGER.info(RES.get("console.skippingSigning")); return false; } boolean finished = false; Throwable tmpException = null; FileOutputStream fout = null; try { SSLInitializer.init(options); final PrivateKeyInfo pkInfo = KeyStoreUtils.getPkInfo(options); final PrivateKey key = pkInfo.getKey(); final Certificate[] chain = pkInfo.getChain(); if (ArrayUtils.isEmpty(chain)) { // the certificate was not found LOGGER.info(RES.get("console.certificateChainEmpty")); return false; } LOGGER.info(RES.get("console.createPdfReader", options.getInFile())); PdfReader reader; try { reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStrX().getBytes()); } catch (Exception e) { try { reader = new PdfReader(options.getInFile(), new byte[0]); } catch (Exception e2) { // try to read without password reader = new PdfReader(options.getInFile()); } } LOGGER.info(RES.get("console.createOutPdf", outFile)); fout = new FileOutputStream(outFile); final HashAlgorithm hashAlgorithm = options.getHashAlgorithmX(); LOGGER.info(RES.get("console.createSignature")); char tmpPdfVersion = '\0'; // default version - the same as input if (reader.getPdfVersion() < hashAlgorithm.getPdfVersion()) { // this covers also problems with visible signatures (embedded // fonts) in PDF 1.2, because the minimal version // for hash algorithms is 1.3 (for SHA1) if (options.isAppendX()) { // if we are in append mode and version should be updated // then return false (not possible) LOGGER.info(RES.get("console.updateVersionNotPossibleInAppendMode")); return false; } tmpPdfVersion = hashAlgorithm.getPdfVersion(); LOGGER.info(RES.get("console.updateVersion", new String[] { String.valueOf(reader.getPdfVersion()), String.valueOf(tmpPdfVersion) })); } final PdfStamper stp = PdfStamper.createSignature(reader, fout, tmpPdfVersion, null, options.isAppendX()); if (!options.isAppendX()) { // we are not in append mode, let's remove existing signatures // (otherwise we're getting to troubles) final AcroFields acroFields = stp.getAcroFields(); @SuppressWarnings("unchecked") final List<String> sigNames = acroFields.getSignatureNames(); for (String sigName : sigNames) { acroFields.removeField(sigName); } } if (options.isAdvanced() && options.getPdfEncryption() != PDFEncryption.NONE) { LOGGER.info(RES.get("console.setEncryption")); final int tmpRight = options.getRightPrinting().getRight() | (options.isRightCopy() ? PdfWriter.ALLOW_COPY : 0) | (options.isRightAssembly() ? PdfWriter.ALLOW_ASSEMBLY : 0) | (options.isRightFillIn() ? PdfWriter.ALLOW_FILL_IN : 0) | (options.isRightScreanReaders() ? PdfWriter.ALLOW_SCREENREADERS : 0) | (options.isRightModifyAnnotations() ? PdfWriter.ALLOW_MODIFY_ANNOTATIONS : 0) | (options.isRightModifyContents() ? PdfWriter.ALLOW_MODIFY_CONTENTS : 0); switch (options.getPdfEncryption()) { case PASSWORD: stp.setEncryption(true, options.getPdfUserPwdStr(), options.getPdfOwnerPwdStrX(), tmpRight); break; case CERTIFICATE: final X509Certificate encCert = KeyStoreUtils .loadCertificate(options.getPdfEncryptionCertFile()); if (encCert == null) { LOGGER.error(RES.get("console.pdfEncError.wrongCertificateFile", StringUtils.defaultString(options.getPdfEncryptionCertFile()))); return false; } if (!KeyStoreUtils.isEncryptionSupported(encCert)) { LOGGER.error(RES.get("console.pdfEncError.cantUseCertificate", encCert.getSubjectDN().getName())); return false; } stp.setEncryption(new Certificate[] { encCert }, new int[] { tmpRight }, PdfWriter.ENCRYPTION_AES_128); break; default: LOGGER.error(RES.get("console.unsupportedEncryptionType")); return false; } } final PdfSignatureAppearance sap = stp.getSignatureAppearance(); sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); final String reason = options.getReason(); if (StringUtils.isNotEmpty(reason)) { LOGGER.info(RES.get("console.setReason", reason)); sap.setReason(reason); } final String location = options.getLocation(); if (StringUtils.isNotEmpty(location)) { LOGGER.info(RES.get("console.setLocation", location)); sap.setLocation(location); } final String contact = options.getContact(); if (StringUtils.isNotEmpty(contact)) { LOGGER.info(RES.get("console.setContact", contact)); sap.setContact(contact); } LOGGER.info(RES.get("console.setCertificationLevel")); sap.setCertificationLevel(options.getCertLevelX().getLevel()); if (options.isVisible()) { // visible signature is enabled LOGGER.info(RES.get("console.configureVisible")); LOGGER.info(RES.get("console.setAcro6Layers", Boolean.toString(options.isAcro6Layers()))); sap.setAcro6Layers(options.isAcro6Layers()); final String tmpImgPath = options.getImgPath(); if (tmpImgPath != null) { LOGGER.info(RES.get("console.createImage", tmpImgPath)); final Image img = Image.getInstance(tmpImgPath); LOGGER.info(RES.get("console.setSignatureGraphic")); sap.setSignatureGraphic(img); } final String tmpBgImgPath = options.getBgImgPath(); if (tmpBgImgPath != null) { LOGGER.info(RES.get("console.createImage", tmpBgImgPath)); final Image img = Image.getInstance(tmpBgImgPath); LOGGER.info(RES.get("console.setImage")); sap.setImage(img); } LOGGER.info(RES.get("console.setImageScale")); sap.setImageScale(options.getBgImgScale()); LOGGER.info(RES.get("console.setL2Text")); final String signer = PdfPKCS7.getSubjectFields((X509Certificate) chain[0]).getField("CN"); final String timestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z") .format(sap.getSignDate().getTime()); if (options.getL2Text() != null) { final Map<String, String> replacements = new HashMap<String, String>(); replacements.put(L2TEXT_PLACEHOLDER_SIGNER, StringUtils.defaultString(signer)); replacements.put(L2TEXT_PLACEHOLDER_TIMESTAMP, timestamp); replacements.put(L2TEXT_PLACEHOLDER_LOCATION, StringUtils.defaultString(location)); replacements.put(L2TEXT_PLACEHOLDER_REASON, StringUtils.defaultString(reason)); replacements.put(L2TEXT_PLACEHOLDER_CONTACT, StringUtils.defaultString(contact)); final String l2text = StrSubstitutor.replace(options.getL2Text(), replacements); sap.setLayer2Text(l2text); } else { final StringBuilder buf = new StringBuilder(); buf.append(RES.get("default.l2text.signedBy")).append(" ").append(signer).append('\n'); buf.append(RES.get("default.l2text.date")).append(" ").append(timestamp); if (StringUtils.isNotEmpty(reason)) buf.append('\n').append(RES.get("default.l2text.reason")).append(" ").append(reason); if (StringUtils.isNotEmpty(location)) buf.append('\n').append(RES.get("default.l2text.location")).append(" ").append(location); sap.setLayer2Text(buf.toString()); } if (FontUtils.getL2BaseFont() != null) { sap.setLayer2Font(new Font(FontUtils.getL2BaseFont(), options.getL2TextFontSize())); } LOGGER.info(RES.get("console.setL4Text")); sap.setLayer4Text(options.getL4Text()); LOGGER.info(RES.get("console.setRender")); RenderMode renderMode = options.getRenderMode(); if (renderMode == RenderMode.GRAPHIC_AND_DESCRIPTION && sap.getSignatureGraphic() == null) { LOGGER.warn( "Render mode of visible signature is set to GRAPHIC_AND_DESCRIPTION, but no image is loaded. Fallback to DESCRIPTION_ONLY."); LOGGER.info(RES.get("console.renderModeFallback")); renderMode = RenderMode.DESCRIPTION_ONLY; } sap.setRender(renderMode.getRender()); LOGGER.info(RES.get("console.setVisibleSignature")); int page = options.getPage(); if (page < 1 || page > reader.getNumberOfPages()) { page = reader.getNumberOfPages(); } sap.setVisibleSignature(new Rectangle(options.getPositionLLX(), options.getPositionLLY(), options.getPositionURX(), options.getPositionURY()), page, null); } LOGGER.info(RES.get("console.processing")); final PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName("adbe.pkcs7.detached")); if (!StringUtils.isEmpty(reason)) { dic.setReason(sap.getReason()); } if (!StringUtils.isEmpty(location)) { dic.setLocation(sap.getLocation()); } if (!StringUtils.isEmpty(contact)) { dic.setContact(sap.getContact()); } dic.setDate(new PdfDate(sap.getSignDate())); sap.setCryptoDictionary(dic); final Proxy tmpProxy = options.createProxy(); final CRLInfo crlInfo = new CRLInfo(options, chain); // CRLs are stored twice in PDF c.f. // PdfPKCS7.getAuthenticatedAttributeBytes final int contentEstimated = (int) (Constants.DEFVAL_SIG_SIZE + 2L * crlInfo.getByteCount()); final Map<PdfName, Integer> exc = new HashMap<PdfName, Integer>(); exc.put(PdfName.CONTENTS, new Integer(contentEstimated * 2 + 2)); sap.preClose(exc); PdfPKCS7 sgn = new PdfPKCS7(key, chain, crlInfo.getCrls(), hashAlgorithm.getAlgorithmName(), null, false); InputStream data = sap.getRangeStream(); final MessageDigest messageDigest = MessageDigest.getInstance(hashAlgorithm.getAlgorithmName()); byte buf[] = new byte[8192]; int n; while ((n = data.read(buf)) > 0) { messageDigest.update(buf, 0, n); } byte hash[] = messageDigest.digest(); Calendar cal = Calendar.getInstance(); byte[] ocsp = null; if (options.isOcspEnabledX() && chain.length >= 2) { LOGGER.info(RES.get("console.getOCSPURL")); String url = PdfPKCS7.getOCSPURL((X509Certificate) chain[0]); if (StringUtils.isEmpty(url)) { // get from options LOGGER.info(RES.get("console.noOCSPURL")); url = options.getOcspServerUrl(); } if (!StringUtils.isEmpty(url)) { LOGGER.info(RES.get("console.readingOCSP", url)); final OcspClientBouncyCastle ocspClient = new OcspClientBouncyCastle((X509Certificate) chain[0], (X509Certificate) chain[1], url); ocspClient.setProxy(tmpProxy); ocsp = ocspClient.getEncoded(); } } byte sh[] = sgn.getAuthenticatedAttributeBytes(hash, cal, ocsp); sgn.update(sh, 0, sh.length); TSAClientBouncyCastle tsc = null; if (options.isTimestampX() && !StringUtils.isEmpty(options.getTsaUrl())) { LOGGER.info(RES.get("console.creatingTsaClient")); if (options.getTsaServerAuthn() == ServerAuthentication.PASSWORD) { tsc = new TSAClientBouncyCastle(options.getTsaUrl(), StringUtils.defaultString(options.getTsaUser()), StringUtils.defaultString(options.getTsaPasswd())); } else { tsc = new TSAClientBouncyCastle(options.getTsaUrl()); } final String tsaHashAlg = options.getTsaHashAlgWithFallback(); LOGGER.info(RES.get("console.settingTsaHashAlg", tsaHashAlg)); tsc.setHashAlgorithm(tsaHashAlg); tsc.setProxy(tmpProxy); final String policyOid = options.getTsaPolicy(); if (StringUtils.isNotEmpty(policyOid)) { LOGGER.info(RES.get("console.settingTsaPolicy", policyOid)); tsc.setPolicy(policyOid); } } byte[] encodedSig = sgn.getEncodedPKCS7(hash, cal, tsc, ocsp); if (contentEstimated + 2 < encodedSig.length) { System.err.println( "SigSize - contentEstimated=" + contentEstimated + ", sigLen=" + encodedSig.length); throw new Exception("Not enough space"); } byte[] paddedSig = new byte[contentEstimated]; System.arraycopy(encodedSig, 0, paddedSig, 0, encodedSig.length); PdfDictionary dic2 = new PdfDictionary(); dic2.put(PdfName.CONTENTS, new PdfString(paddedSig).setHexWriting(true)); LOGGER.info(RES.get("console.closeStream")); sap.close(dic2); fout.close(); fout = null; finished = true; } catch (Exception e) { LOGGER.error(RES.get("console.exception"), e); } catch (OutOfMemoryError e) { LOGGER.fatal(RES.get("console.memoryError"), e); } finally { if (fout != null) { try { fout.close(); } catch (Exception e) { e.printStackTrace(); } } LOGGER.info(RES.get("console.finished." + (finished ? "ok" : "error"))); options.fireSignerFinishedEvent(tmpException); } return finished; }
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 www.java2 s . com*/ 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:nl.knaw.dans.common.lang.pdf.ExtendedHtmlWorker.java
License:Apache License
public void startElement(String tag, HashMap h) { if (!tagsSupported.containsKey(tag)) return;// w ww .j a v a 2 s . c om try { style.applyStyle(tag, h); String follow = (String) FactoryProperties.followTags.get(tag); if (follow != null) { HashMap prop = new HashMap(); prop.put(follow, null); cprops.addToChain(follow, prop); return; } FactoryProperties.insertStyle(h); if (tag.equals("a")) { cprops.addToChain(tag, h); if (currentParagraph == null) currentParagraph = new Paragraph(); stack.push(currentParagraph); currentParagraph = new Paragraph(); return; } if (tag.equals("br")) { if (currentParagraph == null) currentParagraph = new Paragraph(); currentParagraph.add(factoryProperties.createChunk("\n", cprops)); return; } if (tag.equals("font") || tag.equals("span")) { cprops.addToChain(tag, h); return; } if (tag.equals("img")) { String src = (String) h.get("src"); if (src == null) return; cprops.addToChain(tag, h); Image img = null; if (interfaceProps != null) { ImageProvider ip = (ImageProvider) interfaceProps.get("img_provider"); if (ip != null) img = ip.getImage(src, h, cprops, document); if (img == null) { HashMap images = (HashMap) interfaceProps.get("img_static"); if (images != null) { Image tim = (Image) images.get(src); if (tim != null) img = Image.getInstance(tim); } else { if (!src.startsWith("http")) { // relative src references only String baseurl = (String) interfaceProps.get("img_baseurl"); if (baseurl != null) { src = baseurl + src; img = Image.getInstance(src); } } } } } if (img == null) { if (!src.startsWith("http")) { String path = cprops.getProperty("image_path"); if (path == null) path = ""; src = new File(path, src).getPath(); } img = Image.getInstance(src); } String align = (String) h.get("align"); String width = (String) h.get("width"); String height = (String) h.get("height"); String before = cprops.getProperty("before"); String after = cprops.getProperty("after"); if (before != null) img.setSpacingBefore(Float.parseFloat(before)); if (after != null) img.setSpacingAfter(Float.parseFloat(after)); float wp = lengthParse(width, (int) img.getWidth()); float lp = lengthParse(height, (int) img.getHeight()); if (wp > 0 && lp > 0) img.scalePercent(wp > lp ? lp : wp); else if (wp > 0) img.scalePercent(wp); else if (lp > 0) img.scalePercent(lp); img.setWidthPercentage(0); if (align != null) { endElement("p"); int ralign = Image.MIDDLE; if (align.equalsIgnoreCase("left")) ralign = Image.LEFT; else if (align.equalsIgnoreCase("right")) ralign = Image.RIGHT; img.setAlignment(ralign); Img i = null; boolean skip = false; if (interfaceProps != null) { i = (Img) interfaceProps.get("img_interface"); if (i != null) skip = i.process(img, h, cprops, document); } if (!skip) document.add(img); cprops.removeChain(tag); } else { cprops.removeChain(tag); if (currentParagraph == null) currentParagraph = FactoryProperties.createParagraph(cprops); currentParagraph.add(new Chunk(img, 0, 0)); } return; } endElement("p"); if (tag.equals("h1") || tag.equals("h2") || tag.equals("h3") || tag.equals("h4") || tag.equals("h5") || tag.equals("h6")) { if (!h.containsKey("size")) { int v = 7 - Integer.parseInt(tag.substring(1)); h.put("size", Integer.toString(v)); } cprops.addToChain(tag, h); return; } if (tag.equals("ul")) { if (pendingLI) endElement("li"); skipText = true; cprops.addToChain(tag, h); com.lowagie.text.List list = new com.lowagie.text.List(false, 10); list.setListSymbol("\u2022"); String indent = ((String) h.get("indent")); if (indent != null && indent.matches("[0-9]+")) { list.setSymbolIndent(Integer.valueOf(indent)); } stack.push(list); return; } if (tag.equals("ol")) { if (pendingLI) endElement("li"); skipText = true; cprops.addToChain(tag, h); com.lowagie.text.List list = new com.lowagie.text.List(true, 10); String type = ((String) h.get("type")); if (type != null && type.toLowerCase().equals("a")) { list.setLettered(true); list.setNumbered(false); list.setLowercase(type.equals("a")); } String indent = ((String) h.get("indent")); if (indent != null && indent.matches("[0-9]+")) { list.setSymbolIndent(Integer.valueOf(indent)); } stack.push(list); return; } if (tag.equals("li")) { if (pendingLI) endElement("li"); skipText = false; pendingLI = true; cprops.addToChain(tag, h); stack.push(FactoryProperties.createListItem(cprops)); return; } if (tag.equals("div") || tag.equals("body")) { cprops.addToChain(tag, h); return; } if (tag.equals("pre")) { if (!h.containsKey("face")) { h.put("face", "Courier"); } cprops.addToChain(tag, h); isPRE = true; return; } if (tag.equals("p")) { cprops.addToChain(tag, h); currentParagraph = FactoryProperties.createParagraph(h); return; } if (tag.equals("tr")) { if (pendingTR) endElement("tr"); skipText = true; pendingTR = true; cprops.addToChain("tr", h); return; } if (tag.equals("td") || tag.equals("th")) { if (pendingTD) endElement(tag); skipText = false; pendingTD = true; cprops.addToChain("td", h); stack.push(new IncCell(tag, cprops)); return; } if (tag.equals("table")) { cprops.addToChain("table", h); IncTable table = new IncTable(h); stack.push(table); tableState.push(new boolean[] { pendingTR, pendingTD }); pendingTR = pendingTD = false; skipText = true; return; } } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java
License:Apache License
public void setHeaderImage(final URL url) throws HeaderImageException { if (url == null) { headerImage = null;/*from ww w . j a v a 2s . c o m*/ return; } try { headerImage = Image.getInstance(url); } catch (final BadElementException e) { throw new HeaderImageException(url.toString(), e); } catch (final MalformedURLException e) { throw new HeaderImageException(url.toString(), e); } catch (final IOException e) { throw new HeaderImageException(url.toString(), e); } }
From source file:open.dolphin.hiro.PrescriptionPDFMaker.java
/** * ??/*from w w w. j a v a 2s . 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:optika.sql.java
public void eksportoNePdf(String id) { Document document = new Document() { };/*from www. jav a 2s . c o m*/ try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("receta.pdf")); document.open(); document.setPageSize(PageSize.A3); Image img = Image.getInstance("receta.jpg"); img.setAbsolutePosition(450f, 10f); img.scaleToFit(600, 849); img.setAlignment(Image.LEFT | Image.ALIGN_BOTTOM | Image.ALIGN_BASELINE); img.setAbsolutePosition(0, 0); document.add(img); String[][] receta = merrReceten("select * from recetat where id=" + parseInt(id) + ";"); String[][] tabela = merrReceten("select * from tabela where recetat_id=" + parseInt(id) + ";"); int[] white = new int[tabela.length]; for (int i = 0; i < tabela.length; i++) { white[i] = 0; int bosh = 0; for (int j = 3; j < tabela[i].length; j++) { if (tabela[i][j] == tabela[i][6]) { continue; } if (!tabela[i][j].isEmpty()) { bosh = 1; } } if (bosh == 0) { white[i] = 1; } } Paragraph data = new Paragraph("Data: " + receta[0][7]); data.setSpacingBefore(38); data.setSpacingAfter(40); PdfPTable table = new PdfPTable(7); if (white[0] == 0) { table.addCell(getCellPadding("" + tabela[0][3], 1)); } else { table.addCell(getCellWhite("_", 1, 30)); } table.addCell(getCellPadding("" + tabela[0][4], 1)); table.addCell(getCellPadding("" + tabela[0][5], 1)); table.addCell(getCellPadding("", 1)); table.addCell(getCellPadding("" + tabela[0][7], 1)); table.addCell(getCellPadding("" + tabela[0][8], 1)); table.addCell(getCellPadding("" + tabela[0][9], 1)); table.setWidthPercentage(105); table.setHorizontalAlignment(-100); if (white[1] == 0) { table.addCell(getCellPadding("" + tabela[1][3], 1)); } else { table.addCell(getCellWhite("_", 1, 36)); } table.addCell(getCellPadding("" + tabela[1][4], 1)); table.addCell(getCellPadding("" + tabela[1][5], 1)); table.addCell(getCellPadding("", 1)); table.addCell(getCellPadding("" + tabela[1][7], 1)); table.addCell(getCellPadding("" + tabela[1][8], 1)); table.addCell(getCellPadding("" + tabela[1][9], 1)); table.setWidthPercentage(105); table.setHorizontalAlignment(-100); if (white[2] == 0) { if (white[1] == 0) { table.addCell(getCell("" + tabela[2][3], 1, 30)); } else { table.addCell(getCellWhite("_", 1, 23)); } } else { table.addCell(getCellWhite("_", 1, 28)); } table.addCell(getCell("" + tabela[2][4], 1, 0)); table.addCell(getCell("" + tabela[2][5], 1, 0)); table.addCell(getCell("", 1, 0)); table.addCell(getCell("" + tabela[2][7], 1, 0)); table.addCell(getCell("" + tabela[2][8], 1, 0)); table.addCell(getCell("" + tabela[2][9], 1, 0)); table.setWidthPercentage(105); table.setSpacingBefore(27); table.setHorizontalAlignment(-100); String[][] distanca = merrReceten("select * from distanca where recetat_id=" + parseInt(id) + ";"); PdfPTable largAfer = new PdfPTable(3); if (distanca[0][3].isEmpty()) { PdfPCell larg = getCellWhite("_", 2, 15); largAfer.addCell(larg); } else { PdfPCell larg = new PdfPCell(new Phrase("" + distanca[0][3])); larg.setPadding(0); larg.setHorizontalAlignment(2); larg.setBorder(PdfPCell.NO_BORDER); larg.setPaddingBottom(20); largAfer.addCell(larg); } largAfer.addCell(getCell("", PdfPCell.ALIGN_RIGHT, 25)); if (distanca[0][8].isEmpty()) { largAfer.addCell(getCellWhite("_", PdfPCell.ALIGN_RIGHT, 15)); } else { largAfer.addCell(getCell("" + distanca[0][8], PdfPCell.ALIGN_RIGHT, 25)); } largAfer.setWidthPercentage(75); largAfer.setHorizontalAlignment(350); PdfPTable od_os = new PdfPTable(5); od_os.addCell(getCell("OD= " + distanca[0][4], 0, 195)); od_os.addCell(getCell("OS= " + distanca[0][5], 2, 195)); od_os.addCell(getCell("", 0, 0)); od_os.addCell(getCell("OD= " + distanca[0][9], 0, 0)); od_os.addCell(getCell("OS= " + distanca[0][10], 1, 0)); od_os.setWidthPercentage(90); od_os.setHorizontalAlignment(150); PdfPTable visusi = new PdfPTable(2); if (distanca[0][6].isEmpty()) { PdfPCell od_pa = getCellWhite("_", 2, 17); od_pa.setPaddingRight(45); visusi.addCell(od_pa); } else { PdfPCell od_pa = getCell(distanca[0][6], 2, 17); od_pa.setPaddingRight(45); visusi.addCell(od_pa); } if (distanca[0][11].isEmpty()) { visusi.addCell(getCellWhite("_", 2, 17)); } else { visusi.addCell(getCell(distanca[0][11], 2, 17)); } if (distanca[0][7].isEmpty()) { PdfPCell os_pa = getCellWhite("_", 2, 17); os_pa.setPaddingRight(45); visusi.addCell(os_pa); } else { PdfPCell os_pa = getCell(distanca[0][7], 2, 17); os_pa.setPaddingRight(45); visusi.addCell(os_pa); } if (distanca[0][12].isEmpty()) { visusi.addCell(getCellWhite("_", 2, 17)); } else { visusi.addCell(getCell(distanca[0][12], 2, 0)); } visusi.setWidthPercentage(100); visusi.setHorizontalAlignment(50); String[][] admin = merrReceten("select * from admin where id=1;"); PdfPTable klienti = new PdfPTable(3); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("Emri: " + receta[0][2], 0, 0)); klienti.addCell(getCell("Celular: " + admin[0][4], 0, 0)); klienti.addCell(getCell("", 0, 0)); PdfPCell celReceta = getCell("Celular: " + receta[0][4], 0, 0); celReceta.setPaddingTop(5); klienti.addCell(celReceta); klienti.addCell(getCell("Email: " + admin[0][5], 0, 0)); klienti.addCell(getCell("", 0, 0)); PdfPCell emailReceta = getCell("Email: " + receta[0][5], 0, 0); emailReceta.setPaddingBottom(5); emailReceta.setPaddingTop(5); klienti.addCell(emailReceta); klienti.addCell(getCell("Adresa: " + admin[0][6], 0, 0)); klienti.addCell(getCell("", 0, 0)); klienti.addCell(getCell("Adresa: " + receta[0][6], 0, 0)); klienti.setSpacingBefore(50); PdfPTable kreu = new PdfPTable(1); kreu.addCell(getCell(" ", 0, 0)); document.add(kreu); document.add(klienti); document.add(data); document.add(table); document.add(largAfer); document.add(od_os); document.add(visusi); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:org.activityinfo.server.report.renderer.itext.ItextImageRenderer.java
License:Open Source License
@Override public void render(DocWriter writer, Document doc, ImageReportElement element) throws DocumentException { if (element.getUrl() != null) { Image image = null;/*from w ww .j av a 2s . c om*/ try { image = Image.getInstance(element.getUrl()); doc.add(image); } catch (MalformedURLException e) { LOGGER.log(Level.WARNING, "Error rendering image", e); } catch (IOException e) { LOGGER.log(Level.WARNING, "Error rendering image", e); } } }
From source file:org.activityinfo.server.report.renderer.itext.ItextMapRenderer.java
License:Open Source License
@Override protected void drawIcon(Graphics2D g2d, IconMapMarker marker) { int x = marker.getX() - marker.getIcon().getAnchorX(); int y = marker.getY() - marker.getIcon().getAnchorY(); File imageFile = getImageFile(marker.getIcon().getName()); try {//from w ww . ja v a2 s . com Image image = Image.getInstance(imageFile.getAbsolutePath()); image.setAbsolutePosition(x, y); graphic.addImage(imageFile.toURI().toURL().toString(), x, y, marker.getIcon().getWidth(), marker.getIcon().getHeight()); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.activityinfo.server.report.renderer.itext.ItextMapRenderer.java
License:Open Source License
private Image createIconImage(IconLayerLegend legend) { try {//from w ww. j ava 2 s .c o m return Image.getInstance(getImageFile(legend.getDefinition().getIcon()).getAbsolutePath()); } catch (Exception e) { throw new RuntimeException("Can't create image for " + legend.getDefinition().getIcon()); } }
From source file:org.apache.maven.doxia.module.itext.ITextSink.java
License:Apache License
/** * If the <code>name</code> is a relative link, the internal link will used a System property * <code>itext.basedir</code>, or the class loader. * {@inheritDoc}/*from ww w . j a va 2 s.co m*/ */ public void figureGraphics(String name) { String urlName = null; File nameFile = null; if ((name.toLowerCase(Locale.ENGLISH).startsWith("http://")) || (name.toLowerCase(Locale.ENGLISH).startsWith("https://"))) { urlName = name; } else { if (System.getProperty("itext.basedir") != null) { try { nameFile = new File(System.getProperty("itext.basedir"), name); urlName = nameFile.toURI().toURL().toString(); } catch (MalformedURLException e) { getLog().error("MalformedURLException: " + e.getMessage(), e); } } else { if (getClassLoader() != null) { if (getClassLoader().getResource(name) != null) { urlName = getClassLoader().getResource(name).toString(); } } else { if (ITextSink.class.getClassLoader().getResource(name) != null) { urlName = ITextSink.class.getClassLoader().getResource(name).toString(); } } } } if (urlName == null) { String msg = "No image '" + name + "' found in the class loader. Try to call setClassLoader(ClassLoader) before."; logMessage("imageNotFound", msg); return; } if (nameFile != null && !nameFile.exists()) { String msg = "No image '" + nameFile + "' found in your system, check the path."; logMessage("imageNotFound", msg); return; } boolean figureCalled = figureDefined; if (!figureCalled) { figure(); } float width = 0; float height = 0; try { Image image = Image.getInstance(new URL(urlName)); image.scaleToFit(ITextUtil.getDefaultPageSize().width() / 2, ITextUtil.getDefaultPageSize().height() / 2); width = image.plainWidth(); height = image.plainHeight(); } catch (BadElementException e) { getLog().error("BadElementException: " + e.getMessage(), e); } catch (MalformedURLException e) { getLog().error("MalformedURLException: " + e.getMessage(), e); } catch (IOException e) { getLog().error("IOException: " + e.getMessage(), e); } writeAddAttribute(ElementTags.URL, urlName); writeAddAttribute(ElementTags.ALIGN, ElementTags.ALIGN_MIDDLE); writeAddAttribute(ElementTags.PLAINWIDTH, String.valueOf(width)); writeAddAttribute(ElementTags.PLAINHEIGHT, String.valueOf(height)); actionContext.setAction(SinkActionContext.FIGURE_GRAPHICS); if (!figureCalled) { figure_(); } }