/** * Creates a {@link IRandomAccessSource} based on an {@link InputStream}. The full content of the InputStream is read into memory and used * as the source for the {@link IRandomAccessSource} * @param inputStream the stream to read from * @return the newly created {@link IRandomAccessSource} */ public IRandomAccessSource createSource(InputStream inputStream) throws java.io.IOException{ return createSource(StreamUtil.inputStreamToArray(inputStream)); }
/** * Escapes a {@code byte} array according to the PDF conventions. * * @param bytes the {@code byte} array to escape * @return an escaped {@code byte} array */ public static byte[] createEscapedString(byte[] bytes) { return createBufferedEscapedString(bytes).toByteArray(); }
/** * Skips "len" amount of bytes from the InputStream. If len is < 0, nothing is skipped. * * @param len amount of bytes needed to skip * @throws IOException */ public void skip(int len) throws IOException{ length += len; StreamUtil.skip(in, len); }
protected void setStandardHandlerDicEntries(PdfDictionary encryptionDictionary, byte[] userKey, byte[] ownerKey) { encryptionDictionary.put(PdfName.Filter, PdfName.Standard); encryptionDictionary.put(PdfName.O, new PdfLiteral(StreamUtil.createEscapedString(ownerKey))); encryptionDictionary.put(PdfName.U, new PdfLiteral(StreamUtil.createEscapedString(userKey))); encryptionDictionary.put(PdfName.P, new PdfNumber(permissions)); }
public static void writeHexedString(OutputStream outputStream, byte[] bytes) { ByteBuffer buf = createBufferedHexedString(bytes); try { outputStream.write(buf.getInternalBuffer(), 0, buf.size()); } catch (java.io.IOException e) { throw new com.itextpdf.io.IOException(com.itextpdf.io.IOException.CannotWriteBytes, e); } }
private PdfArray getEncodedRecipients() throws IOException, GeneralSecurityException { PdfArray EncodedRecipients = new PdfArray(); byte[] cms; for (int i = 0; i < recipients.size(); i++) { try { cms = getEncodedRecipient(i); EncodedRecipients.add(new PdfLiteral(StreamUtil.createEscapedString(cms))); } catch (GeneralSecurityException e) { EncodedRecipients = null; // break was added while porting to itext7 break; } catch (IOException e) { EncodedRecipients = null; // break was added while porting to itext7 break; } } return EncodedRecipients; }
public static void writeHexedString(OutputStream outputStream, byte[] bytes) { ByteBuffer buf = createBufferedHexedString(bytes); try { outputStream.write(buf.getInternalBuffer(), 0, buf.size()); } catch (java.io.IOException e) { throw new com.itextpdf.io.IOException(com.itextpdf.io.IOException.CannotWriteBytes, e); } }
/** * Creates a {@link IRandomAccessSource} based on an {@link InputStream}. The full content of the InputStream is read into memory and used * as the source for the {@link IRandomAccessSource} * @param inputStream the stream to read from * @return the newly created {@link IRandomAccessSource} */ public IRandomAccessSource createSource(InputStream inputStream) throws java.io.IOException{ return createSource(StreamUtil.inputStreamToArray(inputStream)); }
/** * Escapes a {@code byte} array according to the PDF conventions. * * @param bytes the {@code byte} array to escape * @return an escaped {@code byte} array */ public static byte[] createEscapedString(byte[] bytes) { return createBufferedEscapedString(bytes).toByteArray(); }
private void setAES256DicEntries(PdfDictionary encryptionDictionary, byte[] oeKey, byte[] ueKey, byte[] aes256Perms, boolean encryptMetadata, boolean embeddedFilesOnly) { int vAes256 = 5; int rAes256 = 5; int rAes256Pdf2 = 6; encryptionDictionary.put(PdfName.OE, new PdfLiteral(StreamUtil.createEscapedString(oeKey))); encryptionDictionary.put(PdfName.UE, new PdfLiteral(StreamUtil.createEscapedString(ueKey))); encryptionDictionary.put(PdfName.Perms, new PdfLiteral(StreamUtil.createEscapedString(aes256Perms))); encryptionDictionary.put(PdfName.R, new PdfNumber(isPdf2 ? rAes256Pdf2 : rAes256)); encryptionDictionary.put(PdfName.V, new PdfNumber(vAes256)); PdfDictionary stdcf = new PdfDictionary(); stdcf.put(PdfName.Length, new PdfNumber(32)); if (!encryptMetadata) { encryptionDictionary.put(PdfName.EncryptMetadata, PdfBoolean.FALSE); } if (embeddedFilesOnly) { stdcf.put(PdfName.AuthEvent, PdfName.EFOpen); encryptionDictionary.put(PdfName.EFF, PdfName.StdCF); encryptionDictionary.put(PdfName.StrF, PdfName.Identity); encryptionDictionary.put(PdfName.StmF, PdfName.Identity); } else { stdcf.put(PdfName.AuthEvent, PdfName.DocOpen); encryptionDictionary.put(PdfName.StrF, PdfName.StdCF); encryptionDictionary.put(PdfName.StmF, PdfName.StdCF); } stdcf.put(PdfName.CFM, PdfName.AESV3); PdfDictionary cf = new PdfDictionary(); cf.put(PdfName.StdCF, stdcf); encryptionDictionary.put(PdfName.CF, cf); }
/** * Creates a new {@link IRandomAccessSource} by reading the specified file/resource into memory * @param stream the name of the resource to read * @return the newly created {@link IRandomAccessSource} * @throws java.io.IOException if reading the underling file or stream fails */ private IRandomAccessSource createByReadingToMemory(InputStream stream) throws java.io.IOException { try { return new ArrayRandomAccessSource(StreamUtil.inputStreamToArray(stream)); } finally { try { stream.close(); } catch (java.io.IOException ignored) { } } }
/** * Escapes a {@code byte} array according to the PDF conventions. * * @param outputStream the {@code OutputStream} an escaped {@code byte} array write to. * @param bytes the {@code byte} array to escape. */ public static void writeEscapedString(OutputStream outputStream, byte[] bytes) { ByteBuffer buf = createBufferedEscapedString(bytes); try { outputStream.write(buf.getInternalBuffer(), 0, buf.size()); } catch (java.io.IOException e) { throw new com.itextpdf.io.IOException(com.itextpdf.io.IOException.CannotWriteBytes, e); } }
/** * Creates a new {@link IRandomAccessSource} by reading the specified file/resource into memory * @param stream the name of the resource to read * @return the newly created {@link IRandomAccessSource} * @throws java.io.IOException if reading the underling file or stream fails */ private IRandomAccessSource createByReadingToMemory(InputStream stream) throws java.io.IOException { try { return new ArrayRandomAccessSource(StreamUtil.inputStreamToArray(stream)); } finally { try { stream.close(); } catch (java.io.IOException ignored) { } } }
len = getShort(jpegStream); if (len < 16) { StreamUtil.skip(jpegStream, len - 2); continue; StreamUtil.skip(jpegStream, len - 2 - bcomp.length); continue; StreamUtil.skip(jpegStream, 2); int units = jpegStream.read(); int dx = getShort(jpegStream); image.setDpi((int) (dx * 2.54f + 0.5f), (int) (dy * 2.54f + 0.5f)); StreamUtil.skip(jpegStream, len - 2 - bcomp.length - 7); continue; int markertype = marker(marker); if (markertype == VALID_MARKER) { StreamUtil.skip(jpegStream, 2); if (jpegStream.read() != 0x08) { throw new IOException(IOException._1MustHave8BitsPerComponent).setMessageParams(errorID); throw new IOException(IOException._1UnsupportedJpegMarker2).setMessageParams(errorID, Integer.toString(marker)); } else if (markertype != NOPARAM_MARKER) { StreamUtil.skip(jpegStream, getShort(jpegStream) - 2);
/** * Escapes a {@code byte} array according to the PDF conventions. * * @param outputStream the {@code OutputStream} an escaped {@code byte} array write to. * @param bytes the {@code byte} array to escape. */ public static void writeEscapedString(OutputStream outputStream, byte[] bytes) { ByteBuffer buf = createBufferedEscapedString(bytes); try { outputStream.write(buf.getInternalBuffer(), 0, buf.size()); } catch (java.io.IOException e) { throw new com.itextpdf.io.IOException(com.itextpdf.io.IOException.CannotWriteBytes, e); } }
public PdfButtonFormField setImage(String image) throws IOException { InputStream is = new FileInputStream(image); String str = Base64.encodeBytes(StreamUtil.inputStreamToArray(is)); return (PdfButtonFormField) setValue(str); }