private byte[] getPasswordHash(string key, PDFDictionary dictionary) { PDFString hash = dictionary[key] as PDFString; if (hash == null) { throw new PDFException(); } byte[] result = hash.GetBytes(); if (_revision < 5) { if (result.Length != 32) { throw new PDFException(); } } else { if (result.Length != 48) { throw new PDFException(); } } return(result); }
internal override float GetTextWidth(PDFString str, float fontSize) { PDFArray widths = GetDictionary()["Widths"] as PDFArray; PDFNumber fc = GetDictionary()["FirstChar"] as PDFNumber; int firstChar = 0; if (fc != null) { firstChar = (int)fc.GetValue(); } byte[] data = str.GetBytes(); float result = 0; for (int i = 0; i < data.Length; ++i) { PDFNumber w = widths[data[i] - firstChar] as PDFNumber; if (w != null) { return((float)(w.GetValue() * fontSize / 1000.0f)); } } return(result); }
protected override bool isHitInRange(PDFArray limits, object key) { string name = key as string; if (name == null) { throw new ArgumentException("Key must have a string type for NameTree."); } PDFString first = limits[0] as PDFString; PDFString last = limits[1] as PDFString; if (first != null && last != null) { int comp1 = String.Compare(first.GetValue(), name, StringComparison.Ordinal); int comp2 = String.Compare(last.GetValue(), name, StringComparison.Ordinal); if (comp1 <= 0 && comp2 >= 0) { return(true); } } return(false); }
internal static PDFDictionary Copy(PDFDictionary dict) { PDFDictionary newDict = new PDFDictionary(); PDFName type = dict["Type"] as PDFName; if (type != null) { newDict.AddItem("Type", type.Clone()); } PDFName s = dict["S"] as PDFName; if (s != null) { newDict.AddItem("S", s.Clone()); } PDFString p = dict["P"] as PDFString; if (p != null) { newDict.AddItem("P", p.Clone()); } PDFNumber st = dict["St"] as PDFNumber; if (st != null) { newDict.AddItem("St", st.Clone()); } return(newDict); }
internal override string ConvertFromFontEncoding(PDFString str) { if (str == null) { return(""); } if (_encoding == null) { _encoding = new FontEncoding(GetDictionary()["Encoding"]); } if (str == null) { return(""); } StringBuilder result = new StringBuilder(); byte[] data = str.GetBytes(); for (int i = 0; i < data.Length; ++i) { result.Append(_encoding.GetChar(data[i])); } return(result.ToString()); }
internal Destination(IPDFObject dest, IDocumentEssential owner) { PDFString s = dest as PDFString; if (s != null) { dest = owner.GetDestinationFromNames(s.GetValue()); if (dest == null) { dest = new PDFArray(); } } PDFArray array = dest as PDFArray; if (array != null) { parsePage(array, owner); parseZoomMode(array); parseProperties(array, owner); } else { dest = new PDFArray(); } _array = dest as PDFArray; }
private void readOE(PDFDictionary dict) { PDFString oe = dict["OE"] as PDFString; if (oe == null || oe.GetBytes().Length != 32) { throw new PDFException(); } _oe = oe.GetBytes(); }
private void readPerms(PDFDictionary dict) { PDFString perms = dict["Perms"] as PDFString; if (perms == null || perms.GetBytes().Length != 16) { throw new PDFException(); } _perms = perms.GetBytes(); }
private void readUE(PDFDictionary dict) { PDFString ue = dict["UE"] as PDFString; if (ue == null || ue.GetBytes().Length != 32) { throw new PDFException(); } _ue = ue.GetBytes(); }
internal override string ConvertFromFontEncoding(PDFString str) { byte[] data = str.GetBytes(); char[] result = new char[data.Length]; for (int i = 0; i < data.Length; ++i) { result[i] = (char)data[i]; } return(new string(result)); }
internal override float GetTextWidth(PDFString str, float fontSize) { byte[] data = str.GetBytes(); float result = 0; for (int i = 0; i < data.Length - 1; i += 2) { ushort glyf = (ushort)(data[i] * 256 + data[i + 1]); result += getGlyfWidth(glyf); } return(result * fontSize / 1000.0f); }
/// <summary> /// Gets the element at the specified index. /// </summary> /// <param name="index" href="http://msdn.microsoft.com/en-us/library/system.int32.aspx">The zero-based index of the element to get.</param> /// <returns cref="string" href="http://msdn.microsoft.com/en-us/library/system.string.aspx">The System.String with specified index.</returns> public string this[int index] { get { if (index < 0 || index >= Count) { throw new IndexOutOfRangeException(); } PDFString item = _items[index] as PDFString; if (item == null) { return(""); } return(item.GetValue()); } }
internal override float GetTextWidth(PDFString str, float fontSize) { PDFArray widths = GetDictionary()["Widths"] as PDFArray; float result = 0.0f; byte[] buf = str.GetBytes(); for (int i = 0; i < buf.Length; ++i) { PDFNumber w = widths[buf[i] - 32] as PDFNumber; if (w != null) { result += (float)w.GetValue(); } } result = result * fontSize / 1000.0f; return(result); }
internal static PDFDictionary Copy(PDFDictionary dict) { PDFDictionary newDict = new PDFDictionary(); PDFName type = dict["Type"] as PDFName; if (type != null) { newDict.AddItem("Type", type.Clone()); } PDFNumber count = dict["Count"] as PDFNumber; if (count != null) { newDict.AddItem("Count", count.Clone()); } PDFString title = dict["Title"] as PDFString; if (title != null) { newDict.AddItem("Title", title.Clone()); } PDFArray c = dict["C"] as PDFArray; if (c != null) { newDict.AddItem("C", c.Clone()); } PDFNumber f = dict["F"] as PDFNumber; if (f != null) { newDict.AddItem("F", f.Clone()); } //First, Last, Parent, Prev, Next, SE - do not //Dest, A - need set after adding return(newDict); }
public string ConvertFrom(PDFString str) { byte[] data = str.GetBytes(); char[] result = new char[data.Length]; for (int i = 0; i < data.Length; i += 2) { ushort glyf = (ushort)(data[i] * 256 + data[i + 1]); for (int j = 0; j < _map.Length; ++j) { if (_map[j] == glyf) { result[i] = (char)j; break; } } } return(new string(result)); }
internal override float GetTextWidth(PDFString str, float fontSize) { PDFArray widths = GetDictionary()["Widths"] as PDFArray; byte[] data = str.GetBytes(); float result = 0; if (widths != null) { PDFNumber fc = GetDictionary()["FirstChar"] as PDFNumber; int firstChar = 0; if (fc != null) { firstChar = (int)fc.GetValue(); } for (int i = 0; i < data.Length; ++i) { PDFNumber w = widths[data[i] - firstChar] as PDFNumber; if (w != null) { result += (float)w.GetValue(); } } return(result * fontSize / 1000.0f); } StandardFonts font; if (isStandardFont(out font)) { IGlyfMetrics metrics = getStandardFontMetrics(font); string tmp = ConvertFromFontEncoding(str); for (int i = 0; i < tmp.Length; ++i) { result += metrics.GetCharWidth(tmp[i]); } } return(result * fontSize / 1000.0f); }
protected override IPDFObject findItem(PDFArray array, object key) { if (array == null) { return(null); } string name = (string)key; for (int i = 0; i < array.Count; i += 2) { PDFString val = array[i] as PDFString; if (val != null && val.GetValue() == name) { return(array[i + 1]); } } return(null); }
internal override string ConvertFromFontEncoding(PDFString str) { if (str == null) { return(""); } loadCmapper(); byte[] data = str.GetBytes(); StringBuilder result = new StringBuilder(data.Length / 2 + 1); ushort glyf; char tmp; for (int i = 0; i < data.Length - 1; i += 2) { glyf = (ushort)(data[i] * 256 + data[i + 1]); tmp = _toUnicode.GetChar(glyf); if (tmp == 0) { string s = _toUnicode.GetLigature(glyf); if (s == null) { tmp = _cidToGIDMap.GetChar(glyf); if (tmp != 0) { result.Append(tmp); } } else { result.Append(s); } } else { result.Append(tmp); } } return(result.ToString()); }
internal override string ConvertFromFontEncoding(PDFString str) { if (str == null) { return(""); } loadCmappers(); byte[] data = str.GetBytes(); StringBuilder result = new StringBuilder(data.Length); char tmp; for (int i = 0; i < data.Length; ++i) { tmp = m_toUnicode.GetChar(data[i]); if (tmp == 0) { string s = m_toUnicode.GetLigature(data[i]); if (s == null) { tmp = m_encoding.GetChar(data[i]); if (tmp != 0) { result.Append(tmp); } } else { result.Append(s); } } else { result.Append(tmp); } } return(result.ToString()); }
private void parseFontAndColor() { if (Owner != null) { byte[] data = null; PDFString da = Dictionary["DA"] as PDFString; if (da != null) { data = da.GetBytes(); } else { PDFString ada = Owner.GetAcroFormDefaultAttribute(); if (ada != null) { data = ada.GetBytes(); } } if (data == null) { _fontColor = new ColorRGB(0, 0, 0); _font = new Font(StandardFonts.Helvetica, 12); _font.ChangedFontSize += changedFontSize; return; } PageOperationParser parser = new PageOperationParser(new MemoryStream(data)); List <IPDFPageOperation> operations = new List <IPDFPageOperation>(); IPDFPageOperation operation; while ((operation = parser.Next()) != null) { operations.Add(operation); } parseFont(operations); parseFontColor(operations); } }
private void readID(PDFArray arr) { if (arr == null) { _docID = new byte[16]; _isDocIDEmpty = true; return; } PDFString stringItem = arr[0] as PDFString; if (stringItem == null) { _docID = new byte[16]; _isDocIDEmpty = true; return; } byte[] id = stringItem.GetBytes(); _docID = id; _isDocIDEmpty = false; }
public Signature(float left, float top, float width, float height, string name, PDFDictionary sig, string reason, string contact, string location) : base(left, top, width, height, name, null) { Dictionary.AddItem("FT", new PDFName("Sig")); Flag = 132; // ??? PDFString sname = (PDFString )sig["Name"]; if (sname != null) { _name = sname.ToString(); } _reason = reason; _contact = contact; _location = location; _visible = true; _font = new Font(StandardFonts.Helvetica, 12); //_font.ChangedFontSize += changedFontSize; _fontColor = new ColorRGB(0, 0, 0); BorderColor = new ColorRGB(0, 0, 0); CreateApperance(); Dictionary.AddItem("V", sig); }
public void WriteDigest() { PKCS7 pkcs = new PKCS7(_cert.Akp, _cert.Chain, null, "SHA1", true); for (int i = 0; i < _byteRange.Length; i += 2) { byte[] buf = new byte[_byteRange[i + 1]]; _document.Position = _byteRange[i]; _document.Read(buf, 0, _byteRange[i + 1]); pkcs.Update(buf, 0, buf.Length); } byte[] bsig = pkcs.GetEncodedPKCS7(null, DateTime.Now, null); //byte[] sbuf = new byte[bsig.Length/* +64*/]; //Array.Copy(bsig, 0, sbuf, 0, bsig.Length); // Записываем дайджест //PDFString str = new PDFString(sbuf, true); PDFString str = new PDFString(bsig, true); SaveParameters sp = new SaveParameters(_document); sp.Stream.Position = _byteRange[1]; str.Write(sp); }
internal OptionalContentGroupLabel(PDFString str) { _value = str; }
/// <summary> /// Initializes a new instance of the Bytescout.PDF.OptionalContentGroupLabel class. /// </summary> /// <param name="text" href="http://msdn.microsoft.com/en-us/library/system.string.aspx">The text label.</param> public OptionalContentGroupLabel(string text) { _value = new PDFString(text); }
internal override string ConvertFromFontEncoding(PDFString str) { return(_fontMap.ConvertFrom(str)); }