PDFファイルの変換

PDFページを異なる画像形式に変換する (Facades)

PDFページを異なる画像形式に変換するには、PdfConverterオブジェクトを作成し、BindPdfメソッドを使用してPDFファイルを開く必要があります。その後、DoConvertメソッドを呼び出して初期化タスクを実行します。次に、HasNextImageおよびGetNextImageメソッドを使用してすべてのページをループ処理できます。GetNextImageメソッドを使用すると、特定のページの画像を作成できます。このメソッドには、JPEG、GIF、PNGなどの特定のタイプの画像を作成するためにImageFormatを渡す必要があります。最後に、PdfConverterクラスのCloseメソッドを呼び出します。以下のコードスニペットは、PDFページを画像に変換する方法を示しています。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPdfPagesToImages01()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Images();

    // Create PdfConverter object
    using (var converter = new Aspose.Pdf.Facades.PdfConverter())
    {
        // Bind PDF document
        converter.BindPdf(dataDir + "ConvertPdfPagesToImages.pdf");

        // Initialize the converting process
        converter.DoConvert();

        // Check if pages exist and then convert to image one by one
        while (converter.HasNextImage())
        {
            // Generate output file name with '_out' suffix
            var outputFileName = dataDir + System.DateTime.Now.Ticks.ToString() + "_out.jpg";
            // Convert the page to image and save it
            converter.GetNextImage(outputFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
}

次のコードスニペットでは、いくつかのパラメータを変更する方法を示します。CoordinateTypeを使用して、フレーム「CropBox」を設定します。また、Resolutionを変更して、インチあたりのドット数を指定できます。次はFormPresentationMode - フォームプレゼンテーションモードです。次に、変換の開始ページ番号を設定するStartPageを指定します。範囲を設定することで、最後のページも指定できます。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPdfPagesToImages02()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Images();

    // Create PdfConverter object
    using (var converter = new Aspose.Pdf.Facades.PdfConverter())
    {
        // Bind PDF document
        converter.BindPdf(dataDir + "ConvertPdfPagesToImages.pdf");

        // Initialize the converting process
        converter.DoConvert();

        // Set additional conversion settings
        converter.CoordinateType = Aspose.Pdf.PageCoordinateType.CropBox;
        converter.Resolution = new Aspose.Pdf.Devices.Resolution(600);
        converter.FormPresentationMode = Aspose.Pdf.Devices.FormPresentationMode.Production;
        converter.StartPage = 2;

        // Check if pages exist and then convert to image one by one
        while (converter.HasNextImage())
        {
            // Generate output file name
            var outputFileName = dataDir + System.DateTime.Now.Ticks.ToString() + "_out.jpg";
            // Convert the page to image and save it
            converter.GetNextImage(outputFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
}

カスタムフォント置換を使用したPDFページの画像形式への変換

次のコードスニペットでは、PDFから画像への変換プロセス中にカスタムフォント置換を適用する方法を示します。FontRepository.Substitutionsコレクションを使用して、カスタム置換ルールを登録します。この例では、「Helvetica」フォントが見つかった場合、それは「Arial」に置き換えられます。

参照

Aspose.PDF for .NETは、PDF文書をさまざまな形式に変換することができ、他の形式からPDFへの変換も行えます。また、Aspose.PDF変換の品質を確認し、Aspose.PDFコンバーターアプリで結果をオンラインで表示できます。タスクを解決するための変換セクションを学びましょう。