Java tutorial
package com.jpsycn.print.util; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.util.Map; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.text.TextUtils; import android.util.Log; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; 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.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; public class PDFUtils { private static final String TAG = "PDFUtils"; /** * ????? * * @param mContext * @param file * ?pdf * @param map * ??? * @return */ public static boolean createSamplingPdf(Context mContext, File file, Map<String, String> map) { try { Font simfang12 = FontUtil.getFont(mContext, 12, "simfang.ttf"); Font bf = FontUtil.getFont(mContext, 12, "simfang.ttf", Font.BOLD, null); Document document = setHeader(file, mContext, simfang12, bf, "?????", map.get("sno") == null ? " " : map.get("sno")); // ?100 int cols = 100; // ????5 // ?5 // ?5? int m = 7; int n = 28; int o = 27; int p = 10; int q = 28; PdfPTable table1 = new PdfPTable(cols); // ???80%100% table1.setWidthPercentage(100); table1.setSpacingBefore(3f); table1.addCell(ItextUtil.getCell(simfang12, "?", m + n)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked( new String[] { "", "", "???", "??", "??", "" }, map.get("sample_type")), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "", m + n)); table1.addCell( ItextUtil.getCell(simfang12, ItextUtil.checked( new String[] { "", "", "???", "", "??", "", "?", "", "" }, map.get("sampling_address")), o + p + q, false)); table1.addCell(ItextUtil.getCell(simfang12, "", m, 3)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("name"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "??", n)); table1.addCell(ItextUtil.getCell(bf, map.get("address"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("contact_and_phone"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "??", m, 8)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("product_name"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("product_type"), o)); table1.addCell(ItextUtil.getCell(simfang12, "?", p)); table1.addCell(ItextUtil.getCell(bf, map.get("product_level"), q)); table1.addCell(ItextUtil.getCell(simfang12, "", n)); table1.addCell(ItextUtil.getCell(bf, map.get("product_brand"), o)); table1.addCell(ItextUtil.getCell(simfang12, "", p)); table1.addCell(ItextUtil.getCell(bf, map.get("product_standard"), q)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("product_sno"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "/?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("product_date"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("product_expired"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("number"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "", n)); table1.addCell(ItextUtil.getCell(bf, map.get("date"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "???" + ItextUtil.checked(new String[] { "", "?" }, map.get("company_equal_sampling_ground")) + "????", cols)); table1.addCell(ItextUtil.getCell(simfang12, "?", m, 3)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_name"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "??", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_address"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_linkman_and_phone"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "", m, 4)); table1.addCell(ItextUtil.getCell(simfang12, "??", n)); table1.addCell(ItextUtil.getCell(bf, map.get("depart_name"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("depart_people"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "??", n)); table1.addCell(ItextUtil.getCell(bf, map.get("depart_phone"), o + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "/Email", n)); table1.addCell(ItextUtil.getCell(bf, map.get("depart_email"), o + p + q)); // ? Font blackFont = FontUtil.getFont(mContext, 12, "simfang.ttf", Font.NORMAL, BaseColor.WHITE); String remark = map.get("remark") == null ? "" : map.get("remark"); int nn = 25 + 43 * 6; if (remark != null && remark.length() < 25 + 43 * 4) { nn = nn - remark.length(); } table1.addCell(ItextUtil.getRemarkCell(simfang12, blackFont, "?", bf, remark, cols, nn)); table1.addCell(ItextUtil.getMultiCell3(simfang12, blackFont, "??", "?", " ", 35, 7, 6 + 14 * 4 + 14)); table1.addCell(ItextUtil.getMultiCell2(simfang12, blackFont, "", " ", 33, 5 + 14 * 5 + 9)); table1.addCell(ItextUtil.getMultiCell2(simfang12, blackFont, "??", " ", 32, 5 + 13 * 5 + 8)); document.add(table1); Font simfang8 = FontUtil.getFont(mContext, 8, "simfang.ttf"); Paragraph r1 = new Paragraph( ":1.?,???,????", simfang8); document.add(r1); Paragraph r2 = new Paragraph( "2.???3.????", simfang8); document.add(r2); zxing(map.get("zxing"), mContext, document); stmp(mContext, document, 220, 40); Paragraph bbb = new Paragraph(ItextUtil.getBlackStr(88), blackFont); document.add(bbb); // document.close(); return true; } catch (Exception e) { Log.e(TAG, "", e); return false; } } private static Document setHeader(File file, Context mContext, Font simfang12, Font simfangBlod12, String title, String sno) throws DocumentException, IOException { Document document = new Document(PageSize.A4, 30, 30, 20, 0); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); // Font simhei18 = FontUtil.getFont(mContext, 18, "simhei.ttf"); Paragraph b = new Paragraph(title, simhei18); b.setAlignment(Element.ALIGN_CENTER); document.add(b); // ? Chunk m1 = new Chunk("?", simfang12); Chunk m2 = new Chunk(sno, simfangBlod12); Paragraph p2 = new Paragraph(); p2.add(m1); p2.add(m2); p2.setAlignment(Element.ALIGN_RIGHT); document.add(p2); return document; } /** * ???/?? * * @param mContext * @param file * @param map * @return */ public static boolean createReSamplePdf(Context mContext, File file, Map<String, String> map) { try { Font simfang12 = FontUtil.getFont(mContext, 12, "simfang.ttf"); Font bf = FontUtil.getFont(mContext, 12, "simfang.ttf", Font.BOLD, null); Document document = setHeader(file, mContext, simfang12, bf, "???/??", map.get("sno") == null ? " " : map.get("sno")); // int cols = 100; int m = 5; int n = 12; int o1 = 11; int o2 = 11; int o3 = 11; int p = 5; int q = 5; int r = 20; int s = 20; int o = o1 + o2 + o3; PdfPTable table1 = new PdfPTable(cols); // ???80%100% table1.setWidthPercentage(100); table1.setSpacingBefore(3f); table1.addCell(ItextUtil.getCell(simfang12, "??", m + n)); table1.addCell(ItextUtil.getCell(bf, map.get("source"), o)); table1.addCell(ItextUtil.getCell(simfang12, "", p + q)); table1.addCell(ItextUtil.getCell(bf, map.get("check_type"), r + s)); table1.addCell(ItextUtil.getCell(simfang12, "???", m, 3, false, true)); table1.addCell(ItextUtil.getCell(simfang12, " ??? ?", n, 3, false, true)); table1.addCell(ItextUtil.getCell(bf, map.get("name"), o)); table1.addCell(ItextUtil.getCell(simfang12, "", p + q)); table1.addCell(ItextUtil.getCell(bf, map.get("legal_representative"), r + s)); table1.addCell(ItextUtil.getCell(bf, map.get("address"), o)); table1.addCell(ItextUtil.getCell(simfang12, "? ??", p + q, 2, false, true)); table1.addCell(ItextUtil.getCell(bf, map.get("contact_and_phone"), r + s, 2)); table1.addCell(ItextUtil.getCell(simfang12, "", o)); table1.addCell(ItextUtil.getCell(simfang12, "??", m, 10, false, true)); table1.addCell(ItextUtil.getCell(simfang12, "????", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_name"), o)); table1.addCell(ItextUtil.getCell(simfang12, "?", p, 10, false, true)); String companyType = map.get("company_type"); table1.addCell(ItextUtil.getCell(simfang12, "", q, 4, false, true)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("", companyType), r)); table1.addCell( ItextUtil.getCell(simfang12, ItextUtil.checked("???", companyType), s)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_address"), o)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("", companyType), r)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("??", companyType), s)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_zip"), o)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("??", companyType), r)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("??", companyType), s)); table1.addCell(ItextUtil.getCell(simfang12, "", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_legal_representative"), o)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("?", companyType), r)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("?", companyType), s)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_linkman"), o)); table1.addCell(ItextUtil.getCell(simfang12, "?", q, 3, false, true)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("???", companyType), r)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("???", companyType), s)); table1.addCell(ItextUtil.getCell(simfang12, "??", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_phone"), o)); table1.addCell( ItextUtil.getCell(simfang12, ItextUtil.checked("???", companyType), r, 2)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("??", companyType), s, 2)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_license"), o)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("company_code"), o)); table1.addCell(ItextUtil.getCell(simfang12, "", q, 3, false, true)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("?", companyType), r)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("?", companyType), s)); table1.addCell(ItextUtil.getCell(simfang12, "?", n, 2)); table1.addCell(ItextUtil.getCell(simfang12, "", o1, false)); table1.addCell(ItextUtil.getCell(simfang12, "", o2)); table1.addCell(ItextUtil.getCell(simfang12, "?", o3)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("?", companyType), r, 2)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked("??", companyType), s, 2)); table1.addCell(ItextUtil.getCell(bf, map.get("company_person_number"), o1)); table1.addCell(ItextUtil.getCell(bf, map.get("company_output_value"), o2)); table1.addCell(ItextUtil.getCell(bf, map.get("company_production"), o3)); table1.addCell(ItextUtil.getCell(simfang12, "???", m, 8, false, true)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked(new String[] { "???", "QS", "CCC", "" }, map.get("product_certificate_type")), n + o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "??", r)); table1.addCell(ItextUtil.getCell(bf, map.get("product_certificate_sno"), s)); table1.addCell(ItextUtil.getCell(simfang12, "???", n + o1)); table1.addCell(ItextUtil.getCell(bf, map.get("product_name"), o2 + o3)); table1.addCell(ItextUtil.getCell(simfang12, "?", p + q + r)); table1.addCell(ItextUtil.getCell(bf, map.get("product_type"), s)); table1.addCell(ItextUtil.getCell(simfang12, "/?", n + o1)); table1.addCell(ItextUtil.getCell(bf, map.get("product_date"), o2 + o3)); table1.addCell(ItextUtil.getCell(simfang12, "", p + q + r)); table1.addCell(ItextUtil.getCell(bf, map.get("product_brand"), s)); // gg(map, simfang12, bf, table1); // table1.addCell(ItextUtil.getCell(simfang12, "", n + o1)); table1.addCell(ItextUtil.getCell(bf, map.get("samplint_date"), o2 + o3)); table1.addCell(ItextUtil.getCell(simfang12, "??", p + q + r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_state"), s)); table1.addCell(ItextUtil.getCell(simfang12, "???", n + o1)); table1.addCell(ItextUtil.getCell(bf, map.get("samplint_volumn_and_storage_address"), o2 + o3)); table1.addCell(ItextUtil.getCell(simfang12, "?", p + q + r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_send_address"), s)); table1.addCell(ItextUtil.getCell(simfang12, "???", n + o1)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked(new String[] { "", "?" }, map.get("is_export_product")), o2 + o3)); table1.addCell(ItextUtil.getCell(simfang12, "?", p + q + r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_send_expired"), s)); table1.addCell(ItextUtil.getCell(simfang12, "??", m, 3, false, true)); table1.addCell(ItextUtil.getCell(simfang12, "????", n)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_name"), o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "?", r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_people"), s)); table1.addCell(ItextUtil.getCell(simfang12, "???", n)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_address"), o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "??", r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_phone"), s)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_zip"), o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "/Email", r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_email"), s)); Font blackFont = FontUtil.getFont(mContext, 12, "simfang.ttf", Font.NORMAL, BaseColor.WHITE); String remark = map.get("remark") == null ? "" : map.get("remark"); int nn = 30 + 43 * 3; if (remark != null && remark.length() < 25 + 43 * 4) { nn = nn - remark.length(); } table1.addCell(ItextUtil.getRemarkCell(simfang12, blackFont, "?", bf, remark, cols, nn)); table1.addCell(ItextUtil.getMultiCell3(simfang12, blackFont, "???", "?????", " ", 32, 1, 2 + 13 * 2 + 6)); table1.addCell(ItextUtil.getMultiCell3(simfang12, blackFont, "??", "????", " ", 32, 1, 2 + 13 * 2 + 6)); table1.addCell(ItextUtil.getMultiCell3(simfang12, blackFont, "??", "??", " ", 36, 7 + 15 * 2 + 6, 9)); document.add(table1); Font simfang8 = FontUtil.getFont(mContext, 8, "simfang.ttf"); Paragraph r1 = new Paragraph( "1.??????", simfang8); document.add(r1); Paragraph r2 = new Paragraph( "2.???QS?CCC???3.???????", simfang8); document.add(r2); zxing(map.get("zxing"), mContext, document); stmp(mContext, document, 380, 40); Paragraph bbb = new Paragraph(ItextUtil.getBlackStr(44), blackFont); document.add(bbb); // 5: document.close(); return true; } catch (Exception e) { Log.e(TAG, "", e); return false; } } private static void stmp(Context mContext, Document document, int x, int y) throws MalformedURLException, IOException, DocumentException { Resources resources = mContext.getResources(); int identifier = resources.getIdentifier("stamp", "drawable", mContext.getPackageName()); Bitmap bitmap = BitmapFactory.decodeResource(resources, identifier); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); Image image = Image.getInstance(stream.toByteArray()); Chunk c1 = new Chunk(image, x, y, false); Paragraph pp = new Paragraph(); pp.add(c1); document.add(pp); } private static void zxing(String zxing, Context mContext, Document document) throws MalformedURLException, IOException, DocumentException { if (!TextUtils.isEmpty(zxing)) { Bitmap bitmap = BarcodeCreater.creatBarcode(mContext, zxing, 100, 20, false); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); Image image = Image.getInstance(stream.toByteArray()); Chunk c1 = new Chunk(image, 0, 0, false); float width = image.getWidth(); Chunk c2 = new Chunk(image, 595 - 30 * 2 - width * 2, 0, false); Paragraph pp = new Paragraph(); pp.setLeading(30f); pp.add(c1); pp.add(c2); document.add(pp); } } /** * ????/?? * * @param mContext * @param file * @param map * @return */ public static boolean createSpaqPdf(Context mContext, File file, Map<String, String> map) { try { /* * String[] ss = new String[] { "",".", "", "", "?", "?", "", * "", "", "",".", "", "", "?", "?", "", "", "", "",".", * "", "", "", "", "", "", "", "", "", "", ".","", "", * "", "?", "", "", "?", "", "?", "", "", "?", "", "", "", * "?", "", "", "", "", "" }; */ /* * PdfContentByte cb = writer.getDirectContent(); BaseFont simfang = * FontUtil.getBaseFont(mContext, "simfang.ttf"); cb.beginText(); * cb.setFontAndSize(simfang, 12); float w = 595 - 30; for (int i = * 0; i < ss.length; i++) { String temp = ss[i]; if * (temp.equals("") || temp.equals("")) { * cb.showTextAligned(PdfContentByte.ALIGN_CENTER, temp, w+2, * (680f-i*10)+3, 270); } else { cb.setTextMatrix(w, 680f - i * 10); * cb.showText(temp); } } cb.endText(); */ Font simfang12 = FontUtil.getFont(mContext, 12, "simfang.ttf"); Font bf = FontUtil.getFont(mContext, 12, "simfang.ttf", Font.BOLD, null); Document document = setHeader(file, mContext, simfang12, bf, "????/??", map.get("sno") == null ? " " : map.get("sno")); // int cols = 100; int m = 5; int n = 12; int o1 = 11; int o2 = 11; int o3 = 11; int p = 5; int q = 5; int r = 20; int s = 20; int o = o1 + o2 + o3; PdfPTable table1 = new PdfPTable(cols); // ???80%100% table1.setWidthPercentage(100); table1.setSpacingBefore(3f); table1.addCell(ItextUtil.getCell(20f, simfang12, "??", m + n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("source"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "", p + q)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("check_type"), r + s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "???", m, 3, false, true)); table1.addCell(ItextUtil.getCell(20f, simfang12, "????", n, 3)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("name"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "", p + q)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("legal_representative"), r + s)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("address"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "???", p + q, 2)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("contact_and_phone"), r + s, 2)); table1.addCell(ItextUtil.getCell(20f, simfang12, "", o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "??", m, 10, false, true)); table1.addCell(ItextUtil.getCell(20f, simfang12, "????", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_name"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", p, 10, false, true)); String companyType = map.get("company_type"); table1.addCell(ItextUtil.getCell(simfang12, "", q, 4, false, true)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("", companyType), r)); table1.addCell( ItextUtil.getCell(20f, simfang12, ItextUtil.checked("???", companyType), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "???", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_address"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("", companyType), r)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("??", companyType), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_zip"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("??", companyType), r)); table1.addCell( ItextUtil.getCell(20f, simfang12, ItextUtil.checked("??", companyType), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_legal_representative"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("?", companyType), r)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("?", companyType), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_linkman"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", q, 3, false, true)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("???", companyType), r)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("???", companyType), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "??", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_phone"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("???", companyType), r, 2)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("??", companyType), s, 2)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_license"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("company_code"), o)); table1.addCell(ItextUtil.getCell(20f, simfang12, "", q, 3)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("?", companyType), r)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("?", companyType), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", n, 2)); StringBuilder sb3 = new StringBuilder(); sb3.append(""); sb3.append(map.get("company_person_number") == null ? " " : map.get("company_person_number")); sb3.append(" "); sb3.append(map.get("company_output_value") == null ? " " : map.get("company_output_value")); sb3.append(" ?"); sb3.append(map.get("company_production") == null ? " " : map.get("company_production")); // sb3.append("10000 5000 ?1000?"); Font simfang10 = FontUtil.getFont(mContext, 9, "simfang.ttf"); table1.addCell(ItextUtil.getCell(20f, simfang10, sb3.toString(), o1 + o2 + o3)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("?", companyType), r, 2)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked("??", companyType), s, 2)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked(new String[] { "", "", "?" }, map.get("company_scope")), o1 + o2 + o3)); table1.addCell(ItextUtil.getCell(20f, simfang12, "???", m, 9, false, true)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked(new String[] { "?", "??", "?", "??" }, map.get("food_type")), n + o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(20f, simfang12, "??", r)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("product_certificate_sno"), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "???", n + o1)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("product_name"), o2 + o3)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", p + q + r)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("product_type"), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "/?", n + o1)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("product_date"), o2 + o3)); table1.addCell(ItextUtil.getCell(20f, simfang12, "", p + q + r)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("product_brand"), s)); // gg(map, simfang12, bf, table1); // table1.addCell(ItextUtil.getCell(20f, simfang12, "", n + o1)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("samplint_date"), o2 + o3)); table1.addCell(ItextUtil.getCell(20f, simfang12, "??", p + q + r)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("sampling_state"), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "???", n + o1)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("samplint_volumn_and_storage_address"), o2 + o3)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", p + q + r)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("sampling_send_address"), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", n + o1)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("sampling_send_expired"), o2 + o3)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked(new String[] { "??", "???" }, map.get("is_famous_brand")), p + q + r + s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "", n)); table1.addCell(ItextUtil.getCell(20f, simfang12, ItextUtil.checked(new String[] { "???", "", "" }, map.get("sample_address_1")), o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(simfang12, ItextUtil.checked( new String[] { "", "?", "?" }, map.get("sample_address_2")), r + s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "??", m, 3, false, true)); table1.addCell(ItextUtil.getCell(20f, simfang12, "????", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("sampling_name"), o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(20f, simfang12, "?", r)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("sampling_people"), s)); table1.addCell(ItextUtil.getCell(20f, simfang12, "???", n)); table1.addCell(ItextUtil.getCell(20f, bf, map.get("sampling_address"), o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "??", r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_phone"), s)); table1.addCell(ItextUtil.getCell(simfang12, "?", n)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_zip"), o1 + o2 + o3 + p + q)); table1.addCell(ItextUtil.getCell(simfang12, "/Email", r)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_email"), s)); table1.addCell(ItextUtil.getCell(simfang12, "", m + n, 2)); StringBuilder sb = new StringBuilder(); sb.append("?"); sb.append(ItextUtil.checked(new String[] { "", "" }, map.get("sampling_result_1"))); sb.append("?"); sb.append(ItextUtil.checked(new String[] { "", "?" }, map.get("sampling_result_2"))); sb.append("\n"); sb.append("?"); sb.append(ItextUtil.checked(new String[] { "", "", "" }, map.get("sampling_result_3"))); sb.append("????"); sb.append(ItextUtil.checked(new String[] { "", "?" }, map.get("sampling_result_4"))); table1.addCell(ItextUtil.getCell(simfang12, sb.toString(), o1 + o2 + o3 + p + q + r + s, 2, false)); Font blackFont = FontUtil.getFont(mContext, 12, "simfang.ttf", Font.NORMAL, BaseColor.WHITE); table1.addCell(ItextUtil.getCell(simfang12, "", m + n, 2)); StringBuilder sb2 = new StringBuilder(); sb2.append("??"); sb2.append(ItextUtil.checked(new String[] { "", "" }, map.get("remark_1"))); sb2.append("\n"); sb2.append(""); // sb2.append(map.get("remark_2") == null ? "" : // map.get("remark_2")); String ss = map.get("remark_2") == null ? "" : map.get("remark_2"); table1.addCell(ItextUtil.getCell2(simfang12, sb2.toString(), bf, ss, o1 + o2 + o3 + p + q + r + s)); table1.addCell(ItextUtil.getMultiCell3(simfang12, blackFont, "???", "?????", " ", 32, 1, 2 + 13 * 2 + 6)); table1.addCell(ItextUtil.getMultiCell3(simfang12, blackFont, "??", "????", " ", 32, 1, 2 + 13 * 2 + 6)); table1.addCell(ItextUtil.getMultiCell3(simfang12, blackFont, "??", "??", " ", 36, 7 + 15 * 2 + 6, 9)); document.add(table1); Font simfang8 = FontUtil.getFont(mContext, 8, "simfang.ttf"); Paragraph r1 = new Paragraph( "1???4??????????????2??????????3????", simfang8); document.add(r1); zxing(map.get("zxing"), mContext, document); stmp(mContext, document, 380, 40); Paragraph bbb = new Paragraph(ItextUtil.getBlackStr(44), blackFont); document.add(bbb); // 5: document.close(); return true; } catch (Exception e) { Log.e(TAG, "", e); return false; } } private static void gg(Map<String, String> map, Font simfang12, Font bf, PdfPTable table1) { table1.addCell(ItextUtil.getCell(simfang12, "?", 23)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_number"), 11)); table1.addCell(ItextUtil.getCell(simfang12, "?", 11)); table1.addCell(ItextUtil.getCell(bf, map.get("product_level"), 10)); table1.addCell(ItextUtil.getCell(simfang12, "/?", 20)); table1.addCell(ItextUtil.getCell(bf, map.get("sampling_total_number"), 20)); table1.addCell(ItextUtil.getCell(simfang12, "/", 23 + 11)); table1.addCell(ItextUtil.getCell(bf, map.get("product_standard"), 61)); } }