Java Code Examples for com.lowagie.text.pdf.ColumnText#go()
The following examples show how to use
com.lowagie.text.pdf.ColumnText#go() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JRPdfExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
protected void writePageAnchor(int pageIndex) throws DocumentException { Map<Attribute,Object> attributes = new HashMap<Attribute,Object>(); fontUtil.getAttributesWithoutAwtFont(attributes, new JRBasePrintText(jasperPrint.getDefaultStyleProvider())); Font pdfFont = getFont(attributes, getLocale(), false); Chunk 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, pageFormat.getPageHeight(), 1, 1, 0, Element.ALIGN_LEFT ); colText.go(); tagHelper.endPageAnchor(); }
Example 2
Source File: PdfLogicalPageDrawable.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
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 ); } }
Example 3
Source File: ColumnSimpleTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Demonstrating the use of ColumnText */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("columnsimple.pdf")); // step 3: we open the document document.open(); // step 4: // we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Font font = new Font(bf, 11, Font.NORMAL); ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER); ct.addText(new Phrase(15, "UNI\n", font)); for (int i = 0; i < 27; i++) { ct.addText(new Phrase(15, uni[i] + "\n", font)); } ct.go(); cb.rectangle(103, 295, 52, 8 + 28 * 15); cb.stroke(); ct.setSimpleColumn(105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT); ct.addText(new Phrase(15, "char\n", font)); for (int i = 0; i < 27; i++) { ct.addText(new Phrase(15, code[i] + "\n", font)); } ct.go(); ct.setSimpleColumn(160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT); ct.addText(new Phrase(15, "NAME" + "\n", font)); for (int i = 0; i < 27; i++) { ct.addText(new Phrase(15, name[i] + "\n", font)); } ct.go(); // step 5: we close the document document.close(); }
Example 4
Source File: ColumnIrregularTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Demonstrates the use of ColumnText. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("columnirregular.pdf")); // step 3: we open the document document.open(); // step 4: // we grab the contentbyte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); PdfTemplate t = cb.createTemplate(600, 800); Image caesar = Image.getInstance(PdfTestBase.RESOURCES_DIR + "caesar_coin.jpg"); cb.addImage(caesar, 100, 0, 0, 100, 260, 595); t.setGrayFill(0.75f); t.moveTo(310, 112); t.lineTo(280, 60); t.lineTo(340, 60); t.closePath(); t.moveTo(310, 790); t.lineTo(310, 710); t.moveTo(310, 580); t.lineTo(310, 122); t.stroke(); cb.addTemplate(t, 0, 0); ColumnText ct = new ColumnText(cb); ct.addText(new Phrase( "GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\n", FontFactory.getFont(FontFactory.HELVETICA, 12))); ct.addText(new Phrase( "[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]\n", FontFactory.getFont(FontFactory.HELVETICA, 12))); ct.addText(new Phrase( "Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix. Is M. Messala, [et P.] M. Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent: perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri. Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur: una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit. His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur. Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.\n", FontFactory.getFont(FontFactory.HELVETICA, 12))); ct.addText(new Phrase( "His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare. Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant. Ad eas res conficiendas Orgetorix deligitur. Is sibi legationem ad civitates suscipit. In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat. Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset: non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat. Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.\n", FontFactory.getFont(FontFactory.HELVETICA, 12))); ct.addText(new Phrase( "Ea res est Helvetiis per indicium enuntiata. Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur. Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit. Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", FontFactory.getFont(FontFactory.HELVETICA, 12))); float[] left1 = { 70, 790, 70, 60 }; float[] right1 = { 300, 790, 300, 700, 240, 700, 240, 590, 300, 590, 300, 106, 270, 60 }; float[] left2 = { 320, 790, 320, 700, 380, 700, 380, 590, 320, 590, 320, 106, 350, 60 }; float[] right2 = { 550, 790, 550, 60 }; int status = 0; int column = 0; while ((status & ColumnText.NO_MORE_TEXT) == 0) { if (column == 0) { ct.setColumns(left1, right1); column = 1; } else { ct.setColumns(left2, right2); column = 0; } status = ct.go(); ct.setYLine(790); ct.setAlignment(Element.ALIGN_JUSTIFIED); status = ct.go(); if ((column == 0) && ((status & ColumnText.NO_MORE_COLUMN) != 0)) { document.newPage(); cb.addTemplate(t, 0, 0); cb.addImage(caesar, 100, 0, 0, 100, 260, 595); } } // step 5: we close the document document.close(); }
Example 5
Source File: ColumnTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Demonstrating the use of ColumnText */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("column.pdf")); // step 3: we open the document document.open(); // step 4: // we create some content BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Font font = new Font(bf, 11, Font.NORMAL); Phrase unicodes = new Phrase(15, "UNI\n", font); Phrase characters = new Phrase(15, "\n", font); Phrase names = new Phrase(15, "NAME\n", font); for (int i = 0; i < 27; i++) { unicodes.add(uni[i] + "\n"); characters.add(code[i] + "\n"); names.add(name[i] + "\n"); } // we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(unicodes, 60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER); ct.go(); cb.rectangle(103, 295, 52, 8 + 28 * 15); cb.stroke(); ct.setSimpleColumn(characters, 105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT); ct.go(); ct.setSimpleColumn(names, 160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT); ct.go(); // step 5: we close the document document.close(); }
Example 6
Source File: JRPdfExporter.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * */ public void exportImage(JRPrintImage printImage) throws DocumentException, IOException, JRException { if (printImage.getModeValue() == ModeEnum.OPAQUE) { setFillColor(printImage.getBackcolor()); pdfContentByte.rectangle( printImage.getX() + getOffsetX(), pageFormat.getPageHeight() - printImage.getY() - getOffsetY(), printImage.getWidth(), - printImage.getHeight() ); pdfContentByte.fill(); resetFillColor(); } InternalImageProcessor imageProcessor = new InternalImageProcessor(printImage); Renderable renderer = printImage.getRenderer(); if ( renderer != null && imageProcessor.availableImageWidth > 0 && imageProcessor.availableImageHeight > 0 ) { InternalImageProcessorResult imageProcessorResult = null; try { imageProcessorResult = imageProcessor.process(renderer); } catch (Exception e) { Renderable onErrorRenderer = getRendererUtil().handleImageError(e, printImage.getOnErrorTypeValue()); if (onErrorRenderer != null) { imageProcessorResult = imageProcessor.process(onErrorRenderer); } } if (imageProcessorResult != null) { setAnchor(imageProcessorResult.chunk, printImage, printImage); setHyperlinkInfo(imageProcessorResult.chunk, printImage); tagHelper.startImage(printImage); ColumnText colText = new ColumnText(pdfContentByte); int upperY = pageFormat.getPageHeight() - printImage.getY() - imageProcessor.topPadding - getOffsetY() - imageProcessorResult.yoffset; int lowerX = printImage.getX() + imageProcessor.leftPadding + getOffsetX() + imageProcessorResult.xoffset; colText.setSimpleColumn( new Phrase(imageProcessorResult.chunk), lowerX, upperY, lowerX + imageProcessorResult.scaledWidth, upperY - imageProcessorResult.scaledHeight, 0, Element.ALIGN_LEFT ); colText.go(); tagHelper.endImage(); } } if ( printImage.getLineBox().getTopPen().getLineWidth() <= 0f && printImage.getLineBox().getLeftPen().getLineWidth() <= 0f && printImage.getLineBox().getBottomPen().getLineWidth() <= 0f && printImage.getLineBox().getRightPen().getLineWidth() <= 0f ) { if (printImage.getLinePen().getLineWidth() > 0f) { exportPen(printImage.getLinePen(), printImage); } } else { /* */ exportBox( printImage.getLineBox(), printImage ); } }
Example 7
Source File: PdfTextRenderer.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void draw() { TabSegment segment = segments.get(segmentIndex); float advance = segment.layout.getVisibleAdvance();//getAdvance(); ColumnText colText = new ColumnText(pdfContentByte); colText.setSimpleColumn( pdfExporter.getPhrase(segment.as, segment.text, text), x + drawPosX + leftOffsetFactor * advance,// + leftPadding pdfExporter.getCurrentPageFormat().getPageHeight() - y - topPadding - verticalAlignOffset //- text.getLeadingOffset() + lineHeight - drawPosY, x + drawPosX + advance + rightOffsetFactor * advance,// + leftPadding pdfExporter.getCurrentPageFormat().getPageHeight() - y - topPadding - verticalAlignOffset //- text.getLeadingOffset() -400//+ lineHeight//FIXMETAB - drawPosY, 0,//text.getLineSpacingFactor(),// * text.getFont().getSize(), horizontalAlignment == Element.ALIGN_JUSTIFIED && (!segment.isLastLine || (isLastParagraph && justifyLastLine)) ? Element.ALIGN_JUSTIFIED_ALL : horizontalAlignment ); //colText.setLeading(0, text.getLineSpacingFactor());// * text.getFont().getSize()); colText.setLeading(lineHeight); colText.setRunDirection( text.getRunDirectionValue() == RunDirectionEnum.LTR ? PdfWriter.RUN_DIRECTION_LTR : PdfWriter.RUN_DIRECTION_RTL ); try { colText.go(); } catch (DocumentException e) { throw new JRRuntimeException(e); } }