List of usage examples for com.itextpdf.text.pdf.parser Vector I1
int I1
To view the source code for com.itextpdf.text.pdf.parser Vector I1.
Click Source Link
From source file:com.cyberninjas.invoice.pdf.InvoiceTextExtractionStrategy.java
License:Open Source License
/** * Parses the text with a PDF based on the given settings. * * @param settings settings used to parse the document. *//*w w w .j av a2s . c o m*/ public void parse(PdfInvoiceSettings settings) { cumulativeCostLocationMap = new HashMap(); cumulativeCostSubtotalLocation = null; totalFundedAmountLocation = null; // locate the cumulative cost heading for aligning cumulative cost amounts TextChunk cumulativeCostHeadingTextChunk = matchText(settings.getCumulativeCostHeadingText()); if (cumulativeCostHeadingTextChunk == null) { log.warn("Failed to locate the cumulative cost heading based on the text [" + settings.getCumulativeCostHeadingText() + "]"); } // locate the ItemIds and their containing rows StringBuilder sb = new StringBuilder(); TextChunk lastChunk = null; String lastItemId = null; for (TextChunk chunk : getTextChunks()) { if (lastChunk == null) { sb.append(chunk.getText()); } else { if (chunk.sameLine(lastChunk)) { // we only insert a blank space if the trailing character of the previous string wasn't a space, and the leading character of the current string isn't a space if (isChunkAtWordBoundary(chunk, lastChunk) && !startsWithSpace(chunk.getText()) && !endsWithSpace(lastChunk.getText())) { sb.append(' '); } sb.append(chunk.getText()); } else { if (sb.indexOf(settings.getItemIdSeparator()) > 0) { String itemId = sb.substring(0, sb.indexOf(settings.getItemIdSeparator())); cumulativeCostLocationMap.put(itemId, null); lastItemId = itemId; } if (lastItemId != null && sb.toString().matches(settings.getItemRowPattern())) { cumulativeCostLocationMap.put(lastItemId, new Vector(cumulativeCostHeadingTextChunk.getEndLocation().get(Vector.I1), lastChunk.getEndLocation().get(Vector.I2), 0)); lastItemId = null; } sb = new StringBuilder(); sb.append(chunk.getText()); } } lastChunk = chunk; } // check if all the ItemId rows have been located - if not, position based on the location of the ItemId text cumulativeCostLocationMap.keySet().stream() .filter((itemId) -> (cumulativeCostLocationMap.get(itemId) == null)).forEach((itemId) -> { TextChunk itemIdTextChunk = this.matchText(itemId); if (itemIdTextChunk != null) { cumulativeCostLocationMap.replace(itemId, new Vector(cumulativeCostHeadingTextChunk.getEndLocation().get(Vector.I1), itemIdTextChunk.getEndLocation().get(Vector.I2), 0)); } else { log.warn("Failed to locate row for itemId [" + itemId + "]"); } }); // locate where to write the cumulative cost subtotal TextChunk subTotalLabel = matchText(settings.getSubtotalLabelText()); if (subTotalLabel != null) { cumulativeCostSubtotalLocation = new Vector( cumulativeCostHeadingTextChunk.getEndLocation().get(Vector.I1), subTotalLabel.getEndLocation().get(Vector.I2), 0); } // locate where to write the total funded amount TextChunk totalFundedAmountLabel = matchText(settings.getTotalFundedAmountLabelText()); if (totalFundedAmountLabel != null) { totalFundedAmountLocation = new Vector( totalFundedAmountLabel.getEndLocation().get(Vector.I1) + settings.getTotalFundedAmountOffset(), totalFundedAmountLabel.getEndLocation().get(Vector.I2), 0); } }
From source file:com.cyberninjas.invoice.pdf.PdfInvoiceEditor.java
License:Open Source License
/** * Writes the cumulative cost amount to the given ItemId row. * * @param itemId the ItemId./*from w ww . j a va2 s . com*/ * @param amount the amount to write. */ @Override public void writeCumulativeCost(String itemId, double amount) { PageVector cumulativeCostLocation = cumulativeCostLocationMap.get(itemId); if (cumulativeCostLocation != null) { writeText(cumulativeCostLocation.getPageNum(), numberFormat.format(amount), settings.getCumulativeCostAlignment(), cumulativeCostLocation.get(Vector.I1), cumulativeCostLocation.get(Vector.I2)); } else { log.warn("Failed to write the cumulative cost for item id [" + itemId + "]. Location not identified."); } }
From source file:com.cyberninjas.invoice.pdf.PdfInvoiceEditor.java
License:Open Source License
/** * Writes the cumulative cost subtotal amount to the identified location. * * @param amount the amount to write.//from w ww . j a va 2s .c o m */ @Override public void writeCumulativeCostSubtotal(final double amount) { if (cumulativeCostSubtotalLocation != null) { writeText(cumulativeCostSubtotalLocation.getPageNum(), numberFormat.format(amount), settings.getCumulativeCostSubtotalAlignment(), cumulativeCostSubtotalLocation.get(Vector.I1), cumulativeCostSubtotalLocation.get(Vector.I2)); } else { log.warn("Failed to write the cumulative cost subtotal. Location not identified."); } }
From source file:com.cyberninjas.invoice.pdf.PdfInvoiceEditor.java
License:Open Source License
/** * Writes the total funded amount to the identified location. * * @param amount the amount to write.//from w ww . j a va 2 s . co m */ @Override public void writeTotalFundedAmount(final double amount) { if (totalFundedAmountLocation != null) { writeText(totalFundedAmountLocation.getPageNum(), numberFormat.format(amount), settings.getTotalFundedAmountAlignment(), totalFundedAmountLocation.get(Vector.I1), totalFundedAmountLocation.get(Vector.I2)); } else { log.warn("Failed to write the total funded amount. Location not identified."); } }
From source file:com.cyberninjas.invoice.pdf.PdfInvoiceEditor.java
License:Open Source License
/** * Write text relative to the matching reference text. * * <p>/*w ww . j a va 2 s .c o m*/ * Note: Due to the way PDF stores text, found blocks of text may contain additional text beyond the reference text. * This can cause blocks to be larger than expected requiring a larger or smaller offset to be set to align * properly.</p> * * @param text the text to write. * @param referenceText the reference text to write relative to. * @param offset the offset to write relative to the reference text. * @param align the alignment. * @param findAll indicates if text should be written at every occurrence or only the first. * @throws IOException on I/O error. */ public final void writeTextAtOffset(String text, String referenceText, float offset, final Alignment align, boolean findAll) throws IOException { PdfReader reader = getReader(); PdfReaderContentParser parser = new PdfReaderContentParser(reader); TextChunkExtractionStrategy strategy; for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) { strategy = parser.processContent(pageNum, new TextChunkExtractionStrategy()); if (findAll) { for (TextChunk textChunk : strategy.matchAllText(referenceText)) { this.writeText(pageNum, text, align, textChunk.getEndLocation().get(Vector.I1) + offset, textChunk.getEndLocation().get(Vector.I2)); } } else { TextChunk textChunk = strategy.matchText(referenceText); if (textChunk != null) { this.writeText(pageNum, text, align, textChunk.getEndLocation().get(Vector.I1) + offset, textChunk.getEndLocation().get(Vector.I2)); } } } }
From source file:com.cyberninjas.pdf.PageVector.java
License:Open Source License
/** * Creates a new PageVector.// www . j ava2 s . c om * * @param pageNum the page number * @param vector the point in space. */ public PageVector(final int pageNum, final Vector vector) { this(pageNum, vector.get(Vector.I1), vector.get(Vector.I2), vector.get(Vector.I3)); }
From source file:com.ideationdesignservices.txtbook.sms.MessageListAdapter.java
public View buildView(View view, Context context, Cursor cursor, int type) { int position = cursor.getPosition(); TextView userNameTextView = (TextView) view.findViewById(R.id.userNameTextView); LinearLayout userMessageContent = (LinearLayout) view.findViewById(R.id.userMessageContent); userMessageContent.removeAllViews(); if (type == -1) { type = getItemViewType(position); }// w w w.j a va 2 s . c om switch (type) { case Vector.I1 /*0*/: userNameTextView.setText(this.myName); userMessageContent.setGravity(3); view.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.conversation_cell_bg_dark)); break; case Vector.I2 /*1*/: userNameTextView.setText(this.theirName); userMessageContent.setGravity(5); view.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.conversation_cell_bg_light)); break; } Long date = Long.valueOf(0); LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, 150, 0.0f); layoutParams.setMargins(0, 0, 0, 10); layoutParams = new LinearLayout.LayoutParams(-2, -2, BaseField.BORDER_WIDTH_THIN); layoutParams.setMargins(0, 0, 0, 10); layoutParams = new LinearLayout.LayoutParams(26, 150, 0.0f); layoutParams.setMargins(0, 0, 0, 10); String string = cursor.getString(cursor.getColumnIndex("ct_t")); Bitmap mmsImage = null; Long messageId = Long.valueOf(cursor.getLong(cursor.getColumnIndex("_id"))); if (this.useTimestamps.booleanValue()) { date = Long.valueOf(cursor.getLong(cursor.getColumnIndex("normalized_date"))); } View textView; if ("application/vnd.wap.multipart.related".equals(string)) { String selectionPart = "mid=" + messageId; Cursor mmsCursor = context.getContentResolver().query(Uri.parse("content://mms/part"), null, selectionPart, null, null); for (Boolean hasNext = Boolean.valueOf(mmsCursor.moveToFirst()); hasNext .booleanValue(); hasNext = Boolean.valueOf(mmsCursor.moveToNext())) { try { String partId = mmsCursor.getString(mmsCursor.getColumnIndex("_id")); String mimetype = mmsCursor.getString(mmsCursor.getColumnIndex("ct")); if (!"application/smil".equals(mimetype)) { if (mimetype.startsWith("image/")) { mmsImage = MMSUtilities.getMmsImage(this.mContext, partId); ImageView imageView = new ImageView(context); imageView.setImageBitmap(mmsImage); imageView.setVisibility(0); imageView.setLayoutParams(layoutParams); imageView.setAdjustViewBounds(true); imageView.setContentDescription(context.getString(R.string.user_message_image)); userMessageContent.addView(imageView); if (mmsImage == null || this.usePhotos.booleanValue()) { imageView.setAlpha(BaseField.BORDER_WIDTH_THIN); } else { imageView.setAlpha(0.5f); } } else { if (mimetype.startsWith("text/")) { String body; if (mmsCursor.getString(mmsCursor.getColumnIndex("_data")) != null) { body = MMSUtilities.getMmsText(context, partId); } else { body = mmsCursor.getString(mmsCursor.getColumnIndex("text")); } textView = new TextView(context); textView.setLayoutParams(layoutParams); textView.setTextSize(14.0f); textView.setText(body); textView.setGravity(119); userMessageContent.addView(textView); } else { if (mimetype.startsWith("video/")) { mmsImage = MMSUtilities.getMmsVideoThumbnail(context, partId); textView = new LinearLayout(context); textView.setOrientation(0); textView.setLayoutParams(new RelativeLayout.LayoutParams(-2, -2)); textView = new ImageView(context); textView.setImageDrawable( context.getResources().getDrawable(R.drawable.film_strip_left)); textView.setLayoutParams(layoutParams); textView.setContentDescription(context.getString(R.string.user_message_image)); textView.addView(textView); textView = new ImageView(context); textView.setImageBitmap(mmsImage); textView.setVisibility(0); textView.setLayoutParams(layoutParams); textView.setAdjustViewBounds(true); textView.setContentDescription(context.getString(R.string.user_message_image)); textView.addView(textView); textView = new ImageView(context); textView.setImageDrawable( context.getResources().getDrawable(R.drawable.film_strip_right)); textView.setLayoutParams(layoutParams); textView.setContentDescription(context.getString(R.string.user_message_image)); textView.addView(textView); if (mmsImage == null || this.usePhotos.booleanValue()) { textView.setAlpha(BaseField.BORDER_WIDTH_THIN); } else { textView.setAlpha(0.5f); } userMessageContent.addView(textView); } else { if (mimetype.startsWith("audio/")) { textView = new TextView(context); textView.setLayoutParams(layoutParams); textView.setTextSize(14.0f); textView.setText("[audio message]"); textView.setGravity(119); userMessageContent.addView(textView); } else { textView = new TextView(context); textView.setLayoutParams(layoutParams); textView.setTextSize(14.0f); textView.setText("[unknown message type]"); textView.setGravity(119); userMessageContent.addView(textView); } } } } } } catch (OutOfMemoryError e) { } } 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()) { textView = new TextView(context); textView.setLayoutParams(layoutParams); textView.setTextSize(14.0f); textView.setText(smsCursor.getString(smsCursor.getColumnIndex(HtmlTags.BODY))); textView.setGravity(119); userMessageContent.addView(textView); } smsCursor.close(); } TextView userDateTextView = (TextView) view.findViewById(R.id.userDateTextView); if (this.useTimestamps.booleanValue()) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy h:mm a", Locale.US); simpleDateFormat.setTimeZone(TimeZone.getDefault()); userDateTextView.setText(simpleDateFormat.format(new Date(date.longValue()))); } CheckBox checkbox = (CheckBox) view.findViewById(R.id.userCheckBox); if (mmsImage == null || this.usePhotos.booleanValue()) { checkbox.setChecked( ((ConversationActivity) this.mContext).selectedRows.contains(Integer.valueOf(position))); checkbox.setEnabled(true); userNameTextView.setTextColor(-16777216); userDateTextView.setTextColor(Color.argb(100, 119, 119, 119)); } else { checkbox.setChecked(false); checkbox.setEnabled(false); userNameTextView.setTextColor(Color.argb(50, 0, 0, 0)); userDateTextView.setTextColor(Color.argb(50, 119, 119, 119)); } checkbox.setTag(Integer.valueOf(position)); checkbox.setOnClickListener(new OnClickListener() { public void onClick(View view) { Integer tagPosition = (Integer) view.getTag(); if (((CheckBox) view).isChecked()) { ((ConversationActivity) MessageListAdapter.this.mContext).selectedRows.add(tagPosition); } else { ((ConversationActivity) MessageListAdapter.this.mContext).selectedRows.remove(tagPosition); } ((ConversationActivity) MessageListAdapter.this.mContext).updateSelectOrClearAllButton(); } }); return view; }