/** * Gets a PdfReader associated with the document object belongs to. * * @return PdfReader. */ protected PdfReader getReader() { if (getDocument() != null) return getDocument().getReader(); return null; }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an InputStream covering the revision. Returns null if it's not a signature field * @throws IOException */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = document.getReader().getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an InputStream covering the revision. Returns null if it's not a signature field * @throws IOException */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = document.getReader().getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
if (sorter.size() > 0) { try { if (((int[]) sorter.get(sorter.size() - 1)[1])[0] == document.getReader().getFileLength()) totalRevisions = sorter.size(); else
if (sorter.size() > 0) { try { if (((int[]) sorter.get(sorter.size() - 1)[1])[0] == document.getReader().getFileLength()) totalRevisions = sorter.size(); else
/** * Checks if the signature covers the entire document (except for signature's Contents) or just a part of it. * * @param name the signature field name * @return true if the signature covers the entire document, false if it doesn't */ public boolean signatureCoversWholeDocument(String name) { getSignatureNames(); if (!sigNames.containsKey(name)) return false; try { ContentsChecker signatureReader = new ContentsChecker(document.getReader().getSafeFile().createSourceView()); return signatureReader.checkWhetherSignatureCoversWholeDocument(acroForm.getField(name)); } catch (IOException e) { throw new PdfException(e); } }
/** * Checks if the signature covers the entire document (except for signature's Contents) or just a part of it. * * @param name the signature field name * @return true if the signature covers the entire document, false if it doesn't */ public boolean signatureCoversWholeDocument(String name) { getSignatureNames(); if (!sigNames.containsKey(name)) return false; try { ContentsChecker signatureReader = new ContentsChecker(document.getReader().getSafeFile().createSourceView()); return signatureReader.checkWhetherSignatureCoversWholeDocument(acroForm.getField(name)); } catch (IOException e) { throw new PdfException(e); } }
private void updateByteRange(PdfPKCS7 pkcs7, PdfSignature signature) { PdfArray b = signature.getByteRange(); RandomAccessFileOrArray rf = document.getReader().getSafeFile(); InputStream rg = null; try { rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(rf.createSourceView(), b.toLongArray())); byte[] buf = new byte[8192]; int rd; while ((rd = rg.read(buf, 0, buf.length)) > 0) { pkcs7.update(buf, 0, rd); } } catch (Exception e) { throw new PdfException(e); } finally { try { if (rg != null) rg.close(); } catch (IOException e) { // this really shouldn't ever happen - the source view we use is based on a Safe view, which is a no-op anyway throw new PdfException(e); } } }
private void updateByteRange(PdfPKCS7 pkcs7, PdfSignature signature) { PdfArray b = signature.getByteRange(); RandomAccessFileOrArray rf = document.getReader().getSafeFile(); InputStream rg = null; try { rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(rf.createSourceView(), b.toLongArray())); byte[] buf = new byte[8192]; int rd; while ((rd = rg.read(buf, 0, buf.length)) > 0) { pkcs7.update(buf, 0, rd); } } catch (Exception e) { throw new PdfException(e); } finally { try { if (rg != null) rg.close(); } catch (IOException e) { // this really shouldn't ever happen - the source view we use is based on a Safe view, which is a no-op anyway throw new PdfException(e); } } }
/** * Convenience method for fast PdfCanvas creation by a certain page. * * @param page page to create canvas from. */ public PdfCanvas(PdfPage page) { this(page, (page.getDocument().getReader() != null && page.getDocument().getWriter() != null && page.getContentStreamCount() > 0 && page.getLastContentStream().getLength() > 0) || (page.getRotation() != 0 && page.isIgnorePageRotationForContent())); }
protected void flushSingleRenderer(IRenderer resultRenderer) { Transform transformProp = resultRenderer.<Transform>getProperty(Property.TRANSFORM); if (!waitingDrawingElements.contains(resultRenderer)) { processWaitingDrawing(resultRenderer, transformProp, waitingDrawingElements); if (FloatingHelper.isRendererFloating(resultRenderer) || transformProp != null) return; } if (!resultRenderer.isFlushed() && null != resultRenderer.getOccupiedArea()) { // TODO Remove checking occupied area to be not null when DEVSIX-1001 is resolved. int pageNum = resultRenderer.getOccupiedArea().getPageNumber(); PdfDocument pdfDocument = document.getPdfDocument(); ensureDocumentHasNPages(pageNum, null); PdfPage correspondingPage = pdfDocument.getPage(pageNum); if (correspondingPage.isFlushed()) { throw new PdfException(PdfException.CannotDrawElementsOnAlreadyFlushedPages); } boolean wrapOldContent = pdfDocument.getReader() != null && pdfDocument.getWriter() != null && correspondingPage.getContentStreamCount() > 0 && correspondingPage.getLastContentStream().getLength() > 0 && !wrappedContentPage.contains(pageNum) && pdfDocument.getNumberOfPages() >= pageNum; wrappedContentPage.add(pageNum); if (pdfDocument.isTagged()) { pdfDocument.getTagStructureContext().getAutoTaggingPointer().setPageForTagging(correspondingPage); } resultRenderer.draw(new DrawContext(pdfDocument, new PdfCanvas(correspondingPage, wrapOldContent), pdfDocument.isTagged())); } }
protected void flushSingleRenderer(IRenderer resultRenderer) { Transform transformProp = resultRenderer.<Transform>getProperty(Property.TRANSFORM); if (!waitingDrawingElements.contains(resultRenderer)) { processWaitingDrawing(resultRenderer, transformProp, waitingDrawingElements); if (FloatingHelper.isRendererFloating(resultRenderer) || transformProp != null) return; } if (!resultRenderer.isFlushed() && null != resultRenderer.getOccupiedArea()) { // TODO Remove checking occupied area to be not null when DEVSIX-1001 is resolved. int pageNum = resultRenderer.getOccupiedArea().getPageNumber(); PdfDocument pdfDocument = document.getPdfDocument(); ensureDocumentHasNPages(pageNum, null); PdfPage correspondingPage = pdfDocument.getPage(pageNum); if (correspondingPage.isFlushed()) { throw new PdfException(PdfException.CannotDrawElementsOnAlreadyFlushedPages); } boolean wrapOldContent = pdfDocument.getReader() != null && pdfDocument.getWriter() != null && correspondingPage.getContentStreamCount() > 0 && correspondingPage.getLastContentStream().getLength() > 0 && !wrappedContentPage.contains(pageNum) && pdfDocument.getNumberOfPages() >= pageNum; wrappedContentPage.add(pageNum); if (pdfDocument.isTagged()) { pdfDocument.getTagStructureContext().getAutoTaggingPointer().setPageForTagging(correspondingPage); } resultRenderer.draw(new DrawContext(pdfDocument, new PdfCanvas(correspondingPage, wrapOldContent), pdfDocument.isTagged())); } }
IRandomAccessSource readerSource = document.getReader().getSafeFile().createSourceView(); InputStream rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(readerSource, gaps)); byte[] signedContent = externalSignatureContainer.sign(rg);
IRandomAccessSource readerSource = document.getReader().getSafeFile().createSourceView(); InputStream rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(readerSource, gaps)); byte[] signedContent = externalSignatureContainer.sign(rg);