简体   繁体   English

将aspx页面转换为图像文件

[英]Converting aspx page to image file

I have c# dynamic aspx page after new property add I create for record brochure 添加新属性后,我创建了c#动态aspx页面,用于创建记录手册

http://veneristurkey.com/admin/Brochure.aspx?Admin=PropertiesBrochureA4&id=36 http://veneristurkey.com/admin/Brochure.aspx?Admin=PropertiesBrochureA4&id=36

but I want to this convert image file I am searching on internet but all with webbrowser and windows forms. 但我想在互联网上搜索此转换后的图像文件,但都使用Web浏览器和Windows窗体。 I need on page load show not css type also image file. 我需要在页面加载中显示不是CSS类型的图像文件。 jpg, png or tiff how i can do this. jpg,png或tiff,我该怎么做。 i need to see sample code.. 我需要查看示例代码。

saving aspx page into an image 2 将aspx页面保存到图像中2

As I mentioned in my comment, your best bet is to opt for attempting to render HTML to an image. 正如我在评论中提到的那样,最好的选择是选择尝试将HTML渲染为图像。

Here is the link for a library that will allow your to render html to an image: 这是一个库的链接,该链接将允许您将html渲染为图像:

http://htmlrenderer.codeplex.com/ http://htmlrenderer.codeplex.com/

Here is code that does exactly what you're asking: 这是完全符合您要求的代码:

http://amoghnatu.wordpress.com/2013/05/13/converting-html-text-to-image-using-c/ http://amoghnatu.wordpress.com/2013/05/13/converting-html-text-to-image-using-c/

Now all you have left is to get the html, since I'm assuming you don't want this to render to the browser prior to generating this image - you should look into grabbing the rendered html from the aspx page on the server prior to returning it, and then just return the image. 现在剩下的就是获取html了,因为我假设您不希望在生成此图像之前将其渲染到浏览器中-您应该先研究从服务器上的aspx页获取渲染的html,然后再进行操作。返回它,然后只返回图像。 To render a page: 渲染页面:

https://stackoverflow.com/a/647866/1017882 https://stackoverflow.com/a/647866/1017882

Sorted. 排序。

If you do not mind using a commandline tool you can have a look at wkhtmltopdf . 如果您不介意使用命令行工具,则可以看看wkhtmltopdf The package include a wkhtmltoimage component that can be used to convert HTML to image, using 该软件包包括一个wkhtmltoimage组件,该组件可用于使用以下命令将HTML转换为图像:

wkhtmltoimage [URL] [Image Path]

Codaxy also wrote a wkhtmltopdf c# wrapper available through the NuGet package manager. Codaxy还编写了一个可通过NuGet软件包管理使用的wkhtmltopdf c#包装器。 I'm not sure if the wkhtmltoimage component was included, but it should be easy enough to figure out how they wrap the wkhtml components. 我不确定是否包含wkhtmltoimage组件,但是应该很容易找出它们如何包装wkhtml组件。

i fixed my problem with screenshot machine API they are my code.. 我解决了截图机API的问题,它们是我的代码。

public void resimyap() { 公共无效resimyap(){

        var procad = WS.Satiliklars.Where(v => v.ForSaleID == int.Parse(Request.QueryString["id"])).FirstOrDefault();

        var imageBytes = GetBytesFromUrl("http://api.screenshotmachine.com/?key=xxxxxx&size=F&url=http://xxxxxxx.com/a4.aspx?id=" + procad.ForSaleID);
         string root = Server.MapPath("~/");

            // clean up the path
            if (!root.EndsWith(@"\"))
                root += @"\";

            // make a folder to store the images in
            string fileDirectory = root + @"\images\a4en\";

            // create the folder if it does not exist
            if (!System.IO.Directory.Exists(fileDirectory))
                System.IO.Directory.CreateDirectory(fileDirectory);

        WriteBytesToFile( fileDirectory + + procad.ForSaleID + ".png", imageBytes);

Yes i also try wkhtmltopdf c# wrapper but in pdf or image converting time my computer fan goin crayz. 是的,我也尝试了wkhtmltopdf C#包装器,但是在pdf或图像转换时间中,我的计算机迷迷上了crayz。 also i must upload server exe file and my hosting firm didnt support them 我也必须上传服务器exe文件,而我的托管公司不支持它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM