public static byte[] decodeStringToByte(PdfString s) { byte[] b = s.getBytes(); byte[] br = new byte[b.length]; System.arraycopy(b, 0, br, 0, b.length); return br; }
public static byte[] decodeStringToByte(PdfString s) { byte[] b = s.getBytes(); byte[] br = new byte[b.length]; System.arraycopy(b, 0, br, 0, b.length); return br; }
/** * Decodes a PdfString (which will contain glyph ids encoded in the font's encoding) * based on the active font, and determine the unicode equivalent * @param in the String that needs to be encoded * @return the encoded String */ private String decode(PdfString in){ byte[] bytes = in.getBytes(); return gs.font.decode(bytes, 0, bytes.length); }
/** * Decodes a PdfString (which will contain glyph ids encoded in the font's encoding) * based on the active font, and determine the unicode equivalent * @param in the String that needs to be encoded * @return the encoded String */ private String decode(PdfString in){ byte[] bytes = in.getBytes(); return gs.font.decode(bytes, 0, bytes.length); }
public byte[] getOriginalBytes() { if (originalValue == null) return getBytes(); return PdfEncodings.convertToBytes(originalValue, null); }
public byte[] getOriginalBytes() { if (originalValue == null) return getBytes(); return PdfEncodings.convertToBytes(originalValue, null); }
/** * Returns the Unicode <CODE>String</CODE> value of this * <CODE>PdfString</CODE>-object. * * @return A <CODE>String</CODE> */ public String toUnicodeString() { if (encoding != null && encoding.length() != 0) return value; getBytes(); if (bytes.length >= 2 && bytes[0] == (byte)254 && bytes[1] == (byte)255) return PdfEncodings.convertToString(bytes, PdfObject.TEXT_UNICODE); else return PdfEncodings.convertToString(bytes, PdfObject.TEXT_PDFDOCENCODING); }
/** * Returns the Unicode <CODE>String</CODE> value of this * <CODE>PdfString</CODE>-object. * * @return A <CODE>String</CODE> */ public String toUnicodeString() { if (encoding != null && encoding.length() != 0) return value; getBytes(); if (bytes.length >= 2 && bytes[0] == (byte)254 && bytes[1] == (byte)255) return PdfEncodings.convertToString(bytes, PdfObject.TEXT_UNICODE); else return PdfEncodings.convertToString(bytes, PdfObject.TEXT_PDFDOCENCODING); }
@Override void addChar(PdfString mark, PdfObject code) { try { byte[] src = mark.getBytes(); String dest = createStringFromBytes(code.getBytes()); if (src.length == 1) { singleByteMappings.put(Integer.valueOf(src[0] & 0xff), dest); } else if (src.length == 2) { int intSrc = src[0] & 0xFF; intSrc <<= 8; intSrc |= src[1] & 0xFF; doubleByteMappings.put(Integer.valueOf(intSrc), dest); } else { throw new IOException(MessageLocalization.getComposedMessage("mapping.code.should.be.1.or.two.bytes.and.not.1", src.length)); } } catch (Exception ex) { throw new ExceptionConverter(ex); } }
@Override void addChar(PdfString mark, PdfObject code) { try { byte[] src = mark.getBytes(); String dest = createStringFromBytes(code.getBytes()); if (src.length == 1) { singleByteMappings.put(Integer.valueOf(src[0] & 0xff), dest); } else if (src.length == 2) { int intSrc = src[0] & 0xFF; intSrc <<= 8; intSrc |= src[1] & 0xFF; doubleByteMappings.put(Integer.valueOf(intSrc), dest); } else { throw new IOException(MessageLocalization.getComposedMessage("mapping.code.should.be.1.or.two.bytes.and.not.1", src.length)); } } catch (Exception ex) { throw new ExceptionConverter(ex); } }
private String decodeString(PdfString ps) { if (ps.isHexWriting()) return PdfEncodings.convertToString(ps.getBytes(), "UnicodeBigUnmarked"); else return ps.toUnicodeString(); }
void addFileAttachment(String description, final PdfFileSpecification fs) throws IOException { if (description == null) { PdfString desc = (PdfString)fs.get(PdfName.DESC); if (desc == null) { description = ""; } else { description = PdfEncodings.convertToString(desc.getBytes(), null); } } fs.addDescription(description, true); if (description.length() == 0) description = "Unnamed"; String fn = PdfEncodings.convertToString(new PdfString(description, PdfObject.TEXT_UNICODE).getBytes(), null); int k = 0; while (documentFileAttachment.containsKey(fn)) { ++k; fn = PdfEncodings.convertToString(new PdfString(description + " " + k, PdfObject.TEXT_UNICODE).getBytes(), null); } documentFileAttachment.put(fn, fs.getReference()); }
void addFileAttachment(String description, final PdfFileSpecification fs) throws IOException { if (description == null) { PdfString desc = (PdfString)fs.get(PdfName.DESC); if (desc == null) { description = ""; } else { description = PdfEncodings.convertToString(desc.getBytes(), null); } } fs.addDescription(description, true); if (description.length() == 0) description = "Unnamed"; String fn = PdfEncodings.convertToString(new PdfString(description, PdfObject.TEXT_UNICODE).getBytes(), null); int k = 0; while (documentFileAttachment.containsKey(fn)) { ++k; fn = PdfEncodings.convertToString(new PdfString(description + " " + k, PdfObject.TEXT_UNICODE).getBytes(), null); } documentFileAttachment.put(fn, fs.getReference()); }
public String decodeStringToUnicode(PdfString ps) { if (ps.isHexWriting()) return PdfEncodings.convertToString(ps.getBytes(), "UnicodeBigUnmarked"); else return ps.toUnicodeString(); } }
public String decodeStringToUnicode(PdfString ps) { if (ps.isHexWriting()) return PdfEncodings.convertToString(ps.getBytes(), "UnicodeBigUnmarked"); else return ps.toUnicodeString(); } }
private String decodeString(PdfString ps) { if (ps.isHexWriting()) return PdfEncodings.convertToString(ps.getBytes(), "UnicodeBigUnmarked"); else return ps.toUnicodeString(); }
@Override public void freeReader(PdfReader reader) throws IOException { if (mergeFields) throw new UnsupportedOperationException(MessageLocalization.getComposedMessage("it.is.not.possible.to.free.reader.in.merge.fields.mode")); PdfArray array = reader.trailer.getAsArray(PdfName.ID); if (array != null) originalFileID = array.getAsString(0).getBytes(); indirectMap.remove(reader); // TODO: Removed - the user should be responsible for closing all PdfReaders. But, this could cause a lot of memory leaks in code out there that hasn't been properly closing things - maybe add a finalizer to PdfReader that calls PdfReader#close() ?? // if (currentPdfReaderInstance != null) { // if (currentPdfReaderInstance.getReader() == reader) { // try { // currentPdfReaderInstance.getReader().close(); // currentPdfReaderInstance.getReaderFile().close(); // } // catch (IOException ioe) { // // empty on purpose // } currentPdfReaderInstance = null; // } // } super.freeReader(reader); }
private PdfName getSignatureHashKey(String signatureName) throws NoSuchAlgorithmException, IOException { PdfDictionary dic = acroFields.getSignatureDictionary(signatureName); PdfString contents = dic.getAsString(PdfName.CONTENTS); byte[] bc = null; if(!reader.isEncrypted()) { bc = contents.getOriginalBytes(); }else{ bc = contents.getBytes(); } byte[] bt = null; if (PdfName.ETSI_RFC3161.equals(PdfReader.getPdfObject(dic.get(PdfName.SUBFILTER)))) { ASN1InputStream din = new ASN1InputStream(new ByteArrayInputStream(bc)); ASN1Primitive pkcs = din.readObject(); bc = pkcs.getEncoded(); } bt = hashBytesSha1(bc); return new PdfName(Utilities.convertToHex(bt)); }