List of usage examples for com.itextpdf.text BaseColor BaseColor
public BaseColor(final float red, final float green, final float blue)
From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java
public PdfPTable voyInfo(LclUnitSs lclUnitSs) throws DocumentException { StringBuilder originValues = new StringBuilder(); if (CommonUtils.isNotEmpty(lclUnitSs.getLclSsHeader().getOrigin().getUnLocationName())) { originValues.append(lclUnitSs.getLclSsHeader().getOrigin().getUnLocationName()).append(","); }/*from w w w . j a v a 2 s . c o m*/ if (null != lclUnitSs.getLclSsHeader().getOrigin().getCountryId() && CommonUtils.isNotEmpty(lclUnitSs.getLclSsHeader().getOrigin().getCountryId().getCodedesc())) { originValues.append(lclUnitSs.getLclSsHeader().getOrigin().getCountryId().getCodedesc()).append(" "); } if (CommonUtils.isNotEmpty(lclUnitSs.getLclSsHeader().getOrigin().getUnLocationCode())) { originValues.append("(").append(lclUnitSs.getLclSsHeader().getOrigin().getUnLocationCode()).append(")"); } StringBuilder fdValues = new StringBuilder(); if (CommonUtils.isNotEmpty(lclUnitSs.getLclSsHeader().getDestination().getUnLocationName())) { fdValues.append(lclUnitSs.getLclSsHeader().getDestination().getUnLocationName()).append(","); } if (null != lclUnitSs.getLclSsHeader().getDestination().getStateId() && CommonUtils.isNotEmpty(lclUnitSs.getLclSsHeader().getDestination().getStateId().getCode())) { fdValues.append(lclUnitSs.getLclSsHeader().getDestination().getStateId().getCode()).append(" "); } if (CommonUtils.isNotEmpty(lclUnitSs.getLclSsHeader().getDestination().getUnLocationCode())) { fdValues.append("(").append(lclUnitSs.getLclSsHeader().getDestination().getUnLocationCode()) .append(")"); } Font fontCompSub = FontFactory.getFont("Arial", 9f, Font.BOLD); Paragraph pHeading = null; table = new PdfPTable(1); table.setWidthPercentage(100f); PdfPCell cell1 = new PdfPCell(); cell1.setBorder(0); cell1.setColspan(2); cell1.setBorderColor(new BaseColor(00, 51, 153)); cell1.setBorderWidthBottom(3f); cell1.setBorderWidthLeft(3f); cell1.setBorderWidthRight(3f); cell1.setBorderWidthTop(10f); cell1.setPadding(0f); //Heading pHeading = new Paragraph(8f, "Voyage Information", mainHeadingQuote); pHeading.setAlignment(Element.ALIGN_CENTER); cell1.addElement(pHeading); PdfPTable ntable1 = new PdfPTable(6); ntable1.setWidthPercentage(100f); ntable1.setWidths(new float[] { 0.1f, 1.15f, 0.09f, 4.09f, 1f, 2f }); //company Name ntable1.addCell(createEmptyCell(0, 1f, 6)); //Voyage Cell Origin ntable1.addCell(createEmptyCell(0, 1f, 0)); ntable1.addCell(makeCellNoBorderValue("Voyage. . . . . . . . . .", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(":", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(lclUnitSs.getLclSsHeader().getScheduleNo().toUpperCase(), 4, 0f, 5f, fontgreenCont)); //1Cell Origin ntable1.addCell(createEmptyCell(0, 1f, 0)); ntable1.addCell(makeCellNoBorderValue("Origin. . . . . . . . . . .", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(":", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(originValues.toString().toUpperCase(), 4, 0f, 5f, fontgreenCont)); ///2Cell Destination ntable1.addCell(createEmptyCell(0, 1f, 0)); ntable1.addCell(makeCellNoBorderValue("Destination. . . . . .", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(":", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(fdValues.toString().toUpperCase(), 4, 0f, 5f, fontgreenCont)); //3 StringBuilder billValues = new StringBuilder(); if (lclUnitSs.getLclSsHeader().getBillingTerminal().getTrmnum() != null) { billValues.append(lclUnitSs.getLclSsHeader().getBillingTerminal().getTrmnum()).append("-"); } if (lclUnitSs.getLclSsHeader().getBillingTerminal().getTerminalLocation() != null) { billValues.append(lclUnitSs.getLclSsHeader().getBillingTerminal().getTerminalLocation()); } ntable1.addCell(createEmptyCell(0, 1f, 0)); ntable1.addCell(makeCellNoBorderValue("Billing Terminal. . ", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(":", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(billValues.toString().toUpperCase(), 4, 0f, 4f, fontgreenCont)); ntable1.addCell(createEmptyCell(0, 1f, 6)); cell1.addElement(ntable1); table.addCell(cell1); return table; }
From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java
public PdfPTable unitInfo(LclUnitSs lclUnitSs) throws DocumentException, Exception { LclUnitSsImports lclUnitSsImports = lclUnitSs.getLclUnit().getLclUnitSsImportsList().get(0); StringBuilder cfsWarehs = new StringBuilder(); if (lclUnitSsImports != null && lclUnitSsImports.getCfsWarehouseId() != null) { if (lclUnitSsImports.getCfsWarehouseId().getWarehouseName() != null) { cfsWarehs.append(lclUnitSsImports.getCfsWarehouseId().getWarehouseName()).append("-"); }//from www . jav a2 s . c om if (lclUnitSsImports.getCfsWarehouseId().getWarehouseNo() != null) { cfsWarehs.append(lclUnitSsImports.getCfsWarehouseId().getWarehouseNo()); } } LclUnitSsManifest lclUnitSsManifest = lclUnitSs.getLclUnit().getLclUnitSsManifestList().get(0); Font fontCompSub = FontFactory.getFont("Arial", 9f, Font.BOLD); Paragraph pHeading = null; table = new PdfPTable(1); table.setWidthPercentage(100f); PdfPCell cell1 = new PdfPCell(); cell1.setBorder(0); cell1.setColspan(2); cell1.setBorderColor(new BaseColor(00, 51, 153)); cell1.setBorderWidthBottom(3f); cell1.setBorderWidthLeft(3f); cell1.setBorderWidthRight(3f); cell1.setBorderWidthTop(10f); cell1.setPadding(0f); //Heading pHeading = new Paragraph(8f, "Unit Information", mainHeadingQuote); pHeading.setAlignment(Element.ALIGN_CENTER); cell1.addElement(pHeading); PdfPTable ntable1 = new PdfPTable(6); ntable1.setWidthPercentage(100f); ntable1.setWidths(new float[] { 0.1f, 1.15f, 0.09f, 4.09f, 1f, 2f }); //company Name ntable1.addCell(createEmptyCell(0, 1f, 6)); //unit No Cell ntable1.addCell(createEmptyCell(0, 1f, 0)); ntable1.addCell(makeCellNoBorderValue("Unit No . . . . . . . . .", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(":", 0, 0f, 4f, fontCompSub)); ntable1.addCell( makeCellNoBorderValue(lclUnitSs.getLclUnit().getUnitNo().toUpperCase(), 4, 0f, 4f, fontgreenCont)); //3 ntable1.addCell(createEmptyCell(0, 1f, 0)); ntable1.addCell(makeCellNoBorderValue("CFS(Devanning). . ", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(":", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(cfsWarehs.toString().toUpperCase(), 4, 0f, 4f, fontgreenCont)); // ntable1.addCell(createEmptyCell(0, 1f, 0)); ntable1.addCell(makeCellNoBorderValue("Master BL. . . . . . . ", 0, 0f, 4f, fontCompSub)); ntable1.addCell(makeCellNoBorderValue(":", 0, 0f, 4f, fontCompSub)); ntable1.addCell( makeCellNoBorderValue(lclUnitSsManifest.getMasterbl().toUpperCase(), 4, 0f, 4f, fontgreenCont)); ntable1.addCell(createEmptyCell(0, 1f, 6)); cell1.addElement(ntable1); table.addCell(cell1); return table; }
From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java
public PdfPTable dispoInfo(LclUnitSs lclUnitSs) throws DocumentException, Exception { Paragraph pHeading = null;/*w w w . java 2 s. c om*/ table = new PdfPTable(1); table.setWidthPercentage(100f); PdfPCell cell1 = null; cell1 = new PdfPCell(); cell1.setBorder(0); cell1.setBorderColor(new BaseColor(00, 51, 153)); cell1.setBorderWidthBottom(3f); cell1.setBorderWidthLeft(3f); cell1.setBorderWidthRight(3f); cell1.setBorderWidthTop(10f); cell1.setPadding(0f); //Heading pHeading = new Paragraph(8f, "Disposition Details", mainHeadingQuote); pHeading.setAlignment(Element.ALIGN_CENTER); cell1.addElement(pHeading); //company Name PdfPTable ntable1 = new PdfPTable(9); ntable1.setWidthPercentage(100f); ntable1.setWidths(new float[] { 0.2f, 2f, 0.25f, 1.5f, 0.25f, 4.5f, 1.5f, 5f, .5f }); ntable1.addCell(createEmptyCell(0, 0.1f, 9)); ntable1.addCell(createEmptyCell(0, 1f, 0)); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.06f); Chunk c1 = new Chunk("DATE", greenCourierFont9); cell.addElement(c1); ntable1.addCell(cell); ntable1.addCell(createEmptyCell(0, .5f, 0)); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.06f); c1 = new Chunk("TIME", greenCourierFont9); cell.addElement(c1); ntable1.addCell(cell); ntable1.addCell(createEmptyCell(0, .5f, 0)); cell = new PdfPCell(); cell.setBorder(0); cell.setBorderWidthBottom(0.06f); c1 = new Chunk("CONTAINER STATUS", greenCourierFont9); cell.addElement(c1); ntable1.addCell(cell); ntable1.addCell(createEmptyCell(0, .5f, 0)); ntable1.addCell(createEmptyCell(0, .5f, 0)); ntable1.addCell(createEmptyCell(0, .5f, 0)); LclSsDetail lclSsDetail = lclUnitSs.getLclSsHeader().getVesselSsDetail(); List<LclUnitSsDispo> dispositionList = new LclUnitSsDispoDAO() .getUnitDispoDetailsWithoutData(lclUnitSs.getLclUnit().getId(), lclSsDetail.getId()); if (!dispositionList.isEmpty()) { for (int i = 0; i < dispositionList.size(); i++) { LclUnitSsDispo lclUnitSsDispo = (LclUnitSsDispo) dispositionList.get(i); String dateTimeV = DateUtils.formatDate(lclUnitSsDispo.getDispositionDatetime(), "dd-MMM-yyyy hh:mm a"); String[] dateTimeArray1 = dateTimeV.split(" "); ntable1.addCell(createEmptyCell(0, 1f, 0)); cell = new PdfPCell(); cell.setBorder(0); pHeading = new Paragraph(5f, "" + dateTimeArray1[0], greenCourierFont9); cell.addElement(pHeading); ntable1.addCell(cell); ntable1.addCell(createEmptyCell(0, .5f, 0)); cell = new PdfPCell(); cell.setBorder(0); pHeading = new Paragraph(5f, "" + dateTimeArray1[1] + " " + dateTimeArray1[2], greenCourierFont9); cell.addElement(pHeading); ntable1.addCell(cell); ntable1.addCell(createEmptyCell(0, .5f, 0)); cell = new PdfPCell(); cell.setBorder(0); if (lclUnitSsDispo.getDisposition() != null && lclUnitSsDispo.getDisposition().getDescription() != null) { pHeading = new Paragraph(5f, "" + lclUnitSsDispo.getDisposition().getDescription(), greenCourierFont9); } else { pHeading = new Paragraph(5f, "" + lclUnitSsDispo.getDisposition().getEliteCode(), greenCourierFont9); } cell.addElement(pHeading); ntable1.addCell(cell); ntable1.addCell(createEmptyCell(0, .5f, 0)); ntable1.addCell(createEmptyCell(0, .5f, 0)); ntable1.addCell(createEmptyCell(0, .5f, 0)); } } ntable1.addCell(createEmptyCell(0, 2f, 9)); cell1.addElement(ntable1); table.addCell(cell1); return table; }
From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java
public PdfPTable voyContent(String voyContent) throws DocumentException, Exception { Paragraph pHeading = null;// w w w . j a va 2 s. c o m table = new PdfPTable(1); table.setWidthPercentage(100f); PdfPCell cell1 = null; cell1 = new PdfPCell(); cell1.setBorder(0); cell1.setBorderColor(new BaseColor(00, 51, 153)); cell1.setBorderWidthBottom(3f); cell1.setBorderWidthLeft(3f); cell1.setBorderWidthRight(3f); cell1.setBorderWidthTop(10f); cell1.setPadding(0f); //Heading pHeading = new Paragraph(8f, "Voyage Comments", mainHeadingQuote); pHeading.setAlignment(Element.ALIGN_CENTER); cell1.addElement(pHeading); //company Name PdfPTable ntable1 = new PdfPTable(2); ntable1.setWidthPercentage(100f); ntable1.setWidths(new float[] { 0.1f, 5f }); ntable1.addCell(createEmptyCell(0, 0.1f, 2)); ntable1.addCell(createEmptyCell(0, 1f, 0)); cell = new PdfPCell(); cell.setBorder(0); pHeading = new Paragraph(8f, "" + voyContent.toUpperCase(), blackContentBoldFont); cell.addElement(pHeading); ntable1.addCell(cell); ntable1.addCell(createEmptyCell(0, 2f, 2)); cell1.addElement(ntable1); table.addCell(cell1); return table; }
From source file:com.gp.cong.logisoft.lcl.report.LclVoyageNotificationPdfCreator.java
public PdfPTable thankyouMsg(String contextPath) throws DocumentException, Exception { BaseFont palationRomanBase = BaseFont.createFont(contextPath + "/ttf/palabi.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);// w w w.ja v a 2 s . c o m Font palatinoRomanSmallFont = new Font(palationRomanBase, 8.5f, Font.ITALIC, new BaseColor(00, 102, 12)); table = new PdfPTable(1); table.setWidthPercentage(100f); table.addCell(createEmptyCell(0, 10f, 0)); cell = new PdfPCell(); cell.setBorder(0); Paragraph pContent = new Paragraph(8f, "Thank you for choosing Econocaribe Consolidators, Inc. for your international shipping needs. \n Please contact us if you have any questions at 1-866-ECONO-IT (866-326-6648) or visit us at www.econocaribe.com.", palatinoRomanSmallFont); pContent.setAlignment(Element.ALIGN_CENTER); cell.addElement(pContent); table.addCell(cell); return table; }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public void createPDF(Context context) throws DocumentException, IOException { LicenseKey.loadLicenseFile(context.getAssets().open("itextkey.xml")); this.mContext = context; Map<String, String> pdfParams = new HashMap(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_Hmmss", Locale.US); dateFormat.setTimeZone(TimeZone.getDefault()); this.filename = "txtbook_" + dateFormat.format(new Date()) + ".pdf"; float leftMargin = Txtbook.RIGHT_MARGIN_EVEN; float rightMargin = Txtbook.RIGHT_MARGIN_ODD; if (this.settings.addFrontCover.booleanValue()) { leftMargin = Txtbook.RIGHT_MARGIN_ODD; rightMargin = Txtbook.RIGHT_MARGIN_EVEN; }//from w w w .j av a 2 s . c o m Document document = new Document(PageSize.LETTER, leftMargin, rightMargin, Txtbook.TOP_MARGIN, Txtbook.TOP_MARGIN); File file = new File(Environment.getExternalStorageDirectory(), this.filename); if (!(file.exists() && file.canRead())) { file.createNewFile(); } this.writer = PdfWriter.getInstance(document, new FileOutputStream(file)); this.writer.setCompressionLevel(this.settings.compressionLevel); this.writer.setStrictImageSequence(true); FontFactory.register("assets/fonts/DroidSans.ttf"); this.sansFont6Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 6.0f, 0, new BaseColor(152, 152, 152)); this.sansFont9 = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f); this.sansFont9Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 9.0f, 0, new BaseColor(103, 103, 103)); this.sansFont11Gray = FontFactory.getFont("DroidSans", BaseFont.WINANSI, true, 11.0f, 0, new BaseColor(152, 152, 152)); FontFactory.register("assets/fonts/CourierNew.ttf"); this.serifFont8Gray = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 8.0f, 0, new BaseColor(103, 103, 103)); this.serifFont11 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 11.0f); this.serifFont14 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 14.0f); this.serifFont24 = FontFactory.getFont("Courier New", BaseFont.WINANSI, true, 24.0f); document.open(); document.setMarginMirroring(true); document.addCreationDate(); document.addCreator("Created with txt-book for Android www.txt-book.com"); document.addTitle("txt-book for Android"); if (this.settings.bookStyle == 1) { ConversationHeaderFooter hf = new ConversationHeaderFooter(); hf.footerFont = this.sansFont9; hf.hasFrontCover = this.settings.addFrontCover; this.writer.setPageEvent(hf); } else { StorybookHeaderFooter hf2 = new StorybookHeaderFooter(); hf2.title = this.settings.bookCoverTitle; hf2.headerFont = this.serifFont8Gray; hf2.hasFrontCover = this.settings.addFrontCover; this.writer.setPageEvent(hf2); } if (this.settings.addFrontCover.booleanValue()) { createFrontCoverPage(document, this.settings.bookCoverTitle, this.settings.addFrontCoverImage.booleanValue() ? this.settings.coverPhoto : null); pdfParams.put("PDF Front Cover", "YES"); } else { pdfParams.put("PDF Front Cover", "NO"); } if (this.settings.addFrontCoverImage.booleanValue()) { pdfParams.put("PDF Front Cover Image", "YES"); } else { pdfParams.put("PDF Front Cover Image", "NO"); } if (this.settings.bookStyle == 1) { createContentPagesConversation(document); } else { createContentPagesStorybook(document, this.settings.bookCoverTitle); } int pages = this.writer.getPageNumber(); if (this.settings.bookStyle == 2) { ((StorybookHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true); } else { ((ConversationHeaderFooter) this.writer.getPageEvent()).reachedEndOfContent = Boolean.valueOf(true); } if (this.settings.addBackCover.booleanValue()) { pages++; pdfParams.put("PDF Back Cover", "YES"); if (pages % 2 == 1) { createBlankSpacerPage(document); } createBackCoverPage(document, this.settings.backCoverNote); } else { pdfParams.put("PDF Back Cover", "NO"); if (pages % 2 == 1) { createBlankSpacerPage(document); } } if (this.settings.bookStyle == 2) { pdfParams.put("PDF Style", "Storybook"); } else { pdfParams.put("PDF Style", "Conversation"); } pdfParams.put("PDF Num Pages", Integer.valueOf(this.writer.getPageNumber()).toString()); document.close(); FlurryAgent.logEvent("PDF_CREATED", (Map) pdfParams); }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public Boolean createFrontCoverPage(Document document, String coverTitle, Bitmap photo) throws DocumentException, MalformedURLException, IOException { if (photo != null) { int imageMaxWidth; int imageMaxHeight; int imagePosX; int imagePosY; if (photo.getWidth() < photo.getHeight()) { imageMaxWidth = 900;//from w ww.j av a 2 s .c om imageMaxHeight = 1200; imagePosX = 198; imagePosY = 379; } else { imageMaxWidth = 1200; imageMaxHeight = 900; imagePosX = 162; imagePosY = 379; } OutputStream stream = new ByteArrayOutputStream(); ImageUtilities.scaleCenterCrop(photo, imageMaxWidth, imageMaxHeight).compress(CompressFormat.JPEG, 50, stream); Image coverImage = Image.getInstance(stream.toByteArray()); coverImage.setAbsolutePosition(0.0f, 0.0f); PdfTemplate t = this.writer.getDirectContent().createTemplate((float) imageMaxWidth, (float) imageMaxHeight); t.newPath(); t.moveTo(0.0f, (float) imageMaxHeight); t.lineTo(0.0f, 71.0f); t.lineTo(17.0f, 71.0f); t.lineTo(17.0f, 0.0f); t.lineTo(72.0f, 71.0f); t.lineTo((float) imageMaxWidth, 71.0f); t.lineTo((float) imageMaxWidth, (float) imageMaxHeight); t.lineTo(0.0f, (float) imageMaxHeight); t.closePath(); t.clip(); t.newPath(); t.addImage(coverImage); t.setColorStroke(new BaseColor(0, 0, 0)); t.setLineWidth(BUBBLE_TEXT_INDENT_ALTERNATE); t.newPath(); t.moveTo(0.0f, (float) imageMaxHeight); t.lineTo(0.0f, 71.0f); t.lineTo(17.0f, 71.0f); t.lineTo(17.0f, 0.0f); t.lineTo(72.0f, 71.0f); t.lineTo((float) imageMaxWidth, 71.0f); t.lineTo((float) imageMaxWidth, (float) imageMaxHeight); t.lineTo(0.0f, (float) imageMaxHeight); t.closePathStroke(); Image clipped = Image.getInstance(t); clipped.scalePercent(24.0f); clipped.setAbsolutePosition((float) imagePosX, (float) imagePosY); clipped.setCompressionLevel(this.settings.compressionLevel); clipped.setAlignment(5); document.add(clipped); } if (coverTitle != null && coverTitle.length() > 0) { PdfContentByte canvas = this.writer.getDirectContent(); Paragraph coverTitleEl = new Paragraph(coverTitle, this.serifFont24); coverTitleEl.setAlignment(1); PdfPTable table = new PdfPTable(1); table.setTotalWidth(311.0f); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.addElement(coverTitleEl); cell.setPadding(0.0f); cell.setIndent(0.0f); table.addCell(cell); table.completeRow(); table.writeSelectedRows(0, -1, 147.0f, 390.0f, canvas); } return Boolean.valueOf(true); }
From source file:com.masscustsoft.service.ToPdf.java
License:Open Source License
private BaseColor getColor(Map row, String id) { String color = (String) row.get(id); if (color == null) return null; Color c = Color.getColor(color); if (c == null) return null; return new BaseColor(c.getRed(), c.getBlue(), c.getGreen()); }
From source file:com.microware.intrahealth.Createpdf2.java
@SuppressLint("SdCardPath") public boolean write(Context context, String fname, String[] Header, ArrayList<HashMap<String, String>> data, String[] Page2, int Flag) throws Exception { try {/*from w w w . j ava2 s.c om*/ // file = new File(Environment.getExternalStorageDirectory()+IIHSPdf+ "/"+fname+".pdf"); this.context = context; g = (Global) context.getApplicationContext(); BaseFont urName = BaseFont.createFont("assets/FreeSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); urFontName = new Font(urName, 12); urName1 = FontFactory.getFont("assets/mangal.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // urFontName = new Font(urName, 12); sHeader[0] = context.getResources().getString(R.string.hrpreport); sHeader[1] = context.getResources().getString(R.string.anmname) + " " + g.getsGlobalANMName() + " " + context.getResources().getString(R.string.distname); sHeader[2] = context.getResources().getString(R.string.Identificationcode); sHeader2[0] = context.getResources().getString(R.string.Identificationcode1); sHeader2[1] = context.getResources().getString(R.string.totalhrp); sHeader2[2] = context.getResources().getString(R.string.totalcheckup); sHeader2[3] = context.getResources().getString(R.string.anmsign); catFont2 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); if (Flag == 2) { catFont = new Font(urName, 16, Font.BOLD); catFont1 = new Font(urName, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(urName, 14); smallBold = new Font(urName, 12, Font.BOLD, BaseColor.WHITE); } else { catFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD); catFont1 = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, new BaseColor(0, 85, 133)); subFont = new Font(Font.FontFamily.TIMES_ROMAN, 14); smallBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.WHITE); } String fpath = "/sdcard/msakhi/Pdf"; File path = new File(fpath); File file = new File(path, fname + ".pdf"); if (!path.exists()) { path.mkdirs(); if (!file.exists()) { file.createNewFile(); } } else { if (!file.exists()) { file.createNewFile(); } } // Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0)); // Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12); Document document = new Document(A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(file.getAbsoluteFile())); document.open(); // addMetaData(document); // addTitlePage(document); addContent(document, Header, data, sHeader2, Flag); document.close(); return true; } catch (IOException e) { e.printStackTrace(); return false; } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
From source file:com.microware.intrahealth.Createpdf2.java
private static void createTable(Paragraph preface, String[] Header, ArrayList<HashMap<String, String>> data) throws BadElementException { Context _con = null;// w ww. ja v a 2s . c o m // PdfPTable table = new PdfPTable(new float[] { 2, 1 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPTable table = new PdfPTable(new float[] { 1, 3, 3, 5, 5, 2, 3, 2, 2, 2 }); table.setHorizontalAlignment(Element.ALIGN_LEFT); for (int i = 0; i < Header.length; i++) { // table.addCell(new PdfPCell(new Phrase(Header[i], smallBold))); PdfPCell c1 = new PdfPCell(new Phrase(Header[i], smallBold)); c1.getBorder(); c1.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(c1); } // table.addCell("Value"); // table.addCell("Location"); table.setHeaderRows(1); // PdfPCell c1 = new PdfPCell(new Phrase("Text",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // c1 = new PdfPCell(new Phrase("Value",smallBold)); // c1.getBorder(); // c1.setHorizontalAlignment(Element.ALIGN_CENTER); // table.addCell(c1); // // table.setHeaderRows(1); PdfPCell[] cells = table.getRow(0).getCells(); for (int j = 0; j < cells.length; j++) { cells[j].setBackgroundColor(new BaseColor(0, 85, 133)); if (j == 0) { cells[j].setHorizontalAlignment(Element.ALIGN_LEFT); } else { cells[j].setHorizontalAlignment(Element.ALIGN_CENTER); } } dataprovider = new DataProvider(_con); // // Font f = FontFactory.getFont(getFilesDir() + "/" + HINDI_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // PdfPCell eCell = new PdfPCell(new Phrase(entry, f)); for (int i = 0; i < data.size(); i++) { Phrase phrase = new Phrase(); phrase.add(new Chunk(data.get(i).get("ASHAName"), subFont)); table.addCell(String.valueOf((i + 1))); table.addCell(data.get(i).get("ASHAName")); table.addCell(data.get(i).get("VillageName")); table.addCell(data.get(i).get("PWName")); table.addCell(data.get(i).get("MotherMCTSID")); table.addCell(data.get(i).get("HusbandName")); table.addCell(Validate.changeDateFormat(data.get(i).get("CheckupVisitDate"))); table.addCell(data.get(i).get("DangerSign")); table.addCell(data.get(i).get("CheckupPlace")); table.addCell(""); PdfPCell[] cells1 = table.getRow(i + 1).getCells(); cells1[0].setHorizontalAlignment(Element.ALIGN_LEFT); // cells1[1].setHorizontalAlignment(Element.ALIGN_CENTER); // cells1[2].setHorizontalAlignment(Element.ALIGN_CENTER); } // table.addCell("Colour"); // table.addCell("Hazen Unit"); // table.addCell("1.2"); // table.addCell("Turbidity"); // table.addCell("NTU"); // table.addCell("2.3"); preface.add(table); }