如何在c#中通过页面URL将网页转换为pdf/图像?

如何在c#中通过页面URL将网页转换为pdf/图像?,c#,asp.net,C#,Asp.net,我需要将网页url传递到另一个aspx页面,并需要将其转换为PDF或图像格式并保存在特定路径上。有许多web服务,您可以利用它们的服务完成任务 如果您只需要屏幕截图,我建议您使用Selenium 更新您的问题。有很多图书馆可以这样做,有些是免费的,但大多数都是商业性的。免费版本通常有一些限制。选中此项: 代码参考: using System; using System.Collections.Generic; using System.Linq; using System.Text;

我需要将网页url传递到另一个aspx页面,并需要将其转换为PDF或图像格式并保存在特定路径上。

有许多web服务,您可以利用它们的服务完成任务

如果您只需要屏幕截图,我建议您使用Selenium


更新您的问题。

有很多图书馆可以这样做,有些是免费的,但大多数都是商业性的。免费版本通常有一些限制。选中此项:

代码参考:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Spire.Pdf; 
using System.Threading; 

namespace HtmlToPDF 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            // create a pdf document. 
            PdfDocument doc = new PdfDocument(); 

            String url = "http://www.e-iceblue.com/"; 
            Thread thread = new Thread(() => 
            { doc.LoadFromHTML(url, false, true, true); }); 
            thread.SetApartmentState(ApartmentState.STA); 
            thread.Start(); 
            thread.Join(); 

            // save pdf file. 
            doc.SaveToFile(@"..\..\sample.pdf"); 
            doc.Close(); 

            System.Diagnostics.Process.Start(@"..\..\sample.pdf"); 
        } 
    } 
} 

希望能有所帮助。

您是在寻找付费软件还是免费软件?您可以试用一下。将HTML文件下载到电脑,然后运行Pandoc将其转换为HTML。这就是你要找的吗?