簡體   English   中英

將aspx頁面轉換為圖像文件

[英]Converting aspx page to image file

添加新屬性后,我創建了c#動態aspx頁面,用於創建記錄手冊

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

但我想在互聯網上搜索此轉換后的圖像文件,但都使用Web瀏覽器和Windows窗體。 我需要在頁面加載中顯示不是CSS類型的圖像文件。 jpg,png或tiff,我該怎么做。 我需要查看示例代碼。

將aspx頁面保存到圖像中2

正如我在評論中提到的那樣,最好的選擇是選擇嘗試將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還編寫了一個可通過NuGet軟件包管理使用的wkhtmltopdf c#包裝器。 我不確定是否包含wkhtmltoimage組件,但是應該很容易找出它們如何包裝wkhtml組件。

我解決了截圖機API的問題,它們是我的代碼。

公共無效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或圖像轉換時間中,我的計算機迷迷上了crayz。 我也必須上傳服務器exe文件,而我的托管公司不支持它們

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM