public ColumnText reconfigure( PdfContentByte cb, Phrase p ) { float filledWidth = ColumnText.getWidth( p, runDirection, 0 ) + 0.5f; ColumnText ct = new ColumnText( cb ); ct.setRunDirection( runDirection ); if ( alignment == Element.ALIGN_LEFT ) { ct.setSimpleColumn( llx, lly, llx + filledWidth, ury, leading, alignment ); } else if ( alignment == Element.ALIGN_RIGHT ) { ct.setSimpleColumn( urx - filledWidth, lly, urx, ury, leading, alignment ); } else if ( alignment == Element.ALIGN_CENTER ) { float delta = ( ( urx - llx ) - filledWidth ) / 2; ct.setSimpleColumn( urx + delta, lly, urx - delta, ury, leading, alignment ); } else { ct.setSimpleColumn( llx, lly, urx, ury, leading, alignment ); } return ct; } }
/** * Outputs the lines to the document. It is equivalent to <CODE>go(false)</CODE>. * * @return returns the result of the operation. It can be <CODE>NO_MORE_TEXT</CODE> * and/or <CODE>NO_MORE_COLUMN</CODE> * @throws DocumentException on error */ public int go() throws DocumentException { return go(false); }
/** * Adds an iText element to the cell. * * @param element */ public void addElement(Element element) { if (table != null) { table = null; column.setText(null); } column.addElement(element); }
public static ColumnText createColumnText() { ColumnText text = new ColumnText( null ); // make iText first line alignment compatible with open office text.setAdjustFirstLine( false ); return text; }
/** * Creates an independent duplicated of the instance <CODE>org</CODE>. * * @param org the original <CODE>ColumnText</CODE> * @return the duplicated */ public static ColumnText duplicate(ColumnText org) { ColumnText ct = new ColumnText(null); ct.setACopy(org); return ct; }
ColumnText ct = new ColumnText(writer.getDirectContent()); Paragraph p = new Paragraph(); p.setLeading(0); ct.addElement(p); ct.addElement(ptable); boolean he = ptable.isHeadersInEvent(); ptable.setHeadersInEvent(true); int loop = 0; while (true) { ct.setSimpleColumn(indentLeft(), indentBottom(), indentRight(), indentTop() - currentHeight); int status = ct.go(); if ((status & ColumnText.NO_MORE_TEXT) != 0) { text.moveText(0, ct.getYLine() - indentTop() + currentHeight); currentHeight = indentTop() - ct.getYLine(); break; if (indentTop() - currentHeight == ct.getYLine()) ++loop; else
alignment = Element.ALIGN_LEFT; canvas.saveState(); ColumnText ct = new ColumnText(canvas); float lly = -1; float ury = 2; canvas.concatCTM(cos, sin, -sin, cos, x, y); ct.setSimpleColumn(phrase, llx, lly, urx, ury, 2, alignment); if (runDirection == PdfWriter.RUN_DIRECTION_RTL) { if (alignment == Element.ALIGN_LEFT) alignment = Element.ALIGN_LEFT; ct.setAlignment(alignment); ct.setArabicOptions(arabicOptions); ct.setRunDirection(runDirection); try { ct.go();
setBottom(getTop() - getFixedHeight()); else { ColumnText ct = ColumnText.duplicate(getColumn()); float right, top, left, bottom; if (pivoted) { ct.go(true); } catch (DocumentException e) { throw new ExceptionConverter(e); setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - ct.getFilledWidth()); else { float yLine = ct.getYLine(); if (isUseDescender()) yLine += ct.getDescender(); setBottom(yLine - getEffectivePaddingBottom());
columnText.setCanvas(canvas); if (columnDefs.isEmpty()) { throw new DocumentException("MultiColumnText has no columns"); columnText.setYLine(top); columnText.setSimpleColumn(left[2], left[3], right[0], right[1]); } else { columnText.setColumns(left, right); int result = columnText.go(); if ((result & ColumnText.NO_MORE_TEXT) != 0) { done = true; top = columnText.getYLine(); } else if (shiftCurrentColumn()) { top = nextY; currentHeight = documentY - columnText.getYLine();
ct = new ColumnText(null); ct.setSimpleColumn(ph, rect.getLeft(), rect.getBottom(), rect.getRight(), rect.getTop(), maxFontSize, Element.ALIGN_LEFT); ct.setRunDirection(runDirection); status = ct.go(true); if ((status & ColumnText.NO_MORE_TEXT) != 0) return maxFontSize; for (int k = 0; k < 50; ++k) { //just in case it doesn't converge size = (min + max) / 2; ct = new ColumnText(null); font.setSize(size); ct.setSimpleColumn(new Phrase(text, font), rect.getLeft(), rect.getBottom(), rect.getRight(), rect.getTop(), size, Element.ALIGN_LEFT); ct.setRunDirection(runDirection); status = ct.go(true); if ((status & ColumnText.NO_MORE_TEXT) != 0) { if (max - min < size * precision)
private void setColIdx( int idx ) { colIdx = idx; PdfPCell cell = StylableDocumentSection.getCell( layoutTable, colIdx ); text.setSimpleColumn( cell.getLeft() + cell.getPaddingLeft(), -getAdjustedPageHeight(), cell.getRight() - cell.getPaddingRight(), 0.0f ); cell.setColumn( ColumnText.duplicate( text ) ); }
/** * Consumes part of the content of the cell. * @param height the hight of the part that has to be consumed * @since 2.1.6 */ void consumeHeight(float height) { float rightLimit = getRight() - getEffectivePaddingRight(); float leftLimit = getLeft() + getEffectivePaddingLeft(); float bry = height - getEffectivePaddingTop() - getEffectivePaddingBottom(); if (getRotation() != 90 && getRotation() != 270) { column.setSimpleColumn(leftLimit, bry + 0.001f, rightLimit, 0); } else { column.setSimpleColumn(0, leftLimit, bry + 0.001f, rightLimit); } try { column.go(true); } catch (DocumentException e) { // do nothing } }
protected void writePageAnchor(int pageIndex) throws DocumentException { Map pdfFontAttrs = getDefaultPdfFontAttributes(); Chunk chunk; if (pdfFontAttrs == null) { chunk = new Chunk(" "); } else { Font pdfFont = getFont(pdfFontAttrs, getLocale()); chunk = new Chunk(" ", pdfFont); } chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1)); tagHelper.startPageAnchor(); ColumnText colText = new ColumnText(pdfContentByte); colText.setSimpleColumn( new Phrase(chunk), 0, jasperPrint.getPageHeight(), 1, 1, 0, Element.ALIGN_LEFT ); colText.go(); tagHelper.endPageAnchor(); }
private void simulateText() { int res = 0; try { res = text.go( true ); } catch ( DocumentException e ) { throw new XWPFConverterException( e ); } if ( ColumnText.hasMoreText( res ) ) { // text does not fit into current column // split it to a new column columnBreak(); } }
/** * Simplified method for rectangular columns. * * @param llx the lower left x corner * @param lly the lower left y corner * @param urx the upper right x corner * @param ury the upper right y corner * @param leading the leading * @param alignment the column alignment */ public void setSimpleColumn(float llx, float lly, float urx, float ury, float leading, int alignment) { setLeading(leading); this.alignment = alignment; setSimpleColumn(llx, lly, urx, ury); }
/** * Simplified method for rectangular columns. * * @param phrase a <CODE>Phrase</CODE> * @param llx the lower left x corner * @param lly the lower left y corner * @param urx the upper right x corner * @param ury the upper right y corner * @param leading the leading * @param alignment the column alignment */ public void setSimpleColumn(Phrase phrase, float llx, float lly, float urx, float ury, float leading, int alignment) { addText(phrase); setSimpleColumn(llx, lly, urx, ury, leading, alignment); }
protected void drawComplexText( final RenderableComplexText node, final Graphics2D g2 ) { try { final Phrase p = createPhrase( node ); final ColumnConfig cc = createColumnText( node ); final PdfGraphics2D pg2 = (PdfGraphics2D) getGraphics(); final PdfContentByte cb = pg2.getRawContentByte(); ColumnText ct = cc.reconfigure( cb, p ); ct.setText( p ); if ( ct.go( false ) == ColumnText.NO_MORE_COLUMN ) { throw new InvalidReportStateException( "iText signaled an error when printing text. Failing to prevent silent data-loss: Width=" + ct.getFilledWidth() ); } } catch ( DocumentException e ) { throw new InvalidReportStateException( e ); } }
/** * Construct a MultiColumnText container of the specified height. * If height is <CODE>AUTOMATIC</CODE>, fill complete pages until done. * If a specific height is used, it may span one or more pages. * * @param height */ public MultiColumnText(float height) { columnDefs = new ArrayList(); desiredHeight = height; top = AUTOMATIC; // canvas will be set later columnText = new ColumnText(null); totalHeight = 0f; }
/** * Shows a line of text. Only the first line is written. * * @param canvas where the text is to be written to * @param alignment the alignment * @param phrase the <CODE>Phrase</CODE> with the text * @param x the x reference position * @param y the y reference position * @param rotation the rotation to be applied in degrees counterclockwise */ public static void showTextAligned(PdfContentByte canvas, int alignment, Phrase phrase, float x, float y, float rotation) { showTextAligned(canvas, alignment, phrase, x, y, rotation, PdfWriter.RUN_DIRECTION_NO_BIDI, 0); }
public void addElement( Element element ) { if ( element instanceof SectionPdfPTable ) { // section is a specific container // it is not added to direct parent container // but to section parent container which may be // StylableDocument or StylableTableCell or StylableHeaderFooter table cell sectionParent.addElement( element ); } else { // ordinary element texts.get( colIdx ).addElement( element ); simulateText(); } }