Turn: Implementation PDF document with C # (original code)

xiaoxiao2021-03-05  25

Using

System;

Using

System.IO;

Using

System.Text;

Using

System.collections;

Namespace

PdfGenerator

{Public class PDFGenerator {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 strmsg;} static void main (string [] args) {ArrayList Xrefs = new arraylist () ; // Byte [] buffer = null; float ypos = 0f; long streamstart = 0; long streamend = 0; long streamle n = 0; string strpdfMessage = null; // PDF document header information strpdfMessage = "% PDF-1.1 / n"; convertTOBYTEANDDTOSTREAM (STRPDFMESSAGE); XREFS.ADD (MPDF.LENGTH); strpdfMessage = "1 0 obj / n"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "<< / Length 2 0 R >> / n"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "stream / n"; ConvertToByteAndAddtoStream (strPDFMessage); / ** ///// PDF document describes streamstart = mpdf.length; // font strpdfMessage = "bt / n / f0" fontsize "tf / n";

ConvertToByteAndAddtoStream (strPDFMessage); // PDF document entity height yPos = pageDepth - pageMargin; strPDFMessage = pageMargin "" yPos "Td / n"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = leadSize "TL / n"; ConvertToByteAndAddtoStream (strPDFMessage) ; // substantial contents strPDFMessage = "(http://www.wenhui.org) Tj / n"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = "ET / n"; ConvertToByteAndAddtoStream (strPDFMessage); streamEnd = mPDF.Length; streamLen = streamEnd-streamStart; strPDFMessage = "endstream / nendobj / n"; ConvertToByteAndAddtoStream (strPDFMessage); // version information xRefs.Add PDF document (mPDF.Length); strPDFMessage = "2 0 obj / n" streamLen "/ nendobj / N "; convertTOBYTEANDDTOSTREAM (STRPDFMESSAGE); Xrefs.Add (MPDF.Length); strpdfMessage =" 3 0 obj / n << / type / page / parent 4 0 r / contents 1 0 r >> / NENDOBJ / N "; ConvertTobyteandaddTostream (StrpdfMessage); Xrefs.Add (MPDF.Length); strpdfMessage = "4 0 obj / n << / type / pages / count 1 / n "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage =" / Kids [/ n3 0 R / n] / n "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage =" / Resources << / ProcSet [/ PDF / Text] / Font < > >> / n "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage =" / MediaBox [0 0 " pageWidth " " pageDepth "] / n >> / nendobj / n "; ConvertToByteAndAddtoStream ( StrpdfMessage; Xrefs.Add (MPDF.Length); strpdfMessage = "5 0 obj / n <<

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

New Post(0)