public PdfLiteral(String content) { this(PdfEncodings.convertToBytes(content, null)); }
protected String toUnicodeString(String value, boolean isHexWriting) { byte[] bytes = decodeStringToByte(value); if (isHexWriting) { return PdfEncodings.convertToString(bytes, PdfEncodings.UNICODE_BIG_UNMARKED); } else { if (bytes.length >= 2 && bytes[0] == (byte)0xfe && bytes[1] == (byte)0xff) { return PdfEncodings.convertToString(bytes, PdfEncodings.UNICODE_BIG); } else { return PdfEncodings.convertToString(bytes, PdfEncodings.PDF_DOC_ENCODING); } } }
/** * Gets bytes of String-value considering encoding. * * @return byte array */ // Analog of com.itextpdf.text.pdf.PdfString.getBytes() method in iText5. public byte[] getValueBytes() { if (value == null) generateValue(); if (encoding != null && encoding.equals(PdfEncodings.UNICODE_BIG) && PdfEncodings.isPdfDocEncoding(value)) return PdfEncodings.convertToBytes(value, PdfEncodings.PDF_DOC_ENCODING); else return PdfEncodings.convertToBytes(value, encoding); }
protected void fillNamedEncoding() { PdfEncodings.convertToBytes(" ", baseEncoding); // check if the encoding exists boolean stdEncoding = PdfEncodings.WINANSI.equals(baseEncoding) || PdfEncodings.MACROMAN.equals(baseEncoding); if (!stdEncoding && differences == null) { differences = new String[256]; } byte[] b = new byte[256]; for (int k = 0; k < 256; ++k) { b[k] = (byte) k; } String str = PdfEncodings.convertToString(b, baseEncoding); char[] encoded = str.toCharArray(); for (int ch = 0; ch < 256; ++ch) { char uni = encoded[ch]; String name = AdobeGlyphList.unicodeToName(uni); if (name == null) { name = NOTDEF; } else { unicodeToCode.put(uni, ch); codeToUnicode[ch] = (int) uni; unicodeDifferences.put(uni, uni); } if (differences != null) { differences[ch] = name; } } }
protected void fillNamedEncoding() { PdfEncodings.convertToBytes(" ", baseEncoding); // check if the encoding exists boolean stdEncoding = PdfEncodings.WINANSI.equals(baseEncoding) || PdfEncodings.MACROMAN.equals(baseEncoding); if (!stdEncoding && differences == null) { differences = new String[256]; } byte[] b = new byte[256]; for (int k = 0; k < 256; ++k) { b[k] = (byte) k; } String str = PdfEncodings.convertToString(b, baseEncoding); char[] encoded = str.toCharArray(); for (int ch = 0; ch < 256; ++ch) { char uni = encoded[ch]; String name = AdobeGlyphList.unicodeToName(uni); if (name == null) { name = NOTDEF; } else { unicodeToCode.put(uni, ch); codeToUnicode[ch] = (int) uni; unicodeDifferences.put(uni, uni); } if (differences != null) { differences[ch] = name; } } }
/** * Sets the code that will form the barcode. This text is converted * to bytes using the encoding Cp437. * * @param text the text that will form the barcode */ public void setCode(String text) { this.code = PdfEncodings.convertToBytes(text, "cp437"); }
protected String toUnicodeString(String value, boolean isHexWriting) { byte[] bytes = decodeStringToByte(value); if (isHexWriting) { return PdfEncodings.convertToString(bytes, PdfEncodings.UNICODE_BIG_UNMARKED); } else { if (bytes.length >= 2 && bytes[0] == (byte)0xfe && bytes[1] == (byte)0xff) { return PdfEncodings.convertToString(bytes, PdfEncodings.UNICODE_BIG); } else { return PdfEncodings.convertToString(bytes, PdfEncodings.PDF_DOC_ENCODING); } } }
private byte[] convertPdfStringToBytes(PdfString pdfString) { byte[] bytes; String value = pdfString.getValue(); String encoding = pdfString.getEncoding(); if (encoding != null && encoding.equals(PdfEncodings.UNICODE_BIG) && PdfEncodings.isPdfDocEncoding(value)) bytes = PdfEncodings.convertToBytes(value, PdfEncodings.PDF_DOC_ENCODING); else bytes = PdfEncodings.convertToBytes(value, encoding); return bytes; }
protected void writeFontString(String s) { byte[] b = PdfEncodings.convertToBytes(s, PdfEncodings.WINANSI); System.arraycopy(b, 0, outFont, fontPtr, b.length); fontPtr += b.length; }
protected void generateValue() { assert content != null : "No byte[] content to generate value"; value = PdfEncodings.convertToString(decodeContent(), null); if (decryption != null) { decryption = null; content = null; } }
protected void writeFontString(String s) { byte[] b = PdfEncodings.convertToBytes(s, PdfEncodings.WINANSI); System.arraycopy(b, 0, outFont, fontPtr, b.length); fontPtr += b.length; }
private static void indexedModel(byte[] bdata, int bpc, int paletteEntries, BmpParameters bmp) { RawImageHelper.updateRawImageParameters(bmp.image, bmp.width, bmp.height, 1, bpc, bdata); Object[] colorSpace = new Object[4]; colorSpace[0] = "/Indexed"; colorSpace[1] = "/DeviceRGB"; byte[] np = getPalette(paletteEntries, bmp); int len = np.length; colorSpace[2] = len / 3 - 1; colorSpace[3] = PdfEncodings.convertToString(np, null); bmp.additional = new HashMap<>(); bmp.additional.put("ColorSpace", colorSpace); }
private void append(int in, int len) { StringBuffer sb = new StringBuffer(len + 1); sb.append(Integer.toString(in)); for (int i = sb.length(); i < len; i++) { sb.insert(0, "0"); } byte[] bytes = PdfEncodings.convertToBytes(sb.toString(), "cp437"); numberCompaction(bytes, 0, bytes.length); }
/** * Returns the Unicode {@code String} value of this * {@code PdfString}-object. */ public String toUnicodeString() { if (encoding != null && encoding.length() != 0) { return getValue(); } if (content == null) { generateContent(); } byte[] b = decodeContent(); if (b.length >= 2 && b[0] == (byte) 0xFE && b[1] == (byte) 0xFF) { return PdfEncodings.convertToString(b, PdfEncodings.UNICODE_BIG); } else if (b.length >= 3 && b[0] == (byte)0xEF && b[1] == (byte)0xBB && b[2] == (byte)0xBF) { return PdfEncodings.convertToString(b, PdfEncodings.UTF8); } else { return PdfEncodings.convertToString(b, PdfEncodings.PDF_DOC_ENCODING); } }
private void append(String s) { byte[] bytes = PdfEncodings.convertToBytes(s, "cp437"); textCompaction(bytes, 0, bytes.length); }
private static void indexedModel(byte[] bdata, int bpc, int paletteEntries, BmpParameters bmp) { RawImageHelper.updateRawImageParameters(bmp.image, bmp.width, bmp.height, 1, bpc, bdata); Object[] colorSpace = new Object[4]; colorSpace[0] = "/Indexed"; colorSpace[1] = "/DeviceRGB"; byte[] np = getPalette(paletteEntries, bmp); int len = np.length; colorSpace[2] = len / 3 - 1; colorSpace[3] = PdfEncodings.convertToString(np, null); bmp.additional = new HashMap<>(); bmp.additional.put("ColorSpace", colorSpace); }
protected static Object[] splitDAelements(String da) { PdfTokenizer tk = new PdfTokenizer(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(PdfEncodings.convertToBytes(da, null)))); List<String> stack = new ArrayList<>(); Object[] ret = new Object[3];
public static String decodeCMapObject(CMapObject cMapObject) { if (cMapObject.isHexString()) { return PdfEncodings.convertToString(((String) cMapObject.getValue()).getBytes(), PdfEncodings.UNICODE_BIG_UNMARKED); } else { return (String) cMapObject.getValue(); } } }
protected static Object[] splitDAelements(String da) { PdfTokenizer tk = new PdfTokenizer(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(PdfEncodings.convertToBytes(da, null)))); List<String> stack = new ArrayList<>(); Object[] ret = new Object[3];
/** * Converts an array of bytes to a String of hexadecimal values * * @param bytes a byte array * @return the same bytes expressed as hexadecimal values */ public static String convertToHex(byte[] bytes) { ByteBuffer buf = new ByteBuffer(); for (byte b : bytes) { buf.appendHex(b); } return PdfEncodings.convertToString(buf.toByteArray(), null).toUpperCase(); } }