将 aspx 页转换为图像文件

本文关键字:图像 文件 转换 aspx | 更新日期: 2023-09-27 18:34:30

我在为记录手册创建的新属性添加后有 c# 动态 aspx 页面

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

我想转换这个图像文件,我正在互联网上搜索,但都带有网络浏览器和 Windows 表单。我需要在页面加载时显示不是css类型,还需要图像文件。JPG,PNG或TIFF我怎么能做到这一点。我需要查看示例代码。.

将 ASPX 页保存到图像 2

将 aspx 页转换为图像文件

正如我在评论中提到的,最好的选择是选择尝试将HTML呈现为图像。

这是一个库的链接,该库将允许您将html呈现为图像:

http://htmlrenderer.codeplex.com/

以下是完全按照您的要求执行的代码:

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

现在你剩下的就是获取 html,因为我假设你不希望它在生成这个图像之前呈现给浏览器 - 你应该考虑在返回之前从服务器上的 aspx 页面抓取呈现的 html,然后只返回图像。要呈现页面:

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

排序。

如果你不介意使用命令行工具,你可以看看wkhtmltopdf。该软件包包含一个 wkhtmltoimage 组件,可用于将 HTML 转换为图像,使用

wkhtmltoimage [URL] [Image Path]

Codaxy还编写了一个wkhtmltopdf c#包装器,可通过NuGet包管理器获得。我不确定是否包含wkhtmltoimage组件,但是应该很容易弄清楚它们如何包装wkhtml组件。

我解决了截图机API的问题,它们是我的代码。

public void 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);

是的,我也尝试 wkhtmltopdf c# 包装器,但在 pdf 或图像转换时间,我的电脑粉丝去克雷兹。 此外,我必须上传服务器exe文件,而我的托管公司不支持它们