Как преобразовать PDF в изображение с указанием высоты и ширины на C# и .NET


Полный код

using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
                                  // Get your free 30-day key here:   
			 // https://sautinsoft.com/start-for-free/
			
            //Convert PDF into specified Image height & width
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            
            // Set initial values
            string pdfPath = Path.GetFullPath(@"..\..\..\Potato Beetle.pdf");
            string imageFolder = new DirectoryInfo(Directory.GetCurrentDirectory()).CreateSubdirectory("Result").FullName;
            int width = 1600; // Width in Px
            int height = 1900; // Height in Px

            //Set image options
            f.ImageOptions.ImageFormat = ImageFormat.Png;
            f.ImageOptions.Resize(new Size { Width = width, Height = height }, false);

            f.OpenPdf(pdfPath);
            if (f.PageCount > 0)
            {
                // Convert all pages to PNG images
                f.ToImage(imageFolder, "Page");

                //Show image
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(imageFolder) { UseShellExecute = true });
            }
        }
    }
}

Download

Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports System.Drawing
Imports SautinSoft

Module Sample

    Sub Main()
                                ' Get your free 30-day key here: 
                                ' https://sautinsoft.com/start-for-free/

        'Convert PDF into specified Image height & width
        Dim f As New SautinSoft.PdfFocus()

        ' Set initial values
        Dim pdfPath As String = Path.GetFullPath("..\..\..\Potato Beetle.pdf")
        Dim imageFolder As String = (New DirectoryInfo(Directory.GetCurrentDirectory())).CreateSubdirectory("Result").FullName
        Dim width As Integer = 1600 ' Width in Px
        Dim height As Integer = 1900 ' Height in Px

        'Set image options
        f.ImageOptions.ImageFormat = ImageFormat.Png
        f.ImageOptions.Resize(New Size With {.Width = width, .Height = height}, False)

        f.OpenPdf(pdfPath)
        If f.PageCount > 0 Then
            ' Convert all pages to PNG images
            f.ToImage(imageFolder, "Page")

            'Show image
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(imageFolder) With {.UseShellExecute = True})
        End If
    End Sub
End Module

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.