Fonts source

Hi Team, when we were onPrem , we use to add all our required fonts ( Including Customised fonts ) in c:/Windows/Font

folder so that we dont get “Font not found exception” when we are converting to PDFA3B format.

But now we are moving to Azure cloud and now we dont know from where system will try to check the Fonts. Can you please give us the code snippet to refer how we can set the Source for Font ?? from where system wil look for fonts ??

@GayatriNaik

To set the source for fonts in your application when moving to Azure cloud, you can specify the path to your font files using the FileSystemStreamSource class. This allows you to load custom fonts from a specified directory.

Here’s a code snippet demonstrating how to do this:

import com.aspose.font.FileSystemStreamSource;
import com.aspose.font.Font;
import com.aspose.font.FontDefinition;
import com.aspose.font.FontFileDefinition;
import com.aspose.font.FontType;
import com.aspose.font.TtfFont;
import com.aspose.font.utilities.Utils;

public class LoadCustomFont {
    public static void main(String[] args) {
        // Specify the full path to your font file
        String fontFilePath = "path/to/your/font/Montserrat-Regular.ttf"; // Update this path

        // Create a FontDefinition using the font file
        FontDefinition fontDefinition = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fontFilePath)));
        
        // Open the font
        TtfFont font = (TtfFont) Font.open(fontDefinition);

        // You can now use the font in your application
        System.out.println("Loaded font: " + font.getFontName());
    }
}

In this example, replace "path/to/your/font/Montserrat-Regular.ttf" with the actual path where your font files are stored in Azure. This approach allows your application to access the required fonts without encountering “Font not found” exceptions during PDF conversions.

Make sure that the font files are accessible from the Azure environment where your application is running. You may need to adjust permissions or storage settings accordingly.

If you have any further questions or need additional assistance, feel free to ask!

can you please let me know in above code i can see its FontFilePath which is for 1 single text, But ideally we will be having aroung 150+ fonts so how we will handle it and when should we load this fonts when converting from PDF to PDFA3B format

Hi, @GayatriNaik
Are you using a self-hosting Pdf Cloud image or the cloud service itself?

We are using Azure WebService for Hosting our application . we also will be using azure Cloud storage to store documents

Any Updates ???

@GayatriNaik
Requests containing TextState or TextStyle properties have a Fontfile property in the request, and you can upload the font to cloud storage and then send the file path in the request.

I didnt get what you mean, can you please share the code for same for my reference please we are new in this

Hi, @GayatriNaik
Check this code please:

// Import necessary classes from the Aspose PDF Cloud library
const fs = require("fs");
const { PdfApi } = require("asposepdfcloud");
const { PdfAType } = require("asposepdfcloud/src/models/pdfAType");

// The initialization assumes that the necessary credentials (Application ID and Application Key) from https://dashboard.aspose.cloud/
const api = new PdfApi("YOUR_API_SID", "YOUR_API_KEY");

// Set the document name
const fileName = "4pages.pdf";
// Set the document name
const outputPath = "PDF3A/4pages.pdf";
// Use default storage (null indicates default storage)
const storage = null;
// Set the folder where the document is stored
const folder = "Documents";
// Set the pdf document has no password.
const password = null;

/**
 * Convert the PDF document to PDF3A using the Aspose.PDF Cloud API.
 *
 * This function performs the following steps:
 * 1. Reads a PDF file from the local file system.
 * 2. Uploads the PDF file to the Aspose.PDF Cloud storage.
 * 3. Convert PDF document to PDF3A format using the Aspose.PDF Cloud API.
 * 4. Logs the result to the console.
 *
 * @returns {Promise<void>} A Promise that resolves when the conversion is complete.
 */
async function getPdfInStorageToPdfA()
{
    // Read file from file system.
    const buffer = fs.readFileSync("testData/" + fileName);
    // Upload file to cloud storage.
    const uploadResponse = await api.uploadFile(folder + "/" +fileName, buffer, storage)
    // Swagger method for adding text: https://reference.aspose.cloud/pdf/#/Convert/PutPdfAInStorageToPdf
    // Call the API to convert the specified PDF document to PDF3A format
    const result = await api.putPdfInStorageToPdfA(
        uploadResponse.body.uploaded[0],
        outputPath,
        PdfAType.PDFA3A,
        folder,
        storage,
        password);

    // Log the response to console.
    console.log(result.body.status); // Log the status of the operation
}

// Execute the putAddText function
getPdfInStorageToPdfA();

@GayatriNaik
Converting a pdf document to PDF3B format is not currently supported.
We have noticed the reported issues and logged the following tickets in our issue tracking system for further investigation and rectification. We will notify you as soon as these issues are resolved.

PDFCLOUD-4533: Add support for PDF to PDF 3B conversion.

@GayatriNaik
The issues you have found earlier (filed as PDFCLOUD-4533) have been fixed in this version 24.11. Please update docker image.

@kirill.novinskiy : I can see that u completely ignored what i was raisisng from Beginning , I Neveer raised any issue i just rasied Query to get help for Font loading from Some Defined location thats it ?? Which Ticket u have created and what fix it has is not clear and make no CLue to me…

@GayatriNaik
if you are using a docker image, then you can specify the location of the directory with fonts when launching the container by setting parameter --volume <fonts_dir>:/fonts
In the case of using the PDF Cloud Api, you do not need to specify the path to the directory with fonts, they are already in the cloud, but for some api methods it is possible specify the fontFile parameter, which points to the path to the font file in cloud storage.
Сan you describe the problem in more detail and share the input files and sample code?