List of usage examples for com.itextpdf.text.pdf PdfObject NOTHING
String NOTHING
To view the source code for com.itextpdf.text.pdf PdfObject NOTHING.
Click Source Link
PdfNull
-object and for an empty PdfString
-object. From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public int createContentPagesConversation(Document document) throws DocumentException { float[][] COLUMNS; document.newPage();/*from ww w . jav a 2 s .c o m*/ 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; } 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;/* w ww.jav a 2 s . co 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();//from ww w. jav a 2 s . co m ((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; 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.ideationdesignservices.txtbook.pdf.TxtBookPdf.java
public void addStorybookPart(Document document, int i, Long date, Long previousDate, String senderString, String previousSenderString, String receiverString, String contentString, Bitmap contentBitmap, Boolean isVideo) throws DocumentException, MalformedURLException, IOException { Paragraph paragraph = new Paragraph(); if (i == 0) { paragraph.add(new Chunk("T", this.serifFont24)); paragraph.add(new Chunk("his story begins", this.serifFont11)); if (!this.settings.useTimestamps.booleanValue()) { paragraph.add(new Chunk(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR, this.serifFont11)); }/*w ww . j a v a2 s . c o m*/ } else if (!senderString.equals(previousSenderString)) { document.add(Chunk.NEWLINE); } Boolean dateChanged = Boolean.valueOf(false); if (this.settings.useTimestamps.booleanValue()) { SimpleDateFormat dateFormat; if (i == 0) { dateFormat = new SimpleDateFormat("MMMM dd, yyyy", Locale.US); dateFormat.setTimeZone(TimeZone.getDefault()); paragraph.add(new Chunk(" on " + dateFormat.format(new Date(date.longValue())) + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR, this.serifFont11)); } else { dateFormat = new SimpleDateFormat("MMMM dd, yyyy", Locale.US); dateFormat.setTimeZone(TimeZone.getDefault()); String dateString = dateFormat.format(new Date(date.longValue())); String previousDateString = PdfObject.NOTHING; if (previousDate != null) { previousDateString = dateFormat.format(new Date(previousDate.longValue())); } if (!previousDateString.equals(dateString)) { dateChanged = Boolean.valueOf(true); document.add(Chunk.NEWLINE); paragraph.add(new Chunk("O", this.serifFont24)); paragraph.add(new Chunk("n " + dateString + MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR, this.serifFont11)); } } } if (i == 0) { paragraph.add(new Chunk("when " + senderString + " texted " + receiverString + ", ", this.serifFont11)); } if (contentString.length() > 0) { Boolean addPhrase = Boolean.valueOf(false); String phrase = null; if (dateChanged.booleanValue()) { paragraph.add(new Chunk(new StringBuilder(String.valueOf(senderString)).append(" texted ") .append(receiverString).append(", ").toString(), this.serifFont11)); } else if (!(i == 0 || dateChanged.booleanValue() || senderString.equals(previousSenderString))) { Boolean isOpening = Boolean .valueOf(this.wasLastPhraseOpening.booleanValue() ? this.generator.nextBoolean() : true); int phraseIdx = this.lastPhraseIdx; if (isOpening.booleanValue() && !this.wasLastPhraseOpening.booleanValue()) { this.lastPhraseIdx = -1; } if (isOpening.booleanValue()) { do { phraseIdx = this.generator.nextInt(this.openings.length); } while (phraseIdx == this.lastPhraseIdx); phrase = this.openings[phraseIdx]; } else { do { phraseIdx = this.generator.nextInt(this.closings.length); } while (phraseIdx == this.lastPhraseIdx); phrase = this.closings[phraseIdx]; } this.lastPhraseIdx = phraseIdx; this.wasLastPhraseOpening = isOpening; phrase = phrase.replace("[speaker]", senderString); addPhrase = Boolean.valueOf(true); } if (addPhrase.booleanValue() && this.wasLastPhraseOpening.booleanValue()) { paragraph.add(new Chunk(phrase, this.serifFont11)); } paragraph.add(new Chunk("\"" + contentString.trim() + "\"", this.serifFont11)); if (addPhrase.booleanValue() && !this.wasLastPhraseOpening.booleanValue()) { paragraph.add(new Chunk(phrase, this.serifFont11)); } document.add(paragraph); } else if (contentBitmap != null) { if (i != 0) { paragraph.add(new Chunk(new StringBuilder(String.valueOf(senderString)).append(" sent ") .append(receiverString).append(":").toString(), this.serifFont11)); document.add(paragraph); document.add(Chunk.NEWLINE); } ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (isVideo.booleanValue()) { contentBitmap.compress(CompressFormat.PNG, 50, stream); } else { contentBitmap.compress(CompressFormat.JPEG, 50, stream); } Image contentImage = Image.getInstance(stream.toByteArray()); contentImage.scaleToFit(445.0f, 195.0f); contentImage.setAlignment(1); if (isVideo.booleanValue()) { contentImage.setCompressionLevel(this.settings.compressionLevel); } document.add(contentImage); document.add(Chunk.NEWLINE); } }