ColumnText ct = new ColumnText(cb); Phrase myText = new Phrase("TEST paragraph\nAfter Newline"); ct.setSimpleColumn(myText, 34, 750, 580, 317, 15, Element.ALIGN_LEFT); ct.go();
boolean createHere = false; if (compositeColumn == null) { compositeColumn = new ColumnText(canvas); compositeColumn.setAlignment(para.getAlignment()); compositeColumn.setIndent(para.getIndentationLeft() + para.getFirstLineIndent(), false); compositeColumn.setExtraParagraphSpace(para.getExtraParagraphSpace()); compositeColumn.setFollowingIndent(para.getIndentationLeft()); compositeColumn.setRightIndent(para.getIndentationRight()); compositeColumn.setLeading(para.getLeading(), para.getMultipliedLeading()); compositeColumn.setRunDirection(runDirection); compositeColumn.setArabicOptions(arabicOptions); compositeColumn.setSpaceCharRatio(spaceCharRatio); compositeColumn.addText(para); if (!(firstPass && adjustFirstLine)) { yLine -= para.getSpacingBefore(); compositeColumn.setUseAscender((firstPass || descender == 0) && adjustFirstLine ? useAscender : false); compositeColumn.setInheritGraphicState(inheritGraphicState); compositeColumn.leftX = leftX; compositeColumn.rightX = rightX; boolean keepCandidate = para.getKeepTogether() && createHere && !(firstPass && adjustFirstLine); boolean s = simulate || keepCandidate && keep == 0; if (isTagged(canvas) && !s) { canvas.openMCBlock(para); status = compositeColumn.go(s); if (isTagged(canvas) && !s) { canvas.closeMCBlock(para);
float width = box.getWidth() - 4 * offsetX - extraMarginLeft; float factor = ufont.getFontDescriptor(BaseFont.BBOXURY, 1) - ufont.getFontDescriptor(BaseFont.BBOXLLY, 1); ColumnText ct = new ColumnText(null); if (usize == 0) { usize = h / factor; usize = 12; float step = Math.max((usize - 4) / 10, 0.2f); ct.setSimpleColumn(0, -h, width, 0); ct.setAlignment(alignment); ct.setRunDirection(rtl); for (; usize > 4; usize -= step) { ct.setYLine(0); changeFontSize(phrase, usize); ct.setText(phrase); ct.setLeading(factor * usize); int status = ct.go(true); if ((status & ColumnText.NO_MORE_COLUMN) == 0) break; ct.setCanvas(app); float leading = usize * factor; float offsetY = offsetX + h - ufont.getFontDescriptor(BaseFont.BBOXURY, usize); ct.setSimpleColumn(extraMarginLeft + 2 * offsetX, -20000, box.getWidth() - 2 * offsetX, offsetY + leading); ct.setLeading(leading); ct.setAlignment(alignment); ct.setRunDirection(rtl); ct.setText(phrase); ct.go();
currentCompositeColumn = ColumnText.duplicate(compositeColumn); if (nextElement instanceof PdfDiv) { PdfDiv floatingElement = (PdfDiv) nextElement; status = floatingElement.layout(compositeColumn.getCanvas(), useAscender, true, floatLeftX, minY, floatRightX, yLine); if ((status & ColumnText.NO_MORE_TEXT) == 0) { yLine = minYLine; floatLeftX = leftX; floatRightX = rightX; status = floatingElement.layout(compositeColumn.getCanvas(), useAscender, true, floatLeftX, minY, floatRightX, yLine); if ((status & ColumnText.NO_MORE_TEXT) == 0) { floatingElements.add(0, floatingElement); status = floatingElement.layout(compositeColumn.getCanvas(), useAscender, simulate, floatLeftX, minY, floatRightX, yLine); floatLeftX += floatingElement.getActualWidth(); leftWidth += floatingElement.getActualWidth(); } else if (floatingElement.getFloatType() == PdfDiv.FloatType.RIGHT) { status = floatingElement.layout(compositeColumn.getCanvas(), useAscender, simulate, floatRightX - floatingElement.getActualWidth() - 0.01f, minY, floatRightX, yLine); floatRightX -= floatingElement.getActualWidth(); rightWidth += floatingElement.getActualWidth(); floatingElements.add(0, nextElement); if (currentCompositeColumn != null) currentCompositeColumn.setText(null); break; } else { if (nextElement instanceof Spaceable && (!ignoreSpacingBefore || !currentCompositeColumn.isIgnoreSpacingBefore() || ((Spaceable) nextElement).getPaddingTop() != 0)) { yLine -= ((Spaceable) nextElement).getSpacingBefore();
ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(rectangle); ct.addElement(p1); ct.addElement(p2); ct.go();
ColumnText ct = new ColumnText(isTagged(writer) ? text : writer.getDirectContent()); ct.setRunDirection(ptable.getRunDirection()); newPage(); if (isTagged(writer)) { ct.setCanvas(text); ct.setAdjustFirstLine(false); 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) { if (isTagged(writer)) { text.setTextMatrix(indentLeft(), ct.getYLine()); } else { text.moveText(0, ct.getYLine() - indentTop() + currentHeight); currentHeight = indentTop() - ct.getYLine(); break; if (indentTop() - currentHeight == ct.getYLine()) ++loop; else
signedBy = ""; Rectangle sr2 = new Rectangle(signatureRect.getWidth() - MARGIN, signatureRect.getHeight() - MARGIN ); float signedSize = ColumnText.fitText(font, signedBy, sr2, -1, runDirection); ColumnText ct2 = new ColumnText(t); ct2.setRunDirection(runDirection); ct2.setSimpleColumn(new Phrase(signedBy, font), signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), signedSize, Element.ALIGN_LEFT); ct2.go(); break; case GRAPHIC_AND_DESCRIPTION: ct2 = new ColumnText(t); ct2.setRunDirection(runDirection); ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT); y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2; p.add(new Chunk(im, x + (signatureRect.getWidth() - im.getScaledWidth()) / 2, y, false)); ct2.addElement(p); ct2.go(); break; case GRAPHIC: ct2 = new ColumnText(t); ct2.setRunDirection(runDirection); ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT); y = (signatureRect.getHeight() - im.getScaledHeight()) / 2; p.add(new Chunk(im, x, y, false)); ct2.addElement(p);
/** * 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(final PdfContentByte canvas, final int alignment, final Phrase phrase, final float x, final float y, final float rotation) { showTextAligned(canvas, alignment, phrase, x, y, rotation, PdfWriter.RUN_DIRECTION_NO_BIDI, 0); }
// I define a width of 200pt float width = 200; // I define the height as 10000pt (which is much more than I'll ever need) float max = 10000; // I create a column without a `writer` (strange, but it works) ColumnText ct = new ColumnText(null); ct.setSimpleColumn(new Rectangle(width, max)); for (Element e : el) { ct.addElement(e); } // I add content in simulation mode ct.go(true); // Now I ask the column for its Y position float y = ct.getYLine();
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) { ct.setAlignment(alignment); ct.setArabicOptions(arabicOptions); ct.setRunDirection(runDirection); try { ct.go(); } catch (DocumentException e) { throw new ExceptionConverter(e);
public int go(final boolean simulate, final IAccessibleElement elementToGo) throws DocumentException { isWordSplit = false; if (composite) { return goComposite(simulate); if (isTagged(canvas) && elementToGo instanceof ListItem) { lBody = ((ListItem) elementToGo).getListBody(); addWaitingPhrase(); if (bidiLine == null) { return NO_MORE_TEXT; graphics = canvas; pdf = canvas.getPdfDocument(); if (!isTagged(canvas)) { text = canvas.getDuplicate(inheritGraphicState); } else { if (isUseAscender() && Float.isNaN(firstLineY)) { currentLeading = line.getAscender(); } else { updateFilledWidth(rectangularWidth - line.widthLeft()); x1 = leftX; } else { float yTemp = yLine - currentLeading; float xx[] = findLimitsTwoLines(); if (xx == null) { status = NO_MORE_COLUMN;
float netWidth = currentMaxHeight - cell.getEffectivePaddingTop() - cell.getEffectivePaddingBottom(); float netHeight = cell.getWidth() - cell.getEffectivePaddingLeft() - cell.getEffectivePaddingRight(); ColumnText ct = ColumnText.duplicate(cell.getColumn()); ct.setCanvases(canvases); ct.setSimpleColumn(0, 0, netWidth + 0.001f, -netHeight); try { ct.go(true); } catch (DocumentException e) { throw new ExceptionConverter(e); float calcHeight = -ct.getYLine(); if (netWidth <= 0 || netHeight <= 0) { calcHeight = 0; calcHeight -= ct.getDescender(); ct = ColumnText.duplicate(cell.getColumn()); } else { ct = cell.getColumn(); ct.setCanvases(canvases); ct.setSimpleColumn(-0.003f, -0.001f, netWidth + 0.003f, calcHeight); float pivotX; float pivotY; ct.go(); } catch (DocumentException e) { throw new ExceptionConverter(e);
class MyPdfPTableEvent implements PdfPTableEvent { public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { } public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { ColumnText ct = new ColumnText(canvases[PdfPTable.TEXTCANVAS]); for (int i = 1; i < widths[1].length; i++) { Rectangle position = new Rectangle(widths[1][i - 1], heights[1], widths[1][i], heights[2]); ct.setSimpleColumn(position); ct.addText(new Phrase("This inner table header will always be repeated")); try { ct.go(); } catch (DocumentException ex) { } } } }
BaseFont bf = BaseFont.createFont( "c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font font = new Font(bf, 20); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(36, 730, 569, 36); column.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); column.addElement(new Paragraph( "\u0627\u0644\u0645\u0648\u0642\u0639 \u0627\u0644\u0625\u0644\u0643\u062a\u0631\u0648\u0646\u064a", font)); column.go();
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 & 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 & NO_MORE_TEXT) != 0) { if (max - min < size * precision) {
Phrase p = new Phrase("This text is added at the top of the column."); ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(rect); ct.setUseAscender(true); ct.addText(p); 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();
column.setSimpleColumn(0, 0, paragraphWidth, paragraphHeight); column.setExtraParagraphSpace(0f); column.addElement(paragraph); column.go();
ColumnText ct = ColumnText.duplicate(cell.getColumn()); float left = cell.getLeft() + cell.getEffectivePaddingLeft(); float bottom = cell.getTop() + cell.getEffectivePaddingBottom() - newHeight; status = ct.go(true); } catch (DocumentException e) { throw new ExceptionConverter(e); boolean thisEmpty = (ct.getYLine() == y); if (thisEmpty) { newCell.setColumn(ColumnText.duplicate(cell.getColumn())); ct.setFilledWidth(0); } else if ((status & ColumnText.NO_MORE_TEXT) == 0) { newCell.setColumn(ct); ct.setFilledWidth(0); } else { newCell.setPhrase(null);
// read the file PdfReader fondo = new PdfReader("listaPrecios.pdf"); PdfStamper stamper = new PdfStamper( fondo, response.getOutputStream()); PdfContentByte content = stamper.getOverContent(1); // add text ColumnText ct = new ColumnText( content ); // this are the coordinates where you want to add text // if the text does not fit inside it will be cropped ct.setSimpleColumn(50,500,500,50); ct.setText(new Phrase(str, titulo1)); ct.go();