デフォルトフォント名の設定

Contents
[ ]

Aspose.PDF for .NET APIを使用すると、ドキュメントにフォントがない場合にデフォルトフォント名を設定できます。RenderingOptionsクラスのDefaultFontNameプロパティを使用してデフォルトフォント名を設定できます。DefaultFontNameがnullに設定されている場合、Times New Romanフォントが使用されます。次のコードスニペットは、PDFを画像に保存する際にデフォルトフォント名を設定する方法を示しています。

次のコードスニペットは、Aspose.Drawingライブラリでも動作します。

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

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "PdfToImageWithDefaultFont.pdf"))
    {
        // Open the image stream
        using (var imageStream = new FileStream(dataDir + "SetDefaultFontName.png", FileMode.Create))
        {
            // Set the resolution for the image
            var resolution = new Aspose.Pdf.Devices.Resolution(300);

            // Create the PNG device and set rendering options
            var pngDevice = new Aspose.Pdf.Devices.PngDevice(resolution);
            var ro = new Aspose.Pdf.RenderingOptions
            {
                DefaultFontName = "Arial"
            };
            pngDevice.RenderingOptions = ro;

            // Process the first page of the document and save it as an image
            pngDevice.Process(document.Pages[1], imageStream);
        }
    }
}