/// <summary> /// Set media window /// </summary> /// <param name="MediaWindow">Media window</param> /// <param name="Width">Floating window width</param> /// <param name="Height">Floating window height</param> /// <param name="Position">Floating window position</param> /// <param name="TitleBar">Floating window title bar</param> /// <param name="Resize">Floating window resize</param> /// <param name="Title">Floating window title</param> /// <remarks> /// <para> /// All optional arguments are applicable to floating window only. /// </para> /// </remarks> public void SetMediaWindow ( MediaWindow MediaWindow, Int32 Width = 0, Int32 Height = 0, WindowPosition Position = WindowPosition.Center, WindowTitleBar TitleBar = WindowTitleBar.TitleBarWithCloseButton, WindowResize Resize = WindowResize.KeepAspectRatio, String Title = null ) { // set media play window code MediaScreenParamBE.AddInteger("/W", (Int32)MediaWindow); // all choices but floating window if (MediaWindow != MediaWindow.Floating) { MediaScreenParamBE.Remove("/F"); return; } // play rendition in floating window // Table 9.19 page 774 PdfDictionary FloatingWindow = new PdfDictionary(this); MediaScreenParamBE.AddDictionary("/F", FloatingWindow); // window's dimensions if (Width == 0 || Height == 0) { Width = 320; Height = 180; } FloatingWindow.AddFormat("/D", "[{0} {1}]", Width, Height); FloatingWindow.AddInteger("/P", (Int32)Position); FloatingWindow.AddBoolean("/T", TitleBar != WindowTitleBar.NoTitleBar); if (TitleBar == WindowTitleBar.NoTitleBar) { return; } FloatingWindow.AddInteger("/R", (Int32)Resize); if (Title != null) { // if(Document.Encryption == null) // { // FloatingWindow.AddFormat("/TT", "[() ({0})]", Title); // } // else // { FloatingWindow.AddFormat("/TT", "[{0} {1}]", Document.TextToPdfString(String.Empty, this), Document.TextToPdfString(Title, this)); // } } return; }
/// <summary> /// Scale media /// </summary> /// <param name="ScaleCode">Scale media code</param> public void ScaleMedia ( ScaleMediaCode ScaleCode ) { // media scale and position within annotation rectangle // Value 0 to 5 How to scale the media to fit annotation area page 770 T 9.15 MediaPlayBE.AddInteger("/F", (int)ScaleCode); }
//////////////////////////////////////////////////////////////////// // Write object to PDF file // Called by PdfDocument.CreateFile(FileName) method // to output one indirect PDF object. // It is a virtual method. Derived classes can overwrite it. //////////////////////////////////////////////////////////////////// internal virtual void WriteObjectToPdfFile() { // save file position for this object FilePosition = Document.PdfFile.BaseStream.Position; // write object header Document.PdfFile.WriteFormat("{0} 0 obj\n", ObjectNumber); // switch based on the type of PDF indirect object switch (ObjectType) { case ObjectType.Stream: // convert byte list to array if (ObjectValueList.Count > 0) { ObjectValueArray = ObjectValueList.ToArray(); } // application test if (ObjectValueArray == null) { ObjectValueArray = new Byte[0]; } // compression is disabled if (!NoCompression) { ObjectValueArray = CompressStream(ObjectValueArray); } // encryption if (Document.Encryption != null) { ObjectValueArray = Document.Encryption.EncryptByteArray(ObjectNumber, ObjectValueArray); } // stream length Dictionary.AddInteger("/Length", ObjectValueArray.Length); // write dictionary Dictionary.WriteToPdfFile(); // write stream reserved word Document.PdfFile.WriteString("stream\n"); // write content to pdf file Document.PdfFile.Write(ObjectValueArray); // write end of stream Document.PdfFile.WriteString("\nendstream\nendobj\n"); break; case ObjectType.Dictionary: // write dictionary Dictionary.WriteToPdfFile(); // output object trailer Document.PdfFile.WriteString("endobj\n"); break; case ObjectType.Other: // convert byte list to array if (ObjectValueList.Count > 0) { ObjectValueArray = ObjectValueList.ToArray(); } // we have contents but no dictionary // write content to pdf file Document.PdfFile.Write(ObjectValueArray); // output object trailer Document.PdfFile.WriteString("\nendobj\n"); break; } // resources not used Dictionary = null; ObjectValueList = null; ObjectValueArray = null; return; }
//////////////////////////////////////////////////////////////////// /// <summary> /// Create PDF document file /// </summary> /// <remarks> /// <para>The last step of document creation after all pages were constructed.</para> /// <para> /// If PdfDocument was constructed with a file name, /// the CreateFile method will close the file after the file is /// written to. If the PdfDocument was constructed with a stream, /// the CreateFile does not close the stream. It is the user application /// that should close the stream after the stream was used. /// </para> /// </remarks> //////////////////////////////////////////////////////////////////// public void CreateFile() { // add destinations to link annotation AddDestToLinkAnnot(); // create named destinations CreateNamedDestinations(); // create page array var Kids = new StringBuilder("["); for (var Index = 0; Index < PageArray.Count; Index++) { Kids.AppendFormat("{0} 0 R ", PageArray[Index].ObjectNumber); } if (Kids.Length > 1) { Kids.Length--; } Kids.Append("]"); PagesObject.Dictionary.Add("/Kids", Kids.ToString()); // page count PagesObject.Dictionary.AddInteger("/Count", PageArray.Count); // objects for (var Index = 0; Index < ObjectArray.Count; Index++) { if (ObjectArray[Index].FilePosition == 0) { ObjectArray[Index].WriteObjectToPdfFile(); } } // save cross reference table position var XRefPos = (int)PdfFile.BaseStream.Position; // cross reference PdfFile.WriteFormat("xref\n0 {0}\n0000000000 65535 f \n", ObjectArray.Count + 1); foreach (var PO in ObjectArray) { if (PO.FilePosition != 0) { PdfFile.WriteFormat("{0:0000000000} 00000 n \n", PO.FilePosition); } else { PdfFile.WriteString("0000000000 00000 f \n"); } } // finalize trailer dictionary TrailerDict.AddInteger("/Size", ObjectArray.Count + 1); // trailer PdfFile.WriteString("trailer\n"); TrailerDict.WriteToPdfFile(); PdfFile.WriteFormat("startxref\n{0}\n", XRefPos); // write PDF end of file marker PdfFile.WriteString("%%EOF\n"); // close file and dispose all open resources Dispose(); // successful exit }
/// <summary> /// Set media window /// </summary> /// <param name="MediaWindow">Media window</param> /// <param name="Width">Floating window width</param> /// <param name="Height">Floating window height</param> /// <param name="Position">Floating window position</param> /// <param name="TitleBar">Floating window title bar</param> /// <param name="Resize">Floating window resize</param> /// <param name="Title">Floating window title</param> /// <remarks> /// <para> /// All optional arguments are applicable to floating window only. /// </para> /// </remarks> public void SetMediaWindow( MediaWindow MediaWindow, Int32 Width = 0, Int32 Height = 0, WindowPosition Position = WindowPosition.Center, WindowTitleBar TitleBar = WindowTitleBar.TitleBarWithCloseButton, WindowResize Resize = WindowResize.KeepAspectRatio, String Title = null ) { // set media play window code MediaScreenParamBE.AddInteger("/W", (Int32) MediaWindow); // all choices but floating window if(MediaWindow != MediaWindow.Floating) { MediaScreenParamBE.Remove("/F"); return; } // play rendition in floating window // Table 9.19 page 774 PdfDictionary FloatingWindow = new PdfDictionary(this); MediaScreenParamBE.AddDictionary("/F", FloatingWindow); // window's dimensions if(Width == 0 || Height == 0) { Width = 320; Height = 180; } FloatingWindow.AddFormat("/D", "[{0} {1}]", Width, Height); FloatingWindow.AddInteger("/P", (Int32) Position); FloatingWindow.AddBoolean("/T", TitleBar != WindowTitleBar.NoTitleBar); if(TitleBar == WindowTitleBar.NoTitleBar) return; FloatingWindow.AddInteger("/R", (Int32) Resize); if(Title != null) { // if(Document.Encryption == null) // { // FloatingWindow.AddFormat("/TT", "[() ({0})]", Title); // } // else // { FloatingWindow.AddFormat("/TT", "[{0} {1}]", Document.TextToPdfString(String.Empty, this), Document.TextToPdfString(Title, this)); // } } return; }
//////////////////////////////////////////////////////////////////// /// <summary> /// Create PDF document file /// </summary> /// <remarks> /// <para>The last step of document creation after all pages were constructed.</para> /// <para>If PdfDocument was constructed with a file name, /// the CreateFile method will close the file after the file is /// written to. If the PdfDocument was constructed with a stream, /// the CreateFile does not close the stream. It is the user application /// that should close the stream after the stream was used.</para> /// </remarks> //////////////////////////////////////////////////////////////////// public void CreateFile() { // add destinations to link annotation AddDestToLinkAnnot(); // create named destinations CreateNamedDestinations(); // Optional content properties dictionary if (Layers != null && Layers.LayerList.Count > 0) { // create optional content dictionary Layers.CreateDictionary(); // add to catalog object CatalogObject.Dictionary.AddIndirectReference("/OCProperties", Layers); } // create page array StringBuilder Kids = new StringBuilder("["); for (int Index = 0; Index < PageArray.Count; Index++) { Kids.AppendFormat("{0} 0 R ", PageArray[Index].ObjectNumber); } if (Kids.Length > 1) { Kids.Length--; } Kids.Append("]"); PagesObject.Dictionary.Add("/Kids", Kids.ToString()); // page count PagesObject.Dictionary.AddInteger("/Count", PageArray.Count); // page mode if (InitialDocDisplay != InitialDocDisplay.UseNone) { CatalogObject.Dictionary.Add("/PageMode", InitDocDispText[(int)InitialDocDisplay]); } // objects for (int Index = 0; Index < ObjectArray.Count; Index++) { if (ObjectArray[Index].FilePosition == 0) { ObjectArray[Index].WriteObjectToPdfFile(); } } // save cross reference table position int XRefPos = (int)PdfFile.BaseStream.Position; // cross reference PdfFile.WriteFormat("xref\n0 {0}\n0000000000 65535 f \n", ObjectArray.Count + 1); foreach (PdfObject PO in ObjectArray) { if (PO.FilePosition != 0) { PdfFile.WriteFormat("{0:0000000000} 00000 n \n", PO.FilePosition); } else { PdfFile.WriteString("0000000000 00000 f \n"); } } // finalize trailer dictionary TrailerDict.AddInteger("/Size", ObjectArray.Count + 1); // trailer PdfFile.WriteString("trailer\n"); TrailerDict.WriteToPdfFile(); PdfFile.WriteFormat("startxref\n{0}\n", XRefPos); // write PDF end of file marker PdfFile.WriteString("%%EOF\n"); // close file and dispose all open resources Dispose(); // successful exit return; }
//////////////////////////////////////////////////////////////////// // Write object to PDF file // Called by PdfDocument.CreateFile(FileName) method // to output one indirect PDF object. // It is a virtual method. Derived classes can overwrite it. //////////////////////////////////////////////////////////////////// internal virtual void WriteObjectToPdfFile() { // shortcut PdfBinaryWriter PdfFile = Document.PdfFile; // we have contents stream if (ContentsString != null && ContentsString.Length > 0) { // contents in bytes Byte[] ByteContents = new Byte[ContentsString.Length]; // convert content from string to binary // do not use Encoding.ASCII.GetBytes(...) for (Int32 Index = 0; Index < ContentsString.Length; Index++) { ByteContents[Index] = (Byte)ContentsString[Index]; } // if we have contents and dictionary we have a stream if (Dictionary != null) { // for testing compression is disabled if (!Document.Debug) { // compress stream Byte[] CompContents = CompressStream(ByteContents); if (CompContents != null) { ByteContents = CompContents; Dictionary.Add("/Filter", "/FlateDecode"); } } // encryption if (Document.Encryption != null) { ByteContents = Document.Encryption.EncryptByteArray(ObjectNumber, ByteContents); } // stream length Dictionary.AddInteger("/Length", ByteContents != null ? ByteContents.Length : 0); // write dictionary Dictionary.WriteToPdfFile(); // write stream reserved word PdfFile.WriteString("stream\n"); // write content to pdf file if (ByteContents != null) { PdfFile.Write(ByteContents); } // write end of stream PdfFile.WriteString("\nendstream\n"); } // we have contents but no dictionary else { // write content to pdf file PdfFile.Write(ByteContents); // final terminator PdfFile.Write('\n'); } } // no contents else { // we have a dictionary if (Dictionary != null) { // write dictionary Dictionary.WriteToPdfFile(); } // no contents and no dictionary else { throw new ApplicationException("Empty object"); } } // output object trailer PdfFile.WriteString("endobj\n"); return; }
//////////////////////////////////////////////////////////////////// // Write stream object to PDF file // Called by PdfDocument.CreateFile(FileName) method // to output one indirect stream PDF object. //////////////////////////////////////////////////////////////////// internal void WriteToPdfFile() { // already done or not in file object if (FilePosition != 0 || XRefType != XRefObjType.InFile) { return; } // save file position for this object FilePosition = Document.PdfFile.BaseStream.Position; // write object header Document.PdfFile.WriteFormat("{0} 0 obj\n", ObjectNumber); // stream object if (ObjectType == ObjectType.Stream) { // convert byte list to array if (ObjectValueList.Count > 0) { ObjectValueArray = ObjectValueList.ToArray(); } // object value is empty if (ObjectValueArray == null) { ObjectValueArray = new byte[0]; } // compress the stream and update dictionary if successful if (!NoCompression && PdfDocument.CompressStream(ref ObjectValueArray)) { Dictionary.Add("/Filter", "/FlateDecode"); } // encryption if (Document.Encryption != null) { ObjectValueArray = Document.Encryption.EncryptByteArray(ObjectNumber, ObjectValueArray); } // stream length Dictionary.AddInteger("/Length", ObjectValueArray.Length); // write dictionary Document.PdfFile.Write(Dictionary.ToByteArray()); // write stream reserved word Document.PdfFile.WriteString("stream\n"); // write content to pdf file Document.PdfFile.Write(ObjectValueArray); // write end of stream Document.PdfFile.WriteString("\nendstream\nendobj\n"); } else { // write dictionary Document.PdfFile.Write(Dictionary.ToByteArray()); // write end of object Document.PdfFile.WriteString("\nendobj\n"); } // this indirect object was written to output file // tell the garbage collector that these objects are not used any more Dictionary = null; ObjectValueList = null; ObjectValueArray = null; return; }