Generate a PDF document (reproduced) with C #

xiaoxiao2021-03-06  129

Using

System.drawing;

Using

System.collections;

Using

System.componentmodel;

Using

System.windows.forms;

Using

System.data;

Using

System.IO;

Using

System.Text;

Namespace

PdfGenerator

{/ ** ////

/// Form1 Summary Description. /// public class form1: system.windows.Forms.form {/ ** //// // / / The designer variable is required. /// private system.componentmodel.container Components = NULL; Public Form1 () {// // Windows Form Designer Support To Support // InitializationComponent (); // // Todo: Call in InitializationComponent Add any constructor code //} / ** //// /// clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {Components.dispose ();}} Base.Dispose (DISPOSISING);} Windows Form Designer The generated code #REGION Windows Form Designer Generate / ** //// /// Designer Supports the required method - Do not use the code editor to modify the // / this method.

/// private void initializecomponent () {this.components = new system.componentmodel.container (); this.size = new system.drawing.size (300, 300); this.text = "form1";} # endregion static float pageWidth = 594.0f; static float pageDepth = 828.0f; static float pageMargin = 30.0f; static float fontSize = 20.0f; static float leadSize = 10.0f; static StreamWriter pPDF = new StreamWriter ( "E: /myPDF.pdf "); static MemoryStream mPDF = new MemoryStream (); static void ConvertToByteAndAddtoStream (string strMsg) {Byte [] buffer = null; buffer = ASCIIEncoding.ASCII.GetBytes (strMsg); mPDF.Write (buffer, 0, buffer.Length) ; Buffer = null;} static string xrefformatting (long xvalue) {string strmsg = xvalue.tostring (); int Ilen = strmsg.length; if (Ilen <10) { Stringbuilder s = new stringbuilder (); int i = 10-ilen; S.Append ('0', i); strmsg = S.toString () strmsg;} return;} static void main (string [] args {ArrayList xRefs = new ArrayList (); // Byte [] buffer = null; float yPos = 0f; long streamStart = 0; long streamEnd = 0; long streamLen = 0; string strPDFMessage = null; // PDF document header information strPDFMessage = "% PDF-1.1";

ConvertToByteAndAddtoStream (strPDFMessage); xRefs.Add (mPDF.Length); strPDFMessage = "1 0 obj"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "<< / Length 2 0 R >>"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "stream "; ConvertToByteAndAddtoStream (strPDFMessage); / ** ///// PDF document describes streamStart = mPDF.Length; // font strPDFMessage =" BT / F0 " fontSize " Tf "; ConvertToByteAndAddtoStream (strPDFMessage); // PDF document entity height yPos = pageDepth - pageMargin; strPDFMessage = pageMargin "" yPos "Td"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = leadSize "TL"; ConvertToByteAndAddtoStream (strPDFMessage); // solid content strPDFMessage = "(http: // Www.wen ***. org) TJ "; ConvertTobyTeandAddTostream (StrpdfMessage); STRP DFMessage = "ET"; ConvertToByteAndAddtoStream (strPDFMessage); streamEnd = mPDF.Length; streamLen = streamEnd-streamStart; strPDFMessage = "endstream endobj"; ConvertToByteAndAddtoStream (strPDFMessage); // Version information xRefs.Add PDF document (mPDF.Length) StrpdfMessage = "2 0 obj" streamlen "endobj"; convertTOBYTEANDDTOSTREAM (STRPDFMESSAGE); Xrefs.Add (MPDF.Length); strpdfMessage = "3 0 Obj <<

/ Type / page / parent 4 0 r / contents 1 0 r >> endobj "; convertTobyteandAddTREAM (StrpdfMessage); Xrefs.Add (MPDF.Length); strpdfMessage =" 4 0 Obj << / type / pages / count 1 "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "/ Kids [3 0 R]"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "/ Resources << / procSet [/ PDF / Text] / Font << / F0 5 0 R >> >> "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage =" / MediaBox [0 0 " pageWidth " " pageDepth "] >> endobj "; ConvertToByteAndAddtoStream (strPDFMessage); xRefs.Add (mPDF.Length); strPDFMessage =" 5 0 obj << / Type / Font / Subtype / Type1 / BaseFont / Courier / Encoding / WinAnsiEncoding >> endobj "; ConvertToByteAndAddtoStream (strPDFMessage); xRefs.Add (mPDF.Length); strPDFMessage =" 6 0 obj << / Type / Catalog / PAGES 4 0 r >> endobj "; ConvertTobyteandAdd toStream (strPDFMessage); streamStart = mPDF.Length; strPDFMessage = "xref 0 7 0000000000 65535 f"; for (int i = 0; i > "; convertTobyTeandAddTostream (StrpdfMessage);

转载请注明原文地址:https://www.9cbs.com/read-127071.html

New Post(0)