/** * Calculates the appropriate y position for the bottom of the columns on this page. * * @return the y position of the bottom of the columns */ private float getColumnBottom() { if (desiredHeight == AUTOMATIC) { return document.bottom(); } else { return Math.max(top - (desiredHeight - totalHeight), document.bottom()); } }
@Override public void transform(ArchivalUnit au, PdfDocument pdfDocument) throws PdfException { pdfDocument.unsetModificationDate(); PdfUtil.normalizeTrailerId(pdfDocument); pdfDocument.unsetMetadata(); PDDocumentInformation pdDocInfo = ((GtvPdfBoxDocument) pdfDocument).getPdDocumentInformation(); if (pdDocInfo.getCustomMetadataValue(GtvPdfBoxDocument.PDFDATE) != null) { pdDocInfo.setCustomMetadataValue(GtvPdfBoxDocument.PDFDATE, null); } if (pdDocInfo.getCustomMetadataValue(GtvPdfBoxDocument.PDFUSER) != null) { pdDocInfo.setCustomMetadataValue(GtvPdfBoxDocument.PDFUSER, null); } PdfStateMachineWorker worker = new PdfStateMachineWorker(); boolean anyXform = false; for (PdfPage pdfPage : pdfDocument.getPages()) { PdfTokenStream pdfTokenStream = pdfPage.getPageTokenStream(); worker.process(pdfTokenStream); if (worker.getResult()) { anyXform = true; List<PdfToken> tokens = pdfTokenStream.getTokens(); // clear tokens including text markers tokens.subList(worker.getBegin(), worker.getEnd() + 1).clear(); pdfTokenStream.setTokens(tokens); } } if (log.isDebug2()) { log.debug2("Transform: " + anyXform); } }
/** read the meta-parameter value from an input stream */ @Override public void readValue(InputStream is, String mimeType) throws IOException { try { PdfDocument pdf = new PdfDocument(); pdf.readDocument(is); setValue(pdf); } catch (MetaParameterFormatException ex) { // never happens ex.printStackTrace(); } }
private void newPage() throws DocumentException { resetCurrentColumn(); if (desiredHeight == AUTOMATIC) { top = nextY = AUTOMATIC; } else { top = nextY; } totalHeight = 0; if (document != null) { document.newPage(); } }
/** * Write out the columns. After writing, use {@link #isOverflow()} to see if all text was written. * * @param canvas PdfContentByte to write with * @param document document to write to (only used to get page limit info) * @param documentY starting y position to begin writing at * @return the current height (y position) after writing the columns * @throws DocumentException on error */ public float write(PdfContentByte canvas, PdfDocument document, float documentY) throws DocumentException { this.document = document; columnText.setCanvas(canvas); if (columnDefs.isEmpty()) { throw new DocumentException("MultiColumnText has no columns"); } overflow = false; float currentHeight = 0; boolean done = false; try { while (!done) { if (top == AUTOMATIC) { top = document.getVerticalPosition( true); // RS - 07/07/2005 - Get current doc writing position for top of columns on // new page. } else if (nextY == AUTOMATIC) { nextY = document.getVerticalPosition( true); // RS - 07/07/2005 - - Get current doc writing position for top of columns // on new page. } ColumnDef currentDef = (ColumnDef) columnDefs.get(getCurrentColumn()); columnText.setYLine(top); float[] left = currentDef.resolvePositions(Rectangle.LEFT); float[] right = currentDef.resolvePositions(Rectangle.RIGHT); if (document.isMarginMirroring() && document.getPageNumber() % 2 == 0) { float delta = document.rightMargin() - document.left(); left = (float[]) left.clone(); right = (float[]) right.clone(); for (int i = 0; i < left.length; i += 2) { left[i] -= delta; } for (int i = 0; i < right.length; i += 2) { right[i] -= delta; } } currentHeight = Math.max(currentHeight, getHeight(left, right)); if (currentDef.isSimple()) { 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; } else { // check if we are done because of height totalHeight += currentHeight; if ((desiredHeight != AUTOMATIC) && (totalHeight >= desiredHeight)) { overflow = true; break; } else { // need to start new page and reset the columns documentY = nextY; newPage(); currentHeight = 0; } } } } catch (DocumentException ex) { ex.printStackTrace(); throw ex; } if (desiredHeight == AUTOMATIC && columnDefs.size() == 1) { currentHeight = documentY - columnText.getYLine(); } return currentHeight; }
public CodecDocument openDocument(String fileName) { return PdfDocument.openDocument(fileName, ""); }
/* Inherit documentation */ protected ListIterator /* of PdfPage */ getSelectedPages(PdfDocument pdfDocument) throws IOException { return pdfDocument.getPageIterator(); }
/** write the document to an output stream */ @Override public void writeValue(OutputStream os) throws IOException { PdfDocument pdf = (PdfDocument) getValue(); pdf.writeDocument(os); }