您可以使用第三方库,如 Aspose.PDF 或 iTextSharp 来将 PDF 文件转换为图像。以下是使用 Aspose.PDF 的示例代码:

using System.Drawing;
using Aspose.Pdf;
using Aspose.Pdf.Devices;

public void ConvertPdfToImage(string pdfFilePath, string outputImagePath)
{
    Document pdfDocument = new Document(pdfFilePath);
    Page pdfPage = pdfDocument.Pages[1];
    using (FileStream imageStream = new FileStream(outputImagePath, FileMode.Create))
    {
        PngDevice pngDevice = new PngDevice(new Resolution(300));
        pngDevice.Process(pdfPage, imageStream);
    }
}

在上面的示例中,我们使用 Aspose.PDF 将第一页的 PDF 转换为 PNG 图像,并将图像保存在输出文件路径中。您可以使用不同的输出格式,如 JPEG 或 BMP 等,具体取决于您的需求。

C# .NET Core PDF 转 图片 - 使用 Aspose.PDF 库

原文地址: https://www.cveoy.top/t/topic/ooco 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录