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 streamlen = 0; string strpdfMessage = NULL; // PDF document header information strPDFMessage = "% PDF-1.1 / n"; ConvertToByteAndAddtoStream (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"; ConvertTobyTeandAddTStream (StrpdfMessage);
// PDF document entity highly yPos = pageDepth - pageMargin; strPDFMessage = pageMargin "" yPos "Td / n"; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage = leadSize "TL / n"; ConvertToByteAndAddtoStream (strPDFMessage); // entity content 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"; ConvertToByteAndAddtoStream (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"; ConvertTobyteandAddtrea M (strpdfMessage); strpdfMessage = "/ kids [/ n3 0 r / n] / n"; convertTOBYTEANDDTOSTREAM (STRPDFMESSAGE); STRPDFMESSAGE = "/ resources << / procset [/ pdf / text] / font << / f0 5 0 R >> >> / n "; ConvertToByteAndAddtoStream (strPDFMessage); strPDFMessage =" / MediaBox [0 0 " pageWidth " " pageDepth "] / n >> / nendobj / n "; ConvertToByteAndAddtoStream (strPDFMessage); xRefs. Add (MPDF.Length); strpdfMessage = "5 0 obj / n <<