List of usage examples for org.apache.pdfbox.pdmodel PDPageContentStream PDPageContentStream
public PDPageContentStream(PDDocument document, PDPage sourcePage, AppendMode appendContent, boolean compress) throws IOException
From source file:gov.samhsa.c2s.common.pdfbox.enhance.HexPdf.java
License:Apache License
private void drawFooters() { if (footer != null) { ignorePagebleed = true; // Now new pages while writing footers! int pg;//from w ww . j ava 2 s .c o m int pagecounter = 0; int total = (footer.isCOUNT_FIRSTPAGE()) ? numPages : numPages - 1; PDPageTree pages = this.getDocumentCatalog().getPages(); for (PDPage page : pages) { pagecounter++; try { cs = new PDPageContentStream(this, page, true, true); setTextColor(footer.getTextColor()); setFont(footer.getFont()); setFontSize(footer.getFontsize()); if (pagecounter > 1 || false == footer.isOMIT_FIRSTPAGE()) { pg = (footer.isCOUNT_FIRSTPAGE()) ? pagecounter : pagecounter - 1; //noinspection Since15 if (footer.getLeftText() != null && !footer.getLeftText().isEmpty()) { String left = replaceBookmarks(footer.getLeftText(), pg, total); setCursor(contentStartX, contentEndY - lineSep); drawText(left, HexPdf.LEFT); } //noinspection Since15 if (footer.getRightText() != null && !footer.getRightText().isEmpty()) { String right = replaceBookmarks(footer.getRightText(), pg, total); setCursor(contentStartX, contentEndY - lineSep); drawText(right, HexPdf.RIGHT); } //noinspection Since15 if (footer.getCenterText() != null && !footer.getCenterText().isEmpty()) { String right = replaceBookmarks(footer.getCenterText(), pg, total); setCursor(contentStartX, contentEndY - lineSep); drawText(right, HexPdf.CENTER); } } cs.close(); } catch (IOException ex) { Logger.getLogger(HexPdf.class.getName()).log(Level.SEVERE, null, ex); } } ignorePagebleed = false; } }
From source file:GUI.Helper.PDFIOHelper.java
private static void drawReportHeaderFooter(PDDocument report, Project proj, boolean headerOnFirstPage) { int pageIdx = headerOnFirstPage ? 0 : 1; int marginOffset = 10; try {//from w w w . ja va2 s .c om PDPageContentStream cs; for (int p = pageIdx; p < report.getNumberOfPages(); p++) { cs = new PDPageContentStream(report, report.getPage(p), true, false); cs.setFont(PDType1Font.TIMES_ROMAN, 11); cs.setNonStrokingColor(Color.BLACK); cs.beginText(); String dateString = DateFormat.getDateInstance(DateFormat.MEDIUM) .format(Calendar.getInstance().getTime()); cs.setTextMatrix(new Matrix(1, 0, 0, 1, MARGIN_LEFT_X, MARGIN_TOP_Y + marginOffset)); cs.showText(dateString); String projectString = "WZ ITS Tool Report: " + proj.getName(); cs.setTextMatrix(new Matrix(1, 0, 0, 1, MARGIN_RIGHT_X - (PDType1Font.TIMES_ROMAN.getStringWidth(projectString) / 1000 * 11), MARGIN_TOP_Y + marginOffset)); cs.showText(projectString); String pageNumString = "Page " + String.valueOf(p + 1) + " of " + String.valueOf(report.getNumberOfPages()); cs.setTextMatrix(new Matrix(1, 0, 0, 1, MARGIN_LEFT_X + (MARGIN_RIGHT_X - MARGIN_LEFT_X) / 2.0f - (PDType1Font.TIMES_ROMAN.getStringWidth(pageNumString) / 1000 * 11) / 2.0f, MARGIN_BOTTOM_Y - marginOffset)); cs.showText(pageNumString); cs.setTextMatrix(new Matrix(1, 0, 0, 1, MARGIN_LEFT_X + 20, MARGIN_BOTTOM_Y - marginOffset)); cs.showText("WZ ITS Tool V" + WZITS_FX.VERSION); String analystAgencyStr = (proj.getAnalyst() != null ? proj.getAnalyst() : "") + (proj.getAnalyst() != null && proj.getAgency() != null ? " / " : "") + (proj.getAgency() != null ? proj.getAgency() : ""); cs.setTextMatrix(new Matrix(1, 0, 0, 1, MARGIN_RIGHT_X - (PDType1Font.TIMES_ROMAN.getStringWidth(analystAgencyStr) / 1000 * 11), MARGIN_BOTTOM_Y - marginOffset)); cs.showText(analystAgencyStr); cs.endText(); BufferedImage logoWZITS = ImageIO.read(WZITS_FX.class.getResource("/GUI/Icon/wzits_icon_64.png")); //ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); //op.filter(logoWZITS, logoWZITS); cs.drawImage(LosslessFactory.createFromImage(report, logoWZITS), MARGIN_LEFT_X, MARGIN_BOTTOM_Y - marginOffset - 3, 16, 16); cs.close(); } } catch (IOException e) { System.out.println("Something went wrong"); } }
From source file:helper.pdfpreprocessing.pdf.TextHighlight.java
License:Apache License
public void highlight(final Pattern searchText, final Pattern markingPattern, Color color, int pageNr, boolean withId, String comment) { if (textCache == null || document == null) { throw new IllegalArgumentException("TextCache was not initialized"); }//from ww w. j a v a 2 s . c o m try { boolean found = false; final PDPage page = document.getPages().get(pageNr - 1); PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true); PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState(); graphicsState.setNonStrokingAlphaConstant(0.5f); contentStream.setGraphicsStateParameters(graphicsState); for (Match searchMatch : textCache.match(pageNr, searchText)) { if (textCache.match(searchMatch.positions, markingPattern).size() > 0) { for (Match markingMatch : textCache.match(searchMatch.positions, markingPattern)) { if (markupMatch(color, contentStream, markingMatch, 10, withId, page, comment, false)) { found = true; } } } else { System.out .println("Cannot highlight: " + markingPattern.pattern() + " on page " + (pageNr - 1)); } if (found) { break; } } contentStream.close(); } catch (Exception e) { e.printStackTrace(); } catch (Error e1) { e1.printStackTrace(); throw e1; } }
From source file:helper.pdfpreprocessing.pdf.TextHighlight.java
License:Apache License
public void highlight(int startIndex, int stopIndex, Color color, int pageNr, int boxHeight, boolean hasLineOffset, boolean withId, String comment, boolean commentOnly) { if (textCache == null || document == null) { throw new IllegalArgumentException("TextCache was not initialized"); }/* w w w. ja v a 2 s.c o m*/ try { final PDPage page = document.getPages().get(pageNr - 1); PDPageContentStream contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true); PDExtendedGraphicsState graphicsState = new PDExtendedGraphicsState(); graphicsState.setNonStrokingAlphaConstant(0.5f); contentStream.setGraphicsStateParameters(graphicsState); List<TextPosition> pos = textCache.getTextPositions(pageNr); int numberOfLines = 0; if (hasLineOffset) { numberOfLines = textCache.getText(pageNr).substring(0, stopIndex).split("\\n").length - 1; } pos = pos.subList(Math.min(numberOfLines + startIndex, pos.size()), Math.min(numberOfLines + stopIndex, pos.size())); Match m = new Match(pageNr + "-" + startIndex, pos); markupMatch(color, contentStream, m, boxHeight, withId, page, comment, commentOnly); contentStream.close(); } catch (Exception e) { e.printStackTrace(); } catch (Error e1) { e1.printStackTrace(); throw e1; } }
From source file:jgnash.report.pdf.Report.java
License:Open Source License
public void addTable(final AbstractReportTableModel reportModel, final String title) throws IOException { boolean titleWritten = false; final float[] columnWidths = getColumnWidths(reportModel); final Set<GroupInfo> groupInfoSet = getGroups(reportModel); // calculate the maximum imageable height of the page before we get too close to the footer float imageableBottom = (float) getPageFormat().getHeight() - getBottomMargin() - getTableRowHeight(); float docY = getTopMargin(); // start at top of the page with the margin PDPage page = createPage(); // create the first page for (final GroupInfo groupInfo : groupInfoSet) { int row = 0; // tracks the last written row while (row < reportModel.getRowCount()) { if (docY > imageableBottom || isForceGroupPagination()) { // if near the bottom of the page docY = getTopMargin(); // start at top of the page with the margin page = createPage();/*from w w w. ja v a 2 s . c o m*/ } try (final PDPageContentStream contentStream = new PDPageContentStream(pdfDocument, page, PDPageContentStream.AppendMode.APPEND, false)) { // add the table title if its not been added if (title != null && !title.isEmpty() && row == 0 && !titleWritten) { docY = addReportTitle(contentStream, title, getSubTitle(), docY); titleWritten = true; } // add the group subtitle if needed if (groupInfoSet.size() > 1) { docY = addTableTitle(contentStream, groupInfo.group, docY); } // write a section of the table and save the last row written for next page if needed final Pair<Integer, Float> pair = addTableSection(reportModel, groupInfo.group, contentStream, row, columnWidths, docY); row = pair.getLeft(); docY = pair.getRight(); } catch (final IOException e) { logSevere(Report.class, e); throw (e); } // check to see if this table has summation information and add a summation footer if (groupInfo.hasSummation() && row == reportModel.getRowCount()) { // TODO, make sure the end of the page has not been reached try (final PDPageContentStream contentStream = new PDPageContentStream(pdfDocument, page, PDPageContentStream.AppendMode.APPEND, false)) { docY = addTableFooter(reportModel, groupInfo, contentStream, columnWidths, docY); docY += getBaseFontSize(); // add some padding } catch (final IOException e) { logSevere(Report.class, e); throw (e); } } } } if (reportModel.hasGlobalSummary()) { try (final PDPageContentStream contentStream = new PDPageContentStream(pdfDocument, page, PDPageContentStream.AppendMode.APPEND, false)) { addGlobalFooter(reportModel, contentStream, columnWidths, docY); } catch (final IOException e) { logSevere(Report.class, e); throw (e); } } }
From source file:jgnash.report.pdf.Report.java
License:Open Source License
public void addFooter() throws IOException { final String timeStamp = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT) .format(LocalDateTime.now()); final int pageCount = pdfDocument.getNumberOfPages(); float yStart = getBottomMargin() * 2 / 3; for (int i = 0; i < pageCount; i++) { final PDPage page = pdfDocument.getPage(i); final String pageText = MessageFormat.format(rb.getString("Pattern.Pages"), i + 1, pageCount); final float width = getStringWidth(pageText, getFooterFont(), getFooterFontSize()); try (final PDPageContentStream contentStream = new PDPageContentStream(pdfDocument, page, PDPageContentStream.AppendMode.APPEND, true)) { contentStream.setFont(getFooterFont(), getFooterFontSize()); drawText(contentStream, getLeftMargin(), yStart, timeStamp); drawText(contentStream, (float) getPageFormat().getWidth() - getRightMargin() - width, yStart, pageText);//from www . ja va 2 s . c o m } catch (final IOException e) { logSevere(Report.class, e); } } }
From source file:model.objects.Project.java
License:Apache License
/** * //w w w.ja va2 s.c om * @param _doc * @param _bi * @param _pageindex index of page to which the BufferedImage is * inserted. * If it is equal to -1, new page is created. * */ public void attatchToPDF(final PDDocument _doc, final BufferedImage _bi, final int _pageindex) { PDPage page = null; try { if (_pageindex == -1) { page = new PDPage(new PDRectangle(State.getImageSize().width, State.getImageSize().height)); _doc.addPage(page); } else { page = _doc.getPage(_pageindex); // page.setCropBox(new PDRectangle(State.getImageSize().width , // State.getImageSize().height )); } int width = (int) page.getCropBox().getWidth(); int height = (int) page.getCropBox().getHeight(); PDImageXObject ximage = LosslessFactory.createFromImage(_doc, // _bi); Utils.resizeImage(width, height, _bi)); PDPageContentStream content = new PDPageContentStream(_doc, page, true, true); // contentStream.drawImage(ximage, 20, 20 ); // better method inspired by http://stackoverflow.com/a/22318681/535646 // reduce this value if the image is too large float scale = 1f; content.drawImage(ximage, 20, 20, ximage.getWidth() * scale, ximage.getHeight() * scale); content.close(); // LosslessFactory.createFromImage(doc, bim) // content.drawImage(ximage, 0, 0); // content.close(); } catch (IOException ie) { //handle exception } }
From source file:model.util.pdf.PDFUtils.java
License:Apache License
/** * Test: Create pdf from image and pdf file. * * @param _inputFile pdf input/*from www . j a va 2 s . co m*/ * @param _imagePath image input * @param _outputFile pdf output * * @throws IOException occurs if reading the data fails. */ public void saveAsPdf(String _imagePath, String _outputFile) throws IOException { PDDocument doc = null; try { // create new document and insert empty page to the document. doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); // createFromFile is the easiest way with an image file // if you already have the image in a BufferedImage, // call LosslessFactory.createFromImage() instead PDImageXObject pdImage = PDImageXObject.createFromFile(_imagePath, doc); PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true); // contentStream.drawImage(ximage, 20, 20 ); // better method inspired by http://stackoverflow.com/a/22318681/535646 // reduce this value if the image is too large float scale = 1f; contentStream.drawImage(pdImage, 20, 20, pdImage.getWidth() * scale, pdImage.getHeight() * scale); contentStream.close(); doc.save(_outputFile); } finally { if (doc != null) { doc.close(); } } }
From source file:org.apache.openmeetings.web.room.wb.WbPanel.java
License:Apache License
@Override protected void processWbAction(WbAction a, JSONObject obj, AjaxRequestTarget target) throws IOException { Client c = rp.getClient();//from ww w .java 2s .c o m if (c == null) { return; } switch (a) { case createObj: case modifyObj: { JSONObject o = obj.optJSONObject("obj"); if (o != null && "pointer".equals(o.getString(ATTR_TYPE))) { sendWbOthers(a, obj); return; } } break; case downloadPdf: { boolean moder = c.hasRight(Room.Right.moderator); Room r = rp.getRoom(); if ((moder && !r.isHidden(RoomElement.ActionMenu)) || (!moder && r.isAllowUserQuestions())) { try (PDDocument doc = new PDDocument()) { JSONArray arr = obj.getJSONArray("slides"); for (int i = 0; i < arr.length(); ++i) { String base64Image = arr.getString(i).split(",")[1]; byte[] bb = Base64.decodeBase64(base64Image); BufferedImage img = ImageIO.read(new ByteArrayInputStream(bb)); float width = img.getWidth(); float height = img.getHeight(); PDPage page = new PDPage(new PDRectangle(width, height)); PDImageXObject pdImageXObject = LosslessFactory.createFromImage(doc, img); try (PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.APPEND, false)) { contentStream.drawImage(pdImageXObject, 0, 0, width, height); } doc.addPage(page); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); doc.save(baos); rp.startDownload(target, baos.toByteArray()); } } return; } case loadVideos: { StringBuilder sb = new StringBuilder("WbArea.initVideos("); JSONArray arr = new JSONArray(); for (Entry<Long, Whiteboard> entry : wbm.list(roomId)) { Whiteboard wb = entry.getValue(); for (JSONObject o : wb.list()) { String ft = o.optString(ATTR_FILE_TYPE); if (BaseFileItem.Type.Recording.name().equals(ft) || BaseFileItem.Type.Video.name().equals(ft)) { JSONObject _sts = o.optJSONObject(PARAM_STATUS); if (_sts == null) { continue; } JSONObject sts = new JSONObject(_sts.toString()); //copy sts.put("pos", sts.getDouble("pos") + (System.currentTimeMillis() - sts.getLong(PARAM_UPDATED)) * 1. / 1000); arr.put(new JSONObject().put("wbId", wb.getId()).put("uid", o.getString("uid")) .put(ATTR_SLIDE, o.getString(ATTR_SLIDE)).put(PARAM_STATUS, sts)); } } } sb.append(arr.toString()).append(");"); target.appendJavaScript(sb); return; } default: break; } //presenter-right if (c.hasRight(Right.presenter)) { switch (a) { case createWb: { Whiteboard wb = wbm.add(roomId, c.getUser().getLanguageId()); sendWbAll(WbAction.createWb, getAddWbJson(wb)); } break; case removeWb: { long id = obj.optLong("wbId", -1); if (id > -1) { wbm.remove(roomId, id); sendWbAll(WbAction.removeWb, obj); } } break; case activateWb: { long _id = obj.optLong("wbId", -1); if (_id > -1) { wbm.activate(roomId, _id); sendWbAll(WbAction.activateWb, obj); } } break; case renameWb: { Whiteboard wb = wbm.get(roomId).get(obj.optLong("wbId", -1)); if (wb != null) { wbm.update(roomId, wb.setName(obj.getString("name"))); sendWbAll(WbAction.renameWb, obj); } } break; case setSlide: { Whiteboard wb = wbm.get(roomId).get(obj.optLong("wbId", -1)); if (wb != null) { wb.setSlide(obj.optInt(ATTR_SLIDE, 0)); wbm.update(roomId, wb); sendWbOthers(WbAction.setSlide, obj); } } break; case clearAll: { clearAll(roomId, obj.getLong("wbId")); } break; case setSize: { Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId")); wb.setWidth(obj.getInt(ATTR_WIDTH)); wb.setHeight(obj.getInt(ATTR_HEIGHT)); wb.setZoom(obj.getDouble(ATTR_ZOOM)); wb.setZoomMode(ZoomMode.valueOf(obj.getString("zoomMode"))); wbm.update(roomId, wb); sendWbOthers(WbAction.setSize, getAddWbJson(wb)); } break; default: break; } } //wb-right if (c.hasRight(Right.presenter) || c.hasRight(Right.whiteBoard)) { switch (a) { case createObj: { Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId")); JSONObject o = obj.getJSONObject("obj"); wb.put(o.getString("uid"), o); wbm.update(roomId, wb); addUndo(wb.getId(), new UndoObject(UndoObject.Type.add, o)); sendWbOthers(WbAction.createObj, obj); } break; case modifyObj: { Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId")); JSONArray arr = obj.getJSONArray("obj"); JSONArray undo = new JSONArray(); for (int i = 0; i < arr.length(); ++i) { JSONObject _o = arr.getJSONObject(i); String uid = _o.getString("uid"); JSONObject po = wb.get(uid); if (po != null) { undo.put(po); wb.put(uid, _o); } } if (arr.length() != 0) { wbm.update(roomId, wb); addUndo(wb.getId(), new UndoObject(UndoObject.Type.modify, undo)); } sendWbOthers(WbAction.modifyObj, obj); } break; case deleteObj: { Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId")); JSONArray arr = obj.getJSONArray("obj"); JSONArray undo = new JSONArray(); for (int i = 0; i < arr.length(); ++i) { JSONObject _o = arr.getJSONObject(i); JSONObject u = wb.remove(_o.getString("uid")); if (u != null) { undo.put(u); } } if (undo.length() != 0) { wbm.update(roomId, wb); addUndo(wb.getId(), new UndoObject(UndoObject.Type.remove, undo)); } sendWbAll(WbAction.deleteObj, obj); } break; case clearSlide: { Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId")); JSONArray arr = wb.clearSlide(obj.getInt(ATTR_SLIDE)); if (arr.length() != 0) { wbm.update(roomId, wb); addUndo(wb.getId(), new UndoObject(UndoObject.Type.remove, arr)); } sendWbAll(WbAction.clearSlide, obj); } break; case save: wb2save = obj.getLong("wbId"); fileName.open(target); break; case undo: { Long wbId = obj.getLong("wbId"); UndoObject uo = getUndo(wbId); if (uo != null) { Whiteboard wb = wbm.get(roomId).get(wbId); switch (uo.getType()) { case add: { JSONObject o = new JSONObject(uo.getObject()); wb.remove(o.getString("uid")); wbm.update(roomId, wb); sendWbAll(WbAction.deleteObj, obj.put("obj", new JSONArray().put(o))); } break; case remove: { JSONArray arr = new JSONArray(uo.getObject()); for (int i = 0; i < arr.length(); ++i) { JSONObject o = arr.getJSONObject(i); wb.put(o.getString("uid"), o); } wbm.update(roomId, wb); sendWbAll(WbAction.createObj, obj.put("obj", new JSONArray(uo.getObject()))); } break; case modify: { JSONArray arr = new JSONArray(uo.getObject()); for (int i = 0; i < arr.length(); ++i) { JSONObject o = arr.getJSONObject(i); wb.put(o.getString("uid"), o); } wbm.update(roomId, wb); sendWbAll(WbAction.modifyObj, obj.put("obj", arr)); } break; } } } break; case videoStatus: { Whiteboard wb = wbm.get(roomId).get(obj.getLong("wbId")); String uid = obj.getString("uid"); JSONObject po = wb.get(uid); if (po != null && "video".equals(po.getString(ATTR_TYPE))) { JSONObject ns = obj.getJSONObject(PARAM_STATUS); po.put(PARAM_STATUS, ns.put(PARAM_UPDATED, System.currentTimeMillis())); wbm.update(roomId, wb.put(uid, po)); obj.put(ATTR_SLIDE, po.getInt(ATTR_SLIDE)); sendWbAll(WbAction.videoStatus, obj); } } break; default: break; } } }
From source file:org.esteco.jira.pdf.UsingTextMatrix.java
License:Apache License
/** * creates a sample document with some text using a text matrix. * * @param message The message to write in the file. * @param outfile The resulting PDF.// w w w. j a va 2 s . com * @throws IOException If there is an error writing the data. */ public void doIt(String message, String outfile) throws IOException { // the document PDDocument doc = null; try { doc = new PDDocument(); // Page 1 PDFont font = PDType1Font.HELVETICA; PDPage page = new PDPage(PDRectangle.A4); doc.addPage(page); float fontSize = 12.0f; PDRectangle pageSize = page.getMediaBox(); float centeredXPosition = (pageSize.getWidth() - fontSize / 1000f) / 2f; float stringWidth = font.getStringWidth(message); float centeredYPosition = (pageSize.getHeight() - (stringWidth * fontSize) / 1000f) / 3f; PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, false); contentStream.setFont(font, fontSize); contentStream.beginText(); // counterclockwise rotation for (int i = 0; i < 8; i++) { contentStream.setTextMatrix(Matrix.getRotateInstance(i * Math.PI * 0.25, centeredXPosition, pageSize.getHeight() - centeredYPosition)); contentStream.showText(message + " " + i); } // clockwise rotation for (int i = 0; i < 8; i++) { contentStream.setTextMatrix( Matrix.getRotateInstance(-i * Math.PI * 0.25, centeredXPosition, centeredYPosition)); contentStream.showText(message + " " + i); } contentStream.endText(); contentStream.close(); // Page 2 page = new PDPage(PDRectangle.A4); doc.addPage(page); fontSize = 1.0f; contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, false); contentStream.setFont(font, fontSize); contentStream.beginText(); // text scaling and translation for (int i = 0; i < 10; i++) { contentStream.setTextMatrix(new Matrix(12 + (i * 6), 0, 0, 12 + (i * 6), 100, 100 + i * 50)); contentStream.showText(message + " " + i); } contentStream.endText(); contentStream.close(); // Page 3 page = new PDPage(PDRectangle.A4); doc.addPage(page); fontSize = 1.0f; contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, false); contentStream.setFont(font, fontSize); contentStream.beginText(); int i = 0; // text scaling combined with rotation contentStream.setTextMatrix(new Matrix(12, 0, 0, 12, centeredXPosition, centeredYPosition * 1.5f)); contentStream.showText(message + " " + i++); contentStream.setTextMatrix(new Matrix(0, 18, -18, 0, centeredXPosition, centeredYPosition * 1.5f)); contentStream.showText(message + " " + i++); contentStream.setTextMatrix(new Matrix(-24, 0, 0, -24, centeredXPosition, centeredYPosition * 1.5f)); contentStream.showText(message + " " + i++); contentStream.setTextMatrix(new Matrix(0, -30, 30, 0, centeredXPosition, centeredYPosition * 1.5f)); contentStream.showText(message + " " + i++); contentStream.endText(); contentStream.close(); doc.save(outfile); } finally { if (doc != null) { doc.close(); } } }