Generate PDF Document (ZT) with C #

xiaoxiao2021-03-06  138

turn....

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 required designer variable. ///Prate system.componentmodel.container components = null; public form1 () {// // Windows Form Designer Support for // InitializationComponent (); // // Todo: Add any construct after INITIALIZECOMPONENT call Function code //} / ** /// / / / / / / /////> Clean all the resources being used. /// Protected {if (disponents! = Null) {components.dispose ();}} base.dispose ();} Windows Form Designer Generated Code #} WINDOWS Form Designer Generated Code # The Region Windows Form Designer generated code / ** /// /// 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 = 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"; convertTobyteandAddTREAM (STRPDFMESSAGE); Xrefs.Add (MPDF.Length); strpdfMessage = "3 0 Obj <>

endobj "; ConvertToByteAndAddtoStream (strPDFMessage); xRefs.Add (mPDF.Length); strPDFMessage =" 4 0 obj < "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage =" / Kids [3 0 R] "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "/ Resources <> >>"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "/ MediaBox [0 0" pageWidth "" pageDepth "] >> endobj"; ConvertToByteAndAddtoStream (strPDFMessage); xRefs.Add (mPDF.Length ); strPDFMessage = "5 0 obj <> endobj"; ConvertToByteAndAddtoStream (strPDFMessage); xRefs.Add (mPDF.Length); strPDFMessage = "6 0 obj <> endobj"; ConvertToByteAndAddtoStream (strPDFMessage); streamStart = mPDF.Length; strPDFMessage = "XREF 0 7 0000000000 65535 f"; for (int i = 0; i >"; ConvertToByteAndAddtoStream (strpdfMessage); strpdfMessage = "startxref" streamstart "%% EOF"; convertTOBYTEANDDTOSTREAM (STRPDFMESSAG); mpdf.writeto (ppdf.basestream); mpdf.close (); ppdf.close ();

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

New Post(0)