Web-print and web-print controls

Source: Internet
Author: User

Web-print and web-print controls

Project prospects

Since the previous printing was done by the client program, that is, winform, we need to change it to a web version. Other functions can be well implemented, that is, some difficulties encountered in printing. Due to the first printing function, it was normal to copy the winform file and call the Word document to print it. However, after being published to IIS, it cannot be implemented. After research and study, it was found that the client could not call the server to save the file. Finally, after some research, we found two ways to print the web version.

Solution

1. Use the window. print () method to print the html spelling of the page.

This is the most commonly used method. First, use html on the page to spell out the template to be printed, and then dynamically add data (innerText) where data needs to be added ), call printdiv () to print the local page. The method is as follows:

    function printdiv(printpage)  {           var headstr = "

This print will display the website title, URL, and other information on the header and footer. You need to remove the header and footer check in more settings (Google browser)

 

2. Save the print template as an image, add data at the specified position of the image, and print the image.

This method requires image processing. First, create an object based on the storage path of the image (print template) and encapsulate the drawing using Graphics.

ms = new MemoryStream();System.Drawing.Image myImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(path));map = new Bitmap(myImage);myImage.Dispose();graphics = Graphics.FromImage(map);graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;

Then, call the rendering method to draw the required text content at the specified position.

Public void DrawText (float pointX, float pointY, string text, Color color, string fontfamily = "", float fontsize = 14) {SolidBrush brush = new SolidBrush (color ); pointF p = new PointF (pointX, pointY); using (Font font = new Font (fontfamily, fontsize) {graphics. drawString (text, font, brush, p );}}

The input parameters are X, Y, text content, font color, font format, and font size in sequence. You can also save the drawn images to the specified path.

System.Drawing.Image img = System.Drawing.Image.FromStream(factory.Memory);img.Save(savePath, System.Drawing.Imaging.ImageFormat.Png);

After the image is drawn, the next step is how to print the image. You can save the drawn image to a folder of the server application, and then add the image to the page.

<div id="test">     </div>

Call the method printdiv ("test") in step 1 to print the image...

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.