PdfReaderInstance(PdfReader reader, PdfWriter writer) { this.reader = reader; this.writer = writer; file = reader.getSafeFile(); myXref = new int[reader.getXrefSize()]; }
@Override RandomAccessFileOrArray getReaderFile(PdfReader reader) { if (readers2intrefs.containsKey(reader)) { RandomAccessFileOrArray raf = readers2file.get(reader); if (raf != null) return raf; return reader.getSafeFile(); } if (currentPdfReaderInstance == null) return file; else return currentPdfReaderInstance.getReaderFile(); }
PdfReaderInstance(PdfReader reader, PdfWriter writer) { this.reader = reader; this.writer = writer; file = reader.getSafeFile(); myXref = new int[reader.getXrefSize()]; }
@Override RandomAccessFileOrArray getReaderFile(PdfReader reader) { if (readers2intrefs.containsKey(reader)) { RandomAccessFileOrArray raf = readers2file.get(reader); if (raf != null) return raf; return reader.getSafeFile(); } if (currentPdfReaderInstance == null) return file; else return currentPdfReaderInstance.getReaderFile(); }
/** * @param reader * @param openFile * @throws IOException */ public void registerReader(PdfReader reader, boolean openFile) throws IOException { if (readers2intrefs.containsKey(reader)) return; readers2intrefs.put(reader, new IntHashtable()); if (openFile) { RandomAccessFileOrArray raf = reader.getSafeFile(); readers2file.put(reader, raf); raf.reOpen(); } }
/** * @param reader * @param openFile * @throws IOException */ public void registerReader(PdfReader reader, boolean openFile) throws IOException { if (readers2intrefs.containsKey(reader)) return; readers2intrefs.put(reader, new IntHashtable()); if (openFile) { RandomAccessFileOrArray raf = reader.getSafeFile(); readers2file.put(reader, raf); raf.reOpen(); } }
/** Gets the contents of the page. * @param pageNum the page number. 1 is the first * @throws IOException on error * @return the content */ public byte[] getPageContent(final int pageNum) throws IOException{ RandomAccessFileOrArray rf = getSafeFile(); try { rf.reOpen(); return getPageContent(pageNum, rf); } finally { try{rf.close();}catch(Exception e){} } }
/** Gets the contents of the page. * @param pageNum the page number. 1 is the first * @throws IOException on error * @return the content */ public byte[] getPageContent(final int pageNum) throws IOException{ RandomAccessFileOrArray rf = getSafeFile(); try { rf.reOpen(); return getPageContent(pageNum, rf); } finally { try{rf.close();}catch(Exception e){} } }
/** * Gets the global document JavaScript. * @throws IOException on error * @return the global document JavaScript */ public String getJavaScript() throws IOException { RandomAccessFileOrArray rf = getSafeFile(); try { rf.reOpen(); return getJavaScript(rf); } finally { try{rf.close();}catch(Exception e){} } }
/** * Gets the global document JavaScript. * @throws IOException on error * @return the global document JavaScript */ public String getJavaScript() throws IOException { RandomAccessFileOrArray rf = getSafeFile(); try { rf.reOpen(); return getJavaScript(rf); } finally { try{rf.close();}catch(Exception e){} } }
/** Get the content from a stream applying the required filters. * @param stream the stream * @throws IOException on error * @return the stream content */ public static byte[] getStreamBytes(final PRStream stream) throws IOException { RandomAccessFileOrArray rf = stream.getReader().getSafeFile(); try { rf.reOpen(); return getStreamBytes(stream, rf); } finally { try{rf.close();}catch(Exception e){} } }
/** Get the content from a stream as it is without applying any filter. * @param stream the stream * @throws IOException on error * @return the stream content */ public static byte[] getStreamBytesRaw(final PRStream stream) throws IOException { RandomAccessFileOrArray rf = stream.getReader().getSafeFile(); try { rf.reOpen(); return getStreamBytesRaw(stream, rf); } finally { try{rf.close();}catch(Exception e){} } }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an <CODE>InputStream</CODE> covering the revision. Returns <CODE>null</CODE> if * it's not a signature field * @throws IOException on error */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); field = getTranslatedFieldName(field); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = reader.getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an <CODE>InputStream</CODE> covering the revision. Returns <CODE>null</CODE> if * it's not a signature field * @throws IOException on error */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); field = getTranslatedFieldName(field); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = reader.getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
/** Get the content from a stream applying the required filters. * @param stream the stream * @throws IOException on error * @return the stream content */ public static byte[] getStreamBytes(final PRStream stream) throws IOException { RandomAccessFileOrArray rf = stream.getReader().getSafeFile(); try { rf.reOpen(); return getStreamBytes(stream, rf); } finally { try{rf.close();}catch(Exception e){} } }
/** Get the content from a stream as it is without applying any filter. * @param stream the stream * @throws IOException on error * @return the stream content */ public static byte[] getStreamBytesRaw(final PRStream stream) throws IOException { RandomAccessFileOrArray rf = stream.getReader().getSafeFile(); try { rf.reOpen(); return getStreamBytesRaw(stream, rf); } finally { try{rf.close();}catch(Exception e){} } }
/** Gets the XML metadata. * @throws IOException on error * @return the XML metadata */ public byte[] getMetadata() throws IOException { PdfObject obj = getPdfObject(catalog.get(PdfName.METADATA)); if (!(obj instanceof PRStream)) return null; RandomAccessFileOrArray rf = getSafeFile(); byte b[] = null; try { rf.reOpen(); b = getStreamBytes((PRStream)obj, rf); } finally { try { rf.close(); } catch (Exception e) { // empty on purpose } } return b; }
/** Gets the XML metadata. * @throws IOException on error * @return the XML metadata */ public byte[] getMetadata() throws IOException { PdfObject obj = getPdfObject(catalog.get(PdfName.METADATA)); if (!(obj instanceof PRStream)) return null; RandomAccessFileOrArray rf = getSafeFile(); byte b[] = null; try { rf.reOpen(); b = getStreamBytes((PRStream)obj, rf); } finally { try { rf.close(); } catch (Exception e) { // empty on purpose } } return b; }
private void updateByteRange(PdfPKCS7 pkcs7, PdfDictionary v) { PdfArray b = v.getAsArray(PdfName.BYTERANGE); RandomAccessFileOrArray rf = reader.getSafeFile(); InputStream rg = null; try { rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(rf.createSourceView(), b.asLongArray())); 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 ExceptionConverter(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 ExceptionConverter(e); } } }
private void updateByteRange(PdfPKCS7 pkcs7, PdfDictionary v) { PdfArray b = v.getAsArray(PdfName.BYTERANGE); RandomAccessFileOrArray rf = reader.getSafeFile(); InputStream rg = null; try { rg = new RASInputStream(new RandomAccessSourceFactory().createRanged(rf.createSourceView(), b.asLongArray())); 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 ExceptionConverter(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 ExceptionConverter(e); } } }