<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                java 生成表格pdf文件 --- ```java package com.ucmed.auto.util; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Date; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Image; import com.itextpdf.text.PageSize; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import com.ucmed.common.util.DateUtil; import com.ucmed.model.User; public class PrescriptionPdfUtilThree { public static void main(String[] args) { try { String filePath = "E:/1.pdf"; OutputStream outputStream = new FileOutputStream(filePath); JSONObject patient = new JSONObject(); JSONObject diagnosis = new JSONObject(); patient.put("name", "宋小小"); patient.put("sex", "男"); patient.put("age", "24"); patient.put("treatment_card", "B14684090"); patient.put("phone", "13500000000"); patient.put("department", "呼吸內科"); diagnosis.put("before_diagnosis", "上呼吸道感染"); User user = new User(); user.setUserName("謝旭東"); user.setLoginName("7165"); createPdfContext(outputStream, patient, diagnosis, user, "E:/erCode2.png"); System.out.println("生成成功了"); } catch (Exception e) { System.out.println("生成失敗"); e.printStackTrace(); } } public static void createPdfContext(OutputStream out, JSONObject patient, JSONObject diagnosis, User user, String codePath) throws Exception { Document doc = new Document(PageSize.A4, 20, 20, 20, 20); Date currentDate = DateUtil.getCurrentDate(); Font font; // BaseFont bfChinese = BaseFont.createFont("D:/java/workspace-tjpt/tjpt/tjpt/WebContent/resources/simsun.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); // BaseFont bfChineseHuawen = BaseFont.createFont("D:/java/workspace-tjpt/tjpt/tjpt/WebContent/resources/huawenkt.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); BaseFont bfChinese = BaseFont.createFont("../../fonts/simsun.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); BaseFont bfChineseHuawen = BaseFont.createFont("../../fonts/huawenkt.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); PdfPCell cell; Image image; //ConfigService configService = (ConfigService) ApplicationContextUtil.getBean("configService"); PdfWriter.getInstance(doc, out); doc.open(); // 標題 font = new Font(bfChinese, 24, Font.BOLD); PdfPTable table = new PdfPTable(64); table.setWidthPercentage(95); PdfPTable table2 = new PdfPTable(11); cell = getPdfPCell(getTitleParagraph("浙江大學醫學院附屬第一醫院", font, Element.TITLE), Element.ALIGN_RIGHT, bfChinese, 10); cell.setVerticalAlignment(Element.ALIGN_CENTER); table2.addCell(cell); table2.addCell(getPdfPCell("", Element.ALIGN_RIGHT, bfChinese, 1)); cell = getPdfPCell(getTitleParagraph("互聯網院區處方箋", font, Element.TITLE), Element.ALIGN_RIGHT, bfChinese, 9); cell.setVerticalAlignment(Element.ALIGN_CENTER); table2.addCell(cell); table2.addCell(getPdfPCell("", Element.ALIGN_RIGHT, bfChinese, 2)); cell = new PdfPCell(table2); cell.setColspan(54); cell.setBorder(0); table.addCell(cell); //table2.addCell(getPdfPCell("", Element.TITLE, bfChinese, 3)); font = new Font(bfChinese, 18, Font.ITALIC); cell = getPdfPCell("普 通 處 方", Element.ALIGN_LEFT, bfChineseHuawen, 10, font); cell.setBorderColor(new BaseColor(120, 120, 120)); cell.setBorderWidthBottom(0.4f); cell.setBorderWidthTop(0.4f); cell.setBorderWidthLeft(0.4f); cell.setBorderWidthRight(0.4f); cell.setPaddingTop(-4f); cell.setPaddingLeft(6f); cell.setPaddingBottom(6f); table.addCell(cell); newlineTable(table, 24); doc.add(table); font = new Font(bfChinese, 11, Font.NORMAL); font.setColor(0, 0, 0); table = new PdfPTable(10); table.setWidthPercentage(89.6f); table.addCell(getPdfPCell("病歷號:", Element.ALIGN_LEFT, bfChinese, 5)); table.addCell(getPdfPCell("NO.H" + DateUtil.getyyyyMMdd(currentDate) + String.format("%03d", patient.optLong("id")), Element.ALIGN_RIGHT, bfChinese, 5)); doc.add(table); //1、姓名、性別、年齡、費別 table = new PdfPTable(8); table.setWidthPercentage(100); table.addCell(getPdfPCell("姓名:", Element.ALIGN_RIGHT, bfChinese, 1)); table.addCell(getPdfPCell(StringUtils.isNotBlank(patient.optString("name")) ? patient.optString("name") : "", Element.ALIGN_LEFT, bfChinese, 1)); table.addCell(getPdfPCell("性別:", Element.ALIGN_RIGHT, bfChinese, 1)); table.addCell(getPdfPCell(StringUtils.isNotBlank(patient.optString("sex")) ? patient.optString("sex") : "", Element.ALIGN_LEFT, bfChinese, 1)); table.addCell(getPdfPCell("年 齡:", Element.ALIGN_RIGHT, bfChinese, 1)); table.addCell(getPdfPCell(StringUtils.isNotBlank(patient.optString("age")) ? patient.optString("age") : "", Element.ALIGN_LEFT, bfChinese, 1)); table.addCell(getPdfPCell("費別:", Element.ALIGN_RIGHT, bfChinese, 1)); table.addCell(getPdfPCell("自費", Element.ALIGN_LEFT, bfChinese, 1)); doc.add(table); //2、就診卡號、科別 table = new PdfPTable(12); table.setWidthPercentage(100); table.addCell(getPdfPCell("就診卡號:", Element.ALIGN_RIGHT, bfChinese, 2)); table.addCell(getPdfPCell(StringUtils.isNotBlank(patient.optString("treatment_card")) ? patient.optString("treatment_card") : "", Element.ALIGN_LEFT, bfChinese, 4)); table.addCell(getPdfPCell("科別(床號):" + ( StringUtils.isNotBlank(patient.optString("department")) ? patient.optString("department") : "" ), Element.ALIGN_RIGHT, bfChinese, 5)); table.addCell(getPdfPCell("", Element.ALIGN_RIGHT, bfChinese, 1)); doc.add(table); //3、 地址、手機號 table = new PdfPTable(24); table.setWidthPercentage(90); table.addCell(getPdfPCell("地址:" + "", Element.ALIGN_LEFT, bfChinese, 14)); table.addCell(getPdfPCell("手機號:" + ( StringUtils.isNotBlank(patient.optString("phone")) ? patient.optString("phone") : "" ), Element.ALIGN_RIGHT, bfChinese, 9)); table.addCell(getPdfPCell("", Element.ALIGN_RIGHT, bfChinese, 1)); doc.add(table); //4、 臨床(初步)診斷 table = new PdfPTable(40); table.setWidthPercentage(90); table.addCell(getPdfPCell("臨床(初步)診斷:", Element.ALIGN_RIGHT, bfChinese, 9)); table.addCell(getPdfPCell(StringUtils.isNotBlank(diagnosis.optString("before_diagnose")) ? diagnosis.optString("before_diagnose").replace("@@", "、") : "", Element.ALIGN_LEFT, bfChinese, 31)); doc.add(table); //5、 過敏史 table = new PdfPTable(180); table.setWidthPercentage(90); table.addCell(getPdfPCell("過敏史:", Element.ALIGN_RIGHT, bfChinese, 19)); table.addCell(getPdfPCell(patient.optJSONObject("history") == null ? "" : patient.optJSONObject("history").optString("allergic_history"), Element.ALIGN_LEFT, bfChinese, 161)); doc.add(table); //5、 處方日期 table = new PdfPTable(6); table.setWidthPercentage(100); table.addCell(getPdfPCell("處方日期:", Element.ALIGN_RIGHT, bfChinese, 1)); table.addCell(getPdfPCell(DateUtil.getyyyy_MM_dd(currentDate), Element.ALIGN_LEFT, bfChinese, 5)); doc.add(table); //6、 Rp font = new Font(bfChinese, 26, Font.BOLD); font.setColor(0, 0, 0); doc.add(getTitleParagraph(" Rp", font, Element.ALIGN_LEFT)); doc.add(new Paragraph("\n")); //7、處方內容 table = new PdfPTable(12); table.setWidthPercentage(80); JSONArray drugList = diagnosis.optJSONArray("recipe_list") == null ? new JSONArray() : diagnosis.optJSONArray("recipe_list"); int nullCount = 0; for (int i = 0; i < drugList.size(); i++) { JSONObject drug = drugList.optJSONObject(i); if(drug == null) { nullCount++; continue; } table.addCell(getPdfPCell(drug.optString("name"), Element.ALIGN_LEFT, bfChineseHuawen, 10, new Font(bfChineseHuawen, 14, Font.BOLD))); table.addCell(getPdfPCell(drug.optString("sl") + drug.optString("sldw"), Element.ALIGN_LEFT, bfChineseHuawen, 2, new Font(bfChineseHuawen, 14, Font.BOLD))); table.addCell(getPdfPCell("用法:", Element.ALIGN_RIGHT, bfChineseHuawen, 2)); StringBuilder sbUsingMethod = new StringBuilder(); if(StringUtils.isNotBlank(drug.optString("jl"))) { sbUsingMethod.append("每次" + drug.optString("jl") + drug.optString("ypjldw")); } if(StringUtils.isNotBlank(drug.optString("day")) && StringUtils.isNotBlank(drug.optString("pc"))) { sbUsingMethod.append(" " + drug.optString("pc") + " " + drug.optString("day") + "天"); } if(StringUtils.isNotBlank(drug.optString("yf"))) { sbUsingMethod.append(" " + drug.optString("yf")); } table.addCell(getPdfPCell(sbUsingMethod.toString(), Element.ALIGN_LEFT, bfChineseHuawen, 10)); } doc.add(table); //添加 18 - 2n行 for(int i = 0; i < 16 - 2 * (drugList.size() - nullCount); i ++) { doc.add(new Paragraph("\n")); } //左側、簽名 table = new PdfPTable(20); table.setWidthPercentage(88); table2 = new PdfPTable(1); newlineTable(table2, 1); newlineTable(table2, 1); newlineTable(table2, 1); newlineTable(table2, 1); newlineTable(table2, 1); if(StringUtils.isNotBlank(diagnosis.optString("sum")) && !"0".equals(diagnosis.optString("sum"))) { if(diagnosis.optString("sum").indexOf("元") > 0) { table2.addCell(getPdfPCell("藥費:" + diagnosis.optString("sum"), Element.ALIGN_LEFT, bfChinese, 1)); } else { table2.addCell(getPdfPCell("藥費:" + diagnosis.optString("sum") + "元", Element.ALIGN_LEFT, bfChinese, 1)); } } else { table2.addCell(getPdfPCell("藥費:", Element.ALIGN_LEFT, bfChinese, 1)); } table2.addCell(getPdfPCell("注射費:" + "", Element.ALIGN_LEFT, bfChinese, 1)); table2.addCell(getPdfPCell("", Element.ALIGN_LEFT, bfChinese, 1)); cell = new PdfPCell(table2); cell.setColspan(8); cell.setBorder(0); table.addCell(cell); table2 = new PdfPTable(1); newlineTable(table2, 1); newlineTable(table2, 1); newlineTable(table2, 1); newlineTable(table2, 1); newlineTable(table2, 1); if(user == null || !StringUtils.isNotBlank(user.getUserName())){ table2.addCell(getPdfPCell("醫師:" + patient.optString("yy_doctor") + "(" + patient.optString("doctor_id") + ")", Element.ALIGN_LEFT, bfChinese, 1)); } else { table2.addCell(getPdfPCell("醫師:" + user.getUserName() + "(" + user.getLoginName() + ")", Element.ALIGN_LEFT, bfChinese, 1)); } if(StringUtils.isNotBlank(patient.optString("sh_doctor_name"))) { table2.addCell(getPdfPCell("審核藥師:" + patient.optString("sh_doctor_name"), Element.ALIGN_LEFT, bfChinese, 1)); } else { table2.addCell(getPdfPCell("審核藥師:", Element.ALIGN_LEFT, bfChinese, 1)); } table2.addCell(getPdfPCell("調配藥師:" + "", Element.ALIGN_LEFT, bfChinese, 1)); cell = new PdfPCell(table2); cell.setColspan(7); cell.setBorder(0); table.addCell(cell); //右側、二維碼 table2 = new PdfPTable(1); image = Image.getInstance(codePath); int percent = getImagePercent(image.getHeight(), image.getWidth(), 120); image.scalePercent(percent); cell = getPdfPCellImage(image, 1, 0f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table2.addCell(cell); font = new Font(bfChinese, 11, Font.NORMAL); cell = getPdfPCell("掃一掃 查看電子版", Element.ALIGN_CENTER, bfChinese, 1, font); table2.addCell(cell); cell = new PdfPCell(table2); cell.setColspan(5); cell.setBorder(0); table.addCell(cell); doc.add(table); table = new PdfPTable(1); table.setWidthPercentage(95); table.addCell(getPdfPCell(getTitleParagraph("注:請勿遺失,處方當天有效。因特殊情況,該處方有效為 天(簽名: )", new Font(bfChinese, 12, Font.NORMAL), Element.TITLE), Element.ALIGN_CENTER, bfChinese, 1)); doc.add(table); doc.close(); } /** * 獲取pdf表格的單元格 * * @param content * @param alignment * @param baseFont * @return */ public static PdfPCell getPdfPCell(String content, int alignment,BaseFont baseFont, int colspan) { Font font = new Font(baseFont, 12, Font.NORMAL); Paragraph paragraph = new Paragraph(content, font); PdfPCell cell = new PdfPCell(paragraph); cell.setLeading(0, 1.5f); cell.setLeft(2); cell.setHorizontalAlignment(alignment); cell.setBorder(0); if (colspan > 1) { cell.setColspan(colspan); } return cell; } public static PdfPCell getPdfPCell(Paragraph paragraph, int alignment, BaseFont baseFont, int colspan) { // font.setColor(80, 80, 80); PdfPCell cell = new PdfPCell(paragraph); cell.setLeading(0, 1.5f); cell.setLeft(2); cell.setHorizontalAlignment(alignment); cell.setBorder(0); if (colspan > 1) { cell.setColspan(colspan); } return cell; } /** * 設置單元格,并可以設置字體大小 * * @Description * @param content * @param alignment * @param baseFont * @param colspan * @param font * @return */ public static PdfPCell getPdfPCell(String content, int alignment, BaseFont baseFont, int colspan, Font font) { // font.setColor(80, 80, 80); Paragraph paragraph = new Paragraph(content, font); PdfPCell cell = new PdfPCell(paragraph); cell.setLeading(0, 1.5f); cell.setLeft(2); cell.setHorizontalAlignment(alignment); cell.setBorder(0); if (colspan > 1) cell.setColspan(colspan); return cell; } /** * 獲取pdf表格的單元格,并可以設置上面距離 * @param content * @param alignment * @param baseFont * @return */ public static PdfPCell getPdfPCell(String content, int alignment, BaseFont baseFont,int colspan, float paddingTop){ Font font = new Font(baseFont, 11, Font.NORMAL); //font.setColor(80, 80, 80); Paragraph paragraph = new Paragraph(content, font); PdfPCell cell = new PdfPCell(paragraph); cell.setLeading(0, 1.5f); cell.setLeft(2); cell.setUseBorderPadding(true); cell.setPaddingTop(paddingTop); cell.setHorizontalAlignment(alignment); cell.setBorder(0); if(colspan > 1) cell.setColspan(colspan); return cell; } /** * 獲取pdf表格的單元格 * * @param content * @param alignment * @param baseFont * @return */ public static PdfPCell getPdfPCell2(String content, int alignment, BaseFont baseFont, int colspan) { Font font = new Font(baseFont, 14, Font.NORMAL); font.setColor(59, 142, 222); Paragraph paragraph = new Paragraph(content, font); PdfPCell cell = new PdfPCell(paragraph); // cell.setLeading(0, 1.5f); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setLeft(2); cell.setHorizontalAlignment(alignment); cell.setBorder(0); if (colspan > 1) cell.setColspan(colspan); return cell; } /** * 獲取pdf表格的圖片單元格 * * @param image * @param colspan * @param paddingTop * @return */ public static PdfPCell getPdfPCellImage(Image image, int colspan, float paddingTop) { PdfPCell cell = new PdfPCell(image); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setUseBorderPadding(true); cell.setPaddingTop(paddingTop); cell.setBorder(0); if (colspan > 1) cell.setColspan(colspan); return cell; } /** * 獲取pdf表格的圖片單元格 * * @param content * @param alignment * @param baseFont * @return */ public static PdfPCell getPdfPCellImage2(Image image, int colspan, int align) { PdfPCell cell = new PdfPCell(image); cell.setHorizontalAlignment(align); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setBorder(0); if (colspan > 1) cell.setColspan(colspan); return cell; } /** * 標題文字 * * @param title * @param font * @return */ public static Paragraph getTitleParagraph(String title, Font font, int element) { Paragraph paragraph = new Paragraph(title, font); paragraph.setAlignment(element); return paragraph; } /** * 畫線 * * @return */ public static Chunk getLine() { Chunk underline = new Chunk( " "); underline.setUnderline(new BaseColor(100, 100, 100), 0.1f, 0f, 1f, 0f, 0); return underline; } /** * 畫線 * * @return */ public static Chunk getLine2() { Chunk underline = new Chunk( " "); underline.setUnderline(new BaseColor(100, 100, 100), 0.1f, 0f, 10f, 0f, 0); return underline; } /** * 畫線 * * @return */ public static Chunk getLine2(BaseColor baseColor) { Chunk underline = new Chunk( " "); underline.setUnderline(baseColor, 0.1f, 0f, 10f, 0f, 0); return underline; } /** * pdfptable 換行 * * @param table */ public static void newlineTable(PdfPTable table) { PdfPCell cell = new PdfPCell(new Paragraph(" ")); cell.setBorder(0); cell.setLeading(-1, 0); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); return; } /** * pdfptable 換行 * * @param table */ public static void newlineTable(PdfPTable table, int lineCount) { PdfPCell cell = new PdfPCell(new Paragraph(" ")); cell.setBorder(0); cell.setLeading(-1, 0); for (int i = 0; i < lineCount; i++) { table.addCell(cell); } return; } /** * 第一種解決方案 在不改變圖片形狀的同時,判斷,如果h>w,則按h壓縮,否則在w>h或w=h的情況下,按寬度壓縮 * * @param h * @param w * @return */ public static int getImagePercent(float h, float w, int standard) { int p = 0; float p2 = 100.0f; if (h >= w && h > standard) { p2 = standard / h * 100; } if (h < w && w > standard) { p2 = standard / w * 100; } p = Math.round(p2); return p; } } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看