Как преобразовать PDF файлы в TIFF-файлы с разрешением 300 dpi (точек на дюйм) на 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 files to 300-dpi JPG files
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            string[] pdfFiles = Directory.GetFiles(@"..\..\..\", "*.pdf");
            string folderWithJPGs = new DirectoryInfo(Directory.GetCurrentDirectory()).CreateSubdirectory("Result").FullName;

            foreach (string pdffile in pdfFiles)
            {
                f.OpenPdf(pdffile);

                if (f.PageCount > 0)
                {
                    //Set image format: Jpeg, 300 dpi
                    f.ImageOptions.Dpi = 300;
                    f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

                    //Save all pages to jpeg files with 300 dpi
                    f.ToImage(folderWithJPGs, Path.GetFileNameWithoutExtension(pdffile));
                }
                f.ClosePdf();
            }
            //Show folder with jpegs
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(folderWithJPGs) { UseShellExecute = true });
        }
    }
}

Download

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

Module Sample

    Sub Main()
                                ' Get your free 30-day key here: 
                                ' https://sautinsoft.com/start-for-free/
		
        'Convert PDF files to 300-dpi JPG files
        Dim f As New SautinSoft.PdfFocus()

        Dim pdfFiles() As String = Directory.GetFiles("..\..\..\", "*.pdf")
        Dim folderWithJPGs As String = (New DirectoryInfo(Directory.GetCurrentDirectory())).CreateSubdirectory("Result").FullName

        For Each pdffile As String In pdfFiles
            f.OpenPdf(pdffile)

            If f.PageCount > 0 Then
                'Set image format: JPG, 300 dpi
                f.ImageOptions.Dpi = 300
                f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg

                'Save all pages to jpg files with 300 dpi
                f.ToImage(folderWithJPGs, Path.GetFileNameWithoutExtension(pdffile))
            End If
            f.ClosePdf()
        Next pdffile
        'Show folder with jpegs
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(folderWithJPGs) With {.UseShellExecute = True})
    End Sub
End Module

Download


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



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

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