public void Write(SaveParameters param) { Stream stream = param.Stream; stream.WriteByte((byte)'['); for (int i = 0; i < _items.Count; ++i) { if (i != 0) { stream.WriteByte((byte)' '); } IPDFObject item = _items[i]; if (item is PDFDictionary || item is PDFDictionaryStream) { if (!param.WriteInheritableObjects) { StringUtility.WriteToStream(item.ObjNo, stream); stream.WriteByte((byte)' '); stream.WriteByte((byte)'0'); stream.WriteByte((byte)' '); stream.WriteByte((byte)'R'); } else { item.Write(param); } } else { item.Write(param); } } stream.WriteByte((byte)']'); }
public void Write(SaveParameters param) { Stream stream = param.Stream; stream.WriteByte((byte)'n'); stream.WriteByte((byte)'u'); stream.WriteByte((byte)'l'); stream.WriteByte((byte)'l'); }
private void writeObjects(Stream writer) { int count = _xref.Entries.Count; byte[] endObj = System.Text.Encoding.ASCII.GetBytes("\nendobj\n"); SaveParameters param = new SaveParameters(); param.Stream = writer; param.WriteInheritableObjects = false; param.Buffer = new MemoryStream(4096); param.StringBuffer = new MemoryStream(1024); param.Compression = _compression; param.Encryptor = _xref.Encryptor; if (_xref.Encryptor != null) { count--; } for (int i = 1; i < count; ++i) { Entry entry = _xref.Entries[i]; entry.Offset = (int)writer.Position; string startObj = i.ToString() + " 0 obj\n"; writer.Write(System.Text.Encoding.ASCII.GetBytes(startObj), 0, startObj.Length); param.ObjNo = i; // Если словарь подписи, то находим запись ByteRange и ее офсет if (entry.Object.ObjNo == _signature) { _byteRangeOffset = Sig.Write(param, entry.Object as PDFDictionary, out _byteRange); } else { entry.Object.Write(param); } writer.Write(endObj, 0, endObj.Length); } if (_xref.Encryptor != null) { param.Encryptor = null; param.WriteInheritableObjects = true; Entry entry = _xref.Entries[count]; entry.Offset = (int)writer.Position; string startObj = count.ToString() + " 0 obj\n"; writer.Write(System.Text.Encoding.ASCII.GetBytes(startObj), 0, startObj.Length); entry.Object.Write(param); writer.Write(endObj, 0, endObj.Length); } param.Buffer.Dispose(); param.StringBuffer.Dispose(); }
private void writeTrailer(Stream writer, PDFDictionary trailer) { string trailerHeader = "trailer\n"; writer.Write(System.Text.Encoding.ASCII.GetBytes(trailerHeader), 0, trailerHeader.Length); SaveParameters param = new SaveParameters(writer); param.WriteInheritableObjects = false; trailer.Write(param); writer.Write(System.Text.Encoding.ASCII.GetBytes("\n"), 0, 1); }
public void Write(SaveParameters param) { Stream stream = param.Stream; stream.WriteByte((byte)'<'); stream.WriteByte((byte)'<'); int count = _items.Count; for (int i = 0; i < count; ++i) { KeyValuePair <string, IPDFObject> pair = _items[i]; PDFName.Write(stream, pair.Key); stream.WriteByte((byte)' '); IPDFObject val = pair.Value; if (val is PDFDictionary || val is PDFDictionaryStream) { if (!param.WriteInheritableObjects) { StringUtility.WriteToStream(val.ObjNo, stream); stream.WriteByte((byte)' '); stream.WriteByte((byte)'0'); stream.WriteByte((byte)' '); stream.WriteByte((byte)'R'); } else { val.Write(param); } } else { val.Write(param); } if (i != count - 1) { stream.WriteByte((byte)'\n'); } } stream.WriteByte((byte)'>'); stream.WriteByte((byte)'>'); }
public void Write(SaveParameters param) { Stream stream = param.Stream; if (_value) { stream.WriteByte((byte)'t'); stream.WriteByte((byte)'r'); stream.WriteByte((byte)'u'); stream.WriteByte((byte)'e'); } else { stream.WriteByte((byte)'f'); stream.WriteByte((byte)'a'); stream.WriteByte((byte)'l'); stream.WriteByte((byte)'s'); stream.WriteByte((byte)'e'); } }
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); }
public void Write(SaveParameters param) { byte[] buf = _string; int length = _string.Length; if (param.Encryptor != null) { param.Encryptor.ResetObjectReference(param.ObjNo, param.GenNo, DataType.String); MemoryStream ms = param.StringBuffer; ms.SetLength(0); param.Encryptor.Encrypt(_string, 0, _string.Length, ms, DataType.String); length = (int)ms.Length; buf = ms.GetBuffer(); } if (_hexadecimal) { writeHexString(param.Stream, buf, 0, length); } else { writeString(param.Stream, buf, 0, length); } }
public void Write(SaveParameters param) { Write(param.Stream, _name); }
//internal ByteRange //internal Contents static internal int Write(SaveParameters param, PDFDictionary dict, out int[] byteRange) { int byteRangeOffset = -1; byteRange = new int[4]; byteRange[0] = 0; Stream stream = param.Stream; stream.WriteByte((byte)'<'); stream.WriteByte((byte)'<'); string[] keys = dict.GetKeys(); int count = keys.Length; for (int i = 0; i < count; ++i) { string key = keys[i]; PDFName.Write(stream, key); stream.WriteByte((byte)' '); IPDFObject val = dict[key]; if (key == "ByteRange") { byteRangeOffset = (int)stream.Position; } else if (key == "Contents") { byteRange[1] = (int)stream.Position; } if (val is PDFDictionary || val is PDFDictionaryStream) { if (!param.WriteInheritableObjects) { StringUtility.WriteToStream(val.ObjNo, stream); stream.WriteByte((byte)' '); stream.WriteByte((byte)'0'); stream.WriteByte((byte)' '); stream.WriteByte((byte)'R'); } else { val.Write(param); } } else { val.Write(param); } if (key == "ByteRange") { for (int j = 0; j < 30; j++) { stream.WriteByte((byte)' '); } } else if (key == "Contents") { byteRange[2] = (int)stream.Position; } if (i != count - 1) { stream.WriteByte((byte)'\n'); } } stream.WriteByte((byte)'>'); stream.WriteByte((byte)'>'); return(byteRangeOffset); }
public void Write(SaveParameters param) { _stream.Position = 0; MemoryStream output = _stream; //set compression bool filter = false; if (param.Compression == Compression.Flate) { PDFName subtype = (PDFName)_dictionary["Subtype"]; Filter[] filters = getFilters(); if (subtype != null && subtype.GetValue() == "Image" && filters.Length > 0 && filters[0] == Filter.DCT) { output = param.Buffer; output.SetLength(0); _stream.WriteTo(output); filter = true; } else if (param.Compression != Compression.None && getFilters().Length == 0) { output = param.Buffer; output.SetLength(0); FlateDecoder.Code(_stream, output); _dictionary.AddItem("Filter", new PDFName("FlateDecode")); filter = true; } } //set encryption if (param.Encryptor != null) { param.Encryptor.ResetObjectReference(param.ObjNo, param.GenNo, DataType.Stream); if (filter) { byte[] buffer = output.GetBuffer(); int length = (int)output.Length; output.SetLength(0); param.Encryptor.Encrypt(buffer, 0, length, output, DataType.Stream); } else { output = param.Buffer; output.SetLength(0); param.Encryptor.Encrypt(_stream.GetBuffer(), 0, (int)_stream.Length, output, DataType.Stream); } } output.Position = 0; _dictionary.AddItem("Length", new PDFNumber(output.Length)); _dictionary.Write(param); param.Stream.Write(StartStream, 0, StartStream.Length); param.Stream.Write(output.GetBuffer(), 0, (int)output.Length); param.Stream.Write(EndStream, 0, EndStream.Length); if (filter) { _dictionary.RemoveItem("Filter"); } }