List of usage examples for com.itextpdf.text Document newPage
public boolean newPage()
From source file:com.hris.payroll.reports.PayslipReportPDF.java
public PayslipReportPDF(int branchId, Date payrollDate) { this.branchId = branchId; this.payrollDate = payrollDate; Document document = null; Rectangle pageSize = new Rectangle(318, 825); try {//from w w w. j a va 2 s .c o m // document = new Document(PageSize.A4, 50, 50, 48, 40); document = new Document(pageSize, 37, 37, 37, 37); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.open(); PdfPTable mainTable = new PdfPTable(1); // mainTable.setTotalWidth(new float[]{ 120, 120 }); mainTable.setWidthPercentage(100); mainTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL); // mainTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // mainTable.setLockedWidth(true); // leftColumnTable(mainTable); // rightColumnTable(mainTable); // for(Employee e : es.findEmployeeByBranch(getBranchId())){ for (PayrollRegister pr : ps.findByBranch(getBranchId(), getPayrollDate())) { document.add(leftColumnTable(pr, getPayrollDate())); document.newPage(); } } catch (DocumentException ex) { Logger.getLogger(PayslipReportPDF.class.getName()).log(Level.SEVERE, null, ex); } finally { document.close(); } }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public Boolean createBackCoverPage(Document document, String backCoverNote) throws DocumentException, MalformedURLException, IOException { document.newPage(); Image backCoverImageFrame = Image .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/txtbook_backpage_300.png")); backCoverImageFrame.scalePercent(24.0f); backCoverImageFrame.setAbsolutePosition(87.0f, 78.0f); backCoverImageFrame.setCompressionLevel(this.settings.compressionLevel); document.add(backCoverImageFrame);/*from ww w.j a va 2 s .co m*/ PdfContentByte canvas = this.writer.getDirectContent(); PdfPTable table = new PdfPTable(1); table.setTotalWidth(215.0f); if (backCoverNote != null && backCoverNote.length() > 0) { Paragraph backCoverEl = new Paragraph(backCoverNote, this.serifFont14); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.addElement(backCoverEl); cell.setPadding(13.0f); cell.setIndent(0.0f); cell.setFixedHeight(310.0f); table.addCell(cell); table.completeRow(); } Element backUrl = new Anchor("txt-book.com", this.sansFont11Gray); backUrl.setName("txt-book.com"); backUrl.setReference("http://www.txt-book.com"); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(2); paragraph.add(backUrl); PdfPCell cell2 = new PdfPCell(); cell2.setBorder(0); cell2.setHorizontalAlignment(2); cell2.addElement(paragraph); cell2.setPadding(0.0f); cell2.setPaddingTop(0.0f); cell2.setIndent(0.0f); table.addCell(cell2); table.completeRow(); table.writeSelectedRows(0, -1, 306.0f, 400.0f, canvas); return Boolean.valueOf(true); }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public Boolean createBlankSpacerPage(Document document) { document.newPage(); this.writer.setPageEmpty(false); return Boolean.valueOf(true); }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public int createContentPagesConversation(Document document) throws DocumentException { float[][] COLUMNS; document.newPage(); ColumnText ct = new ColumnText(this.writer.getDirectContent()); this.currentColumn = 0; if (COLUMNS_REG[0][0] == Txtbook.leftMargin(this.writer, document, this.settings.addFrontCover)) { COLUMNS = COLUMNS_REG;/*from w w w.ja v a 2 s . c o m*/ } else { COLUMNS = COLUMNS_ALT; } ct.setSimpleColumn(COLUMNS[this.currentColumn][0], COLUMNS[this.currentColumn][1], COLUMNS[this.currentColumn][2], COLUMNS[this.currentColumn][3]); Cursor cursor = this.mContext.getContentResolver().query( Uri.parse("content://mms-sms/conversations/" + this.settings.threadId), new String[] { "_id", "ct_t", "normalized_date" }, "normalized_date >= " + this.settings.startDateMillis + " AND normalized_date <= " + this.settings.endDateMillis, null, "normalized_date"); Iterator<Integer> itr = this.settings.getSelectedRows().iterator(); while (itr.hasNext()) { if (cursor.moveToPosition(((Integer) itr.next()).intValue())) { String senderString; Boolean isMe; Long messageId = Long.valueOf(cursor.getLong(cursor.getColumnIndex("_id"))); String mimetype = cursor.getString(cursor.getColumnIndex("ct_t")); if (MMSUtilities.getMessageSenderType(this.mContext, messageId, mimetype) == 1) { senderString = this.settings.theirName; isMe = Boolean.valueOf(false); } else { senderString = this.settings.myName; isMe = Boolean.valueOf(true); } String contentString = PdfObject.NOTHING; Boolean isVideo = Boolean.valueOf(false); if ("application/vnd.wap.multipart.related".equals(mimetype)) { Cursor mmsCursor = this.mContext.getContentResolver().query(Uri.parse("content://mms/part"), null, "mid=" + messageId, null, null); Boolean hasNext = Boolean.valueOf(mmsCursor.moveToFirst()); while (hasNext.booleanValue()) { contentString = PdfObject.NOTHING; Bitmap contentImage = null; isVideo = Boolean.valueOf(false); String partId = mmsCursor.getString(mmsCursor.getColumnIndex("_id")); String mimetype2 = mmsCursor.getString(mmsCursor.getColumnIndex("ct")); if ("application/smil".equals(mimetype2)) { hasNext = Boolean.valueOf(mmsCursor.moveToNext()); } else { if (mimetype2.startsWith("image/")) { contentImage = MMSUtilities.getMmsImage(this.mContext, partId); } else { if (mimetype2.startsWith("text/")) { contentString = mmsCursor.getString(mmsCursor.getColumnIndex("_data")) != null ? MMSUtilities.getMmsText(this.mContext, partId) : mmsCursor.getString(mmsCursor.getColumnIndex("text")); } else { if (mimetype2.startsWith("video/")) { isVideo = Boolean.valueOf(true); contentImage = wrapVideoThumbnailWithFilm(this.mContext, MMSUtilities.getMmsVideoThumbnail(this.mContext, partId)); } else { contentString = mimetype2.startsWith("audio/") ? "[audio message]" : "[unknown message type]"; } } } doAddNextConversation(document, cursor, ct, senderString, contentString, contentImage, isVideo, isMe); hasNext = Boolean.valueOf(mmsCursor.moveToNext()); } } mmsCursor.close(); } else { Cursor smsCursor = this.mContext.getContentResolver().query(Uri.parse("content://sms"), new String[] { HtmlTags.BODY, LicenseKey.LICENSE_DATE }, "_id = " + messageId, null, null); if (smsCursor.moveToFirst()) { contentString = smsCursor.getString(smsCursor.getColumnIndex(HtmlTags.BODY)); } smsCursor.close(); doAddNextConversation(document, cursor, ct, senderString, contentString, null, Boolean.valueOf(false), isMe); } } } return 0; }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public void doAddNextConversation(Document document, Cursor cursor, ColumnText ct, String senderString, String contentString, Bitmap contentImage, Boolean isVideo, Boolean isMe) { float[][] COLUMNS; if (COLUMNS_REG[0][0] == Txtbook.leftMargin(this.writer, document, this.settings.addFrontCover)) { COLUMNS = COLUMNS_REG;//ww w.j a v a 2 s .c o m } else { COLUMNS = COLUMNS_ALT; } String dateString = PdfObject.NOTHING; if (this.settings.useTimestamps.booleanValue()) { Long date = Long.valueOf(cursor.getLong(cursor.getColumnIndex("normalized_date"))); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy h:mm a", Locale.US); simpleDateFormat.setTimeZone(TimeZone.getDefault()); dateString = simpleDateFormat.format(new Date(date.longValue())); } try { this.currentY = ct.getYLine(); addConversationPart(ct, this.currentColumn, dateString, senderString, contentString, contentImage, isVideo, isMe); if (ColumnText.hasMoreText(ct.go(true))) { this.currentColumn = (this.currentColumn + 1) % 2; if (this.currentColumn == 0) { document.newPage(); if (COLUMNS_REG[0][0] == Txtbook.leftMargin(this.writer, document, this.settings.addFrontCover)) { COLUMNS = COLUMNS_REG; } else { COLUMNS = COLUMNS_ALT; } } ct.setSimpleColumn(COLUMNS[this.currentColumn][0], COLUMNS[this.currentColumn][1], COLUMNS[this.currentColumn][2], COLUMNS[this.currentColumn][3]); this.currentY = COLUMNS[this.currentColumn][3]; } ct.setYLine(this.currentY); ct.setText(null); float width = addConversationPart(ct, this.currentColumn, dateString, senderString, contentString, contentImage, isVideo, isMe); int status = ct.go(false); Document document2 = document; ColumnText columnText = ct; addConversationBackground(document2, columnText, this.currentColumn, this.currentY, width, this.currentY - ct.getYLine(), isMe); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public int createContentPagesStorybook(Document document, String title) throws DocumentException { document.newPage(); ((StorybookHeaderFooter) this.writer.getPageEvent()).addHeader(this.writer, document); Cursor cursor = this.mContext.getContentResolver().query( Uri.parse("content://mms-sms/conversations/" + this.settings.threadId), new String[] { "_id", "ct_t", "normalized_date" }, "normalized_date >= " + this.settings.startDateMillis + " AND normalized_date <= " + this.settings.endDateMillis, null, "normalized_date"); int i = 0;/* w w w .j a va 2s .co m*/ Long previousDate = null; String previousSenderString = PdfObject.NOTHING; Iterator<Integer> itr = this.settings.getSelectedRows().iterator(); while (itr.hasNext()) { if (cursor.moveToPosition(((Integer) itr.next()).intValue())) { Long messageId = Long.valueOf(cursor.getLong(cursor.getColumnIndex("_id"))); String mimetype = cursor.getString(cursor.getColumnIndex("ct_t")); int type = MMSUtilities.getMessageSenderType(this.mContext, messageId, mimetype); String senderString = this.settings.myName; String receiverString = this.settings.theirName; if (type == 1) { senderString = this.settings.theirName; receiverString = this.settings.myName; } String contentString = PdfObject.NOTHING; Boolean isVideo = Boolean.valueOf(false); Long date; if ("application/vnd.wap.multipart.related".equals(mimetype)) { Cursor mmsCursor = this.mContext.getContentResolver().query(Uri.parse("content://mms/part"), null, "mid=" + messageId, null, null); Boolean hasNext = Boolean.valueOf(mmsCursor.moveToFirst()); while (hasNext.booleanValue()) { contentString = PdfObject.NOTHING; Bitmap contentImage = null; isVideo = Boolean.valueOf(false); String partId = mmsCursor.getString(mmsCursor.getColumnIndex("_id")); String mimetype2 = mmsCursor.getString(mmsCursor.getColumnIndex("ct")); if ("application/smil".equals(mimetype2)) { hasNext = Boolean.valueOf(mmsCursor.moveToNext()); } else { if (mimetype2.startsWith("image/")) { contentImage = MMSUtilities.getMmsImage(this.mContext, partId); } else { if (mimetype2.startsWith("text/")) { contentString = mmsCursor.getString(mmsCursor.getColumnIndex("_data")) != null ? MMSUtilities.getMmsText(this.mContext, partId) : mmsCursor.getString(mmsCursor.getColumnIndex("text")); } else { if (mimetype2.startsWith("video/")) { isVideo = Boolean.valueOf(true); contentImage = wrapVideoThumbnailWithFilm(this.mContext, MMSUtilities.getMmsVideoThumbnail(this.mContext, partId)); } else { contentString = mimetype2.startsWith("audio/") ? "[audio message]" : "[unknown message type]"; } } } date = null; if (this.settings.useTimestamps.booleanValue()) { date = Long.valueOf(cursor.getLong(cursor.getColumnIndex("normalized_date"))); } try { addStorybookPart(document, i, date, previousDate, senderString, previousSenderString, receiverString, contentString, contentImage, isVideo); } catch (Exception e) { e.printStackTrace(); } previousDate = date; previousSenderString = senderString; hasNext = Boolean.valueOf(mmsCursor.moveToNext()); } } mmsCursor.close(); } else { Cursor smsCursor = this.mContext.getContentResolver().query(Uri.parse("content://sms"), new String[] { HtmlTags.BODY, LicenseKey.LICENSE_DATE }, "_id = " + messageId, null, null); if (smsCursor.moveToFirst()) { contentString = smsCursor.getString(smsCursor.getColumnIndex(HtmlTags.BODY)); } smsCursor.close(); date = null; if (this.settings.useTimestamps.booleanValue()) { date = Long.valueOf(cursor.getLong(cursor.getColumnIndex("normalized_date"))); } try { addStorybookPart(document, i, date, previousDate, senderString, previousSenderString, receiverString, contentString, null, Boolean.valueOf(false)); } catch (Exception e2) { e2.printStackTrace(); } previousDate = date; previousSenderString = senderString; } } i++; } return 0; }
From source file:com.imipgroup.hieuvt.pdf.PdfUtils.java
private static void addTitlePage(Document document) { Paragraph preface = new Paragraph(); addEmptyLine(preface, 1);// ww w. jav a 2s. c om preface.add(new Paragraph("Title of the document", catFont)); addEmptyLine(preface, 1); preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); try { document.add(preface); } catch (DocumentException e) { e.printStackTrace(); } // Start a new page document.newPage(); }
From source file:com.insider.kontrollactive.QualityReportActivity.java
private static void addTitlePage(Document document) throws DocumentException { Paragraph preface = new Paragraph(); // We add one empty line addEmptyLine(preface, 1);/*from ww w . j av a 2 s .co m*/ // Lets write a big header preface.add(new Paragraph("Vr frste pdf!", catFont)); addEmptyLine(preface, 1); // Will create: Report generated by: _name, _date preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); addEmptyLine(preface, 3); preface.add(new Paragraph("This document describes something which is very important ", smallBold)); addEmptyLine(preface, 8); preface.add(new Paragraph( "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); document.add(preface); // Start a new page document.newPage(); }
From source file:com.kohmiho.mpsr.export.PDFGenerator.java
protected void importPages(Document document, PdfWriter writer, String mpsrID, String fileName) throws DocumentException { if (null != fileName) { String filePath = MPSRUI.getFilePath(mpsrID, fileName); PdfReader reader = null;// w w w. ja v a2s . com try { reader = new PdfReader(filePath); } catch (IOException e) { document.add(new Paragraph(String.format("*** Can not load file %s ***", filePath))); // e.printStackTrace(); } if (null != reader) { for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) { document.setPageSize(reader.getPageSize(pageNum)); document.newPage(); PdfImportedPage page = writer.getImportedPage(reader, pageNum); // addPageByImage(writer, page); addPageByTemplate(writer, page); document.setPageSize(DEFAULT_PAGE_SIZE); document.newPage(); } } } }
From source file:com.lawyer.pdfgeneration.AddParagraph.java
public void addNewParagraph(Document document, Font smallBold) throws DocumentException { // TODO Auto-generated method stub Paragraph preface = new Paragraph(); // We add one empty line // Lets write a big header //addEmptyLine(preface, 27); String SomeDataWhichIsDerived = pdfReaderFunction.rep1; // preface.add(new Paragraph("Generated Path of file"+OUTPUTFILE, catFont)); //The new paragraph allows us to set the font of our choice //addEmptyLine(preface, 5); // Will create: Report generated by: _name, _date // preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3smallBold)); // addEmptyLine(preface, 20); preface.add(new Paragraph(SomeDataWhichIsDerived, smallBold)); // addEmptyLine(preface, 25); // preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",redFont)); document.add(preface);//from w w w .j a v a 2s.c o m // Start a new page document.newPage(); }