C # (text type conversion) [drop-down menu -> C # Font CodeBehind] attached: [Implementation PDF document with C #

xiaoxiao2021-03-04  72

FontStyle fs = (FontStyle) System.Enum.Parse (typeof (FontStyle), this.Dropdownlist4.SelectedValue); Dropdownlist4 // Choose Font Font ft = new Font (this.DropDownList1.SelectedValue.ToString (), Convert.ToInt ( this.DropDownList2.SelectedValue), fs); DropDownList1 // select the font size color color = Color.FromName (this.DropDownList3.SelectedValue); DropDownList3 // selected font color ContentAlignment pos = (ContentAlignment) System.Enum.Parse (typeof ( ContentAlignment, this.dropdownList5.selectedValue; DropDownList5 // Select the position of the font

/// Implement the generated PDF document (source code) with C #

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-len; 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"; convertTOBYTEANDDTOSTREAM (STRPDFMESSAGE); / ** / PDF document Description streamstart = mpdf.length;

// font strPDFMessage = "BT / n / F0" fontSize "Tf / n"; ConvertToByteAndAddtoStream (strPDFMessage); // PDF document entity highly 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); // PDF version of the document information xRefs.Add (MPDF.LENGTH); STRPDFMESSAGE = "2 0 obj / n" streamlen "/ Nendobj / n"; convertTobyteandAddTREAM (STRPDFMESSAGE); Xrefs.Add (MPDF.Length); strpdfMessage = "3 0 Obj / n << / TYPE / PAGE / PARENT 4 0 R / Contents 1 0 r >> / NENDOBJ / N "; ConvertTobyteandAddTREAM (STRPDFMESSAGE); Xrefs.Add (MPDF.L ength); 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 << / f0 5 0 r >> >> / n"; convertTOBYTEANDDTOSTREAM (STRPDFMESSAGE); strpdfMessage = "/ MediaBox [0 0" PageWidth "" PageDepth "] / N >> / NENDOBJ / N"; ConvertTobyTeandAddTREAM (STRPDFMESSAGE);

xRefs.Add (mPDF.Length); strPDFMessage = "5 0 obj / n << / Type / Font / Subtype / Type1 / BaseFont / Courier / Encoding / WinAnsiEncoding >> / nendobj / n"; ConvertToByteAndAddtoStream (strPDFMessage); xRefs. Add (mPDF.Length); strPDFMessage = "6 0 obj / n << / Type / Catalog / Pages 4 0 R >> / nendobj / n"; ConvertToByteAndAddtoStream (strPDFMessage); streamStart = mPDF.Length; strPDFMessage = "xref / N0 7 / N0000000000 65535 f / n "; for (int i = 0; i > / n"; convertTOBYTEANDDTOSTREAM (STRPDFMESSAGE); STRPDFMESSAGE = "StartXRef / N " streamstart " / n %% EOF / N "; ConvertTobyTeandAddTostream (StrPdfMessage); MPDF.Writeto (PPDF.BaseStream); mpdf.close (); ppdf.close ();}}} -> end

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

New Post(0)