Set Default Font Name

[ ]

Aspose.PDF for Java API allows you to set a default font name when a font is not available in the document. You can use setDefaultFontName method of RenderingOptions class to set the default font name. In case setDefaultFontName is set to null the Times New Roman font will be used.

The following code snippet shows how to set a default font name when saving PDF into an image:

package com.aspose.pdf.examples;


import com.aspose.pdf.*;
import com.aspose.pdf.devices.PngDevice;
import com.aspose.pdf.devices.Resolution;

public class ExampleSetDefaultFontName {
    private static String _dataDir = "/home/admin1/pdf-examples/Samples/";

    public static void SetDefaultFontName() {
        Document pdfDocument = new Document(_dataDir + "input.pdf");
        FileOutputStream imageStream = null;;
        try {
            imageStream = new FileOutputStream(_dataDir + "SetDefaultFontName.png");
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block

        Resolution resolution = new Resolution(300);
        PngDevice pngDevice = new PngDevice(resolution);
        RenderingOptions ro = new RenderingOptions();
        ro.setDefaultFontName ("Arial");
        pngDevice.process(pdfDocument.getPages().get_Item(1), imageStream);