Render HTML as an Image

前端 未结 9 2074
遥遥无期
遥遥无期 2020-11-27 18:19

I\'m generating a coupon based on dynamic input and a cropped image, and I\'m displaying the coupon using ntml and css right now, the problem is, printing this has become an

相关标签:
9条回答
  • 2020-11-27 18:34

    Unless the "other problems" are pretty severe, couldn't you just instruct your users to turn on Background Images when printing?

    In any case, I'd default to serving a PDF rather than an image, doubly so since it is intended for print.

    0 讨论(0)
  • 2020-11-27 18:36

    Try PDFSharp...it's not exactly a "take this HTML and make a PDF" but with a small amout of fiddling you can easily make a PDF out of the info you are using to make the HTML.

    0 讨论(0)
  • 2020-11-27 18:38

    You can render html to a bitmap using the WebBrowser control in either a winforms or console application.

    An example of this can be found here: http://www.wincustomize.com/articles.aspx?aid=136426&c=1

    The above example can be modified to run in ASP.Net by creating a new STAThread and performing an Application.Run on it to start a new message loop.

    0 讨论(0)
  • 2020-11-27 18:39

    PHP/Ruby Alternative


    If you have accessed this question and are actually looking for soething that will work without Windows, you can try the KHTML library: http://wiki.goatpr0n.de/projects/khtmld

    The website has a ridiculous name I admit, but I can assure you it is genuine. Other related pages are: the sourceforge page http://khtml2png.sourceforge.net/

    0 讨论(0)
  • 2020-11-27 18:43

    MARKUP ONLY ALTERNATE SOLUTION

    Use SVG and XSLT to transform the html data into an image that can be rendered/saved/etc.

    I'll admit that at first it was tedious getting this to work because of all of the coordinates, but well worth the effort once it is running.

    0 讨论(0)
  • 2020-11-27 18:43

    Just set up your css properly, so that you have a css file targeted at the print medium. It is pretty easy to guarantee that the coupon will always be legible, without worrying about whether they have bg images on or not. Needlesly moving to an image doesn't make any sense, unless there is some reason you don't want it to be machine readable.

    0 讨论(0)
提交回复
热议问题