c# - Print an Envelope from a website? -
I want to print a standard size envelope from a webpage using C #. Does anyone know what to do? I will load the data from the system for this address and will pass it. I just need basic steps to do this.
I was going with PDF. We use, which is a free PDF creator tool for .NET. I make PDFs here on the fly using the function, and then on the page I load this page as a new window. The method I have done here is also being made for anyone who wants to do something similar.
Protected void DisplayPDFEnvelope () {try {pdf document document = new pdf document (); Pdf page pdfpage = new pdf page (); XUnit pdfWidth = new XUnit (4.125, XGraphicsUnit.Inch); XUnit pdfHeight = New XUnit (9.5, XGraphicsUnit.Inch); Pdfpage.height = pdfHeight; Pdfpage.Width = pdfWidth; Pdfpage.Orientation = PageOrientation.Landscape; XPdfFontOptions Options = New XPdfFontOptions (PdfFontEncoding.Unicode, PdfFontEmbedding.Always); Document.AddPage (pdfpage); // Create a font XFont font = New XFont ("ARIAL", 1, XFontStyle.Regular, option); // Existing content XGraphics gfx = XGraphics.FromPdfPage (pdfpage, XGraphicsPdfPageOptions.Append) Get an XGraphics object for drawing below; // Use of this method only returns a formatted address based on line breaks of // from DB, i.e. 'test person \ n address line 1 \ city, state zip' string address = GetAddress (); // Get the size of the text XSize size = gfx.MeasureString (address, font) (in point); // Create a graphical path XGraphicsPath path = new XGraphicsPath (); Path.AddString (address, font.fontfamily, xfontcity, regular, 10, new exponent (345, 160), extring format. Default); // a blurred pen and brush xpine pen = new expan (excl. Foamgrescale (0), 0); // XColor.FromArgb (50, 75, 0, 130), 3); Xbrush brush = new Xsylade brush (); // XColor.FromArgb (50, 106, 90, 205)); // stroke paths gfx Outline of the droplet (pen, brush, path); Memorystream stream = new memorystream (); Document.Save (Section, False); Page.Response.Clear (); Page. answer. Contact type = "application / pdf"; Page. response. Appendix ("content-length", stream-length.tostring ()); Page response. App header ("content-type", "app / pdf"); Page response. App header ("content-disposition", "inline; filename = envelope pdf"); Page.Response.BinaryWrite (stream.ToArray ()); Page.Response.Flush (); Stream.Close (); HttpContext.Current.ApplicationInstance.CompleteRequest (); } Hold (Exceptional) {East; }}
Comments
Post a Comment