/** * Adds the title of the document. * * @param title the title of the document */ void addTitle(String title) { put(PdfName.TITLE, new PdfString(title, PdfObject.TEXT_UNICODE)); }
/** * Adds a child layer. Nested layers can only have one parent. * @param child the child layer */ public void addChild(PdfLayer child) { if (child.parent != null) throw new IllegalArgumentException("The layer '" + ((PdfString)child.get(PdfName.NAME)).toUnicodeString() + "' already has a parent."); child.parent = this; if (children == null) children = new ArrayList(); children.add(child); }
/** * @return a string whose characters represent code points in a possibly two-byte font */ public String getFontCodes() { if (pdfText != null) { return pdfText.toString(); } return null; }
private String decodeString(PdfString ps) { if (ps.isHexWriting()) return PdfEncodings.convertToString(ps.getBytes(), "UnicodeBigUnmarked"); else return ps.toUnicodeString(); }
private void updateOneEntryPerDoc(PdfMergeInput input, int offset) { String name = input.getSource().getName(); if (StringUtils.isNotBlank(name)) { LOG.debug("Adding outline entry for {}", name); Map<String, Object> current = new HashMap<String, Object>(); current.put(ITextOutlineUtils.TITLE_KEY, new PdfString(removeExtension(name)).toUnicodeString()); current.put(ITextOutlineUtils.PAGE_KEY, Integer.toString(offset + 1)); current.put(ITextOutlineUtils.ACTION_KEY, ITextOutlineUtils.GOTO_VALUE); outline.add(current); } else { LOG.warn("Outline entry not created, unable to find its name."); } }
void addFileAttachment(String description, 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()); }
if (sub.equals(PdfName.ADBE_X509_RSA_SHA1)) { PdfString cert = v.getAsString(PdfName.CERT); pk = new PdfPKCS7(contents.getOriginalBytes(), cert.getBytes(), provider); pk = new PdfPKCS7(contents.getOriginalBytes(), provider); updateByteRange(pk, v); PdfString str = v.getAsString(PdfName.M); if (str != null) pk.setSignDate(PdfDate.decode(str.toString())); PdfObject obj = PdfReader.getPdfObject(v.get(PdfName.NAME)); if (obj != null) { if (obj.isString()) pk.setSignName(((PdfString)obj).toUnicodeString()); else if(obj.isName()) pk.setSignName(PdfName.decodeName(obj.toString())); pk.setReason(str.toUnicodeString()); str = v.getAsString(PdfName.LOCATION); if (str != null) pk.setLocation(str.toUnicodeString()); return pk;
else if (v.isString()) { PdfString vs = (PdfString)v; if (encoding == null || vs.getEncoding() != null) return vs.toUnicodeString(); byte b[] = vs.getBytes(); if (b.length >= 2 && b[0] == (byte)254 && b[1] == (byte)255) return vs.toUnicodeString(); try { if (encoding.equals(PdfName.SHIFT_JIS)) return vs.toUnicodeString();
public byte[] getOriginalBytes() { if (originalValue == null) return getBytes(); return PdfEncodings.convertToBytes(originalValue, null); }
for (int j = 0; j < strings.size(); ++j) { PdfString str = (PdfString)strings.get(j); str.decrypt(this);
/** * return the characters in our value without any translation. This allows * a string to be built that holds 2-byte or one-byte character codes, as needed * for processing by fonts when extracting text. * * Intended for use when no encoding transformations are desired. * @return The code points in this font as chars. */ public char[] getOriginalChars() { char[] chars; if (encoding == null || encoding.length() == 0) { byte [] bytes = getOriginalBytes(); chars = new char[bytes.length]; for (int i = 0; i<bytes.length; i++) chars[i] = (char) (bytes[i]&0xff); } else { chars = new char[0]; } return chars; }
if (sub.equals(PdfName.ADBE_X509_RSA_SHA1)) { PdfString cert = v.getAsString(PdfName.CERT); pk = new PdfPKCS7(contents.getOriginalBytes(), cert.getBytes(), provider); } else { pk = new PdfPKCS7(contents.getOriginalBytes(), provider); pk.setSignDate(PdfDate.decode(str.toString())); pk.setSignName(((PdfString) obj).toUnicodeString()); } else if (obj.isName()) { pk.setSignName(PdfName.decodeName(obj.toString())); pk.setReason(str.toUnicodeString()); pk.setLocation(str.toUnicodeString());
void addFileAttachment(String description, 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()); }
private String decodeString(PdfString ps) { if (ps.isHexWriting()) { return PdfEncodings.convertToString(ps.getBytes(), "UnicodeBigUnmarked"); } else { return ps.toUnicodeString(); } }
else if (v.isString()) { PdfString vs = (PdfString)v; if (encoding == null || vs.getEncoding() != null) return vs.toUnicodeString(); byte[] b = vs.getBytes(); if (b.length >= 2 && b[0] == (byte)254 && b[1] == (byte)255) return vs.toUnicodeString(); try { if (encoding.equals(PdfName.SHIFT_JIS)) return vs.toUnicodeString();
/** * @return The original bytes used to create this PDF string, or the bytes of our current value * if the original bytes are missing. */ public byte[] getOriginalBytes() { if (originalValue == null) return getBytes(); return PdfEncodings.convertToBytes(originalValue, null); }
for (int j = 0; j < strings.size(); ++j) { PdfString str = (PdfString)strings.get(j); str.decrypt(this);
/** * This constructor should only be called when the origin for text display is at (0,0) and the * graphical state reflects all transformations of the baseline. This is in text space units. * * 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 * @since 2.1.7 */ protected String decode(PdfString in) { byte[] bytes = in.getOriginalBytes(); return gs.font.decode(bytes, 0, bytes.length); }
/** * Sets the name of this layer. * @param name the name of this layer */ public void setName(String name) { put(PdfName.NAME, new PdfString(name, PdfObject.TEXT_UNICODE)); }
if (sub.equals(PdfName.ADBE_X509_RSA_SHA1)) { PdfString cert = v.getAsString(PdfName.CERT); pk = new PdfPKCS7(contents.getOriginalBytes(), cert.getBytes(), provider); pk = new PdfPKCS7(contents.getOriginalBytes(), provider); updateByteRange(pk, v); PdfString str = v.getAsString(PdfName.M); if (str != null) pk.setSignDate(PdfDate.decode(str.toString())); PdfObject obj = PdfReader.getPdfObject(v.get(PdfName.NAME)); if (obj != null) { if (obj.isString()) pk.setSignName(((PdfString)obj).toUnicodeString()); else if(obj.isName()) pk.setSignName(PdfName.decodeName(obj.toString())); pk.setReason(str.toUnicodeString()); str = v.getAsString(PdfName.LOCATION); if (str != null) pk.setLocation(str.toUnicodeString()); return pk;