Error with aspose.pdf for java

We just purchased Aspose.total for Java and paid for support as well as part of purchase.
I am trying to place a ticket but the system does not allow me to do it.
So, i decided to use the FREE support,

I am trying work with a Fillable PDF form and populate with data, when i ran my java app. in windows environment it works OK, However when i ran in the unix environment which is the intended target i get errors.

Please help, if i need to supply more info. of our code please let me know.
Thanks,
Marc

I AM GETTING THESE ERRORS:

Exception in thread “main” com.aspose.pdf.internal.l20if.l12if: Requested font type subsetting is not supported.
at com.aspose.pdf.internal.l20if.l37y.l0p(Unknown Source)
at com.aspose.pdf.internal.l4k.l1h.l1h(Unknown Source)
at com.aspose.pdf.internal.l4k.l1p.lI(Unknown Source)
at com.aspose.pdf.internal.l4f.lu.lI(Unknown Source)
at com.aspose.pdf.internal.l5if.lI.lI(Unknown Source)
at com.aspose.pdf.ComboBoxField.lf(Unknown Source)
at com.aspose.pdf.WidgetAnnotation.lI(Unknown Source)
at com.aspose.pdf.Field.updateAppearances(Unknown Source)
at com.aspose.pdf.Field.le(Unknown Source)
at com.aspose.pdf.ChoiceField.setSelected(Unknown Source)
at rr.formpdf.FormPDFfill.main(FormPDFfill.java:39)
$

@mromero_rubinrothman_com

Thank you for contacting support.

Would you please share SSCCE code, source ZIP file and environment details including JDK version, OS version etc., so that we may try to reproduce and investigate it.

Moreover, if you are facing any problem while logging in to Paid Support Helpdesk then you may contact our sales team while mentioning your 12 digit order ID, over Purchase forum.

Hi Farhan,
Bellow please find my SSCCE. it is very small,
Please help!!

My configuration is:

Java 8.
aspose.pdf-19.4.jar
Eclipse (IBM RDi Version: 9.6.0.1)
O/S Windows 7

My Problem:

i compile this program and ran it on my PC —> It work OK, perfect
i created a jar of this program and ran in my AS400 unix environment ----> i get the error i reported earlier

My Program:

package rr.formpdf;

import com.aspose.pdf.ComboBoxField;
import com.aspose.pdf.Document;
import com.aspose.pdf.Field;
import com.aspose.pdf.TextBoxField;

public class FormPDFfill {

static TextBoxField textBoxField = null;

public static void main(String[] args) {
	
	com.aspose.pdf.License license = new com.aspose.pdf.License();
	// Call setLicense method to set license
	try {
		license.setLicense("Aspose.Total.Java.lic");
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	// Open a document, this is PDF fillable document
	Document pdfDocument = new Document("FormMA1.pdf");

	Field[] fields = pdfDocument.getForm().getFields();
	for (int i = 0; i < fields.length; i++) {
		System.out.println("Form field: " + fields[i].getFullName() + "        " +
		                   "value: " + fields[i].getValue());
	}
	
	for (int i = 0; i < fields.length; i++) {
		if (fields[i].getFullName().toString().equals("CT_DIV")) {
			ComboBoxField cbField = new ComboBoxField();
			cbField = (com.aspose.pdf.ComboBoxField) fields[i]; 
			System.out.println("ComboBox item selected: 1");
			cbField.setSelected(1);
		};
		if (fields[i].getFullName().toString().equals("plff")) {
			fields[i].setValue("First Northern Bank");	
		};
		if (fields[i].getFullName().toString().equals("deft")) {
			fields[i].setValue("Mariam Sherry Harryman");	
		};
		if (fields[i].getFullName().toString().equals("doc.no")) {
			fields[i].setValue("D-0009146-772-0129");	
		};

		if (fields[i].getFullName().toString().equals("af")) {
			fields[i].setValue("No");	
		};
		if (fields[i].getFullName().toString().equals("er")) {
			fields[i].setValue("Yes");	
		};
		fields[i].setReadOnly(true);
	}
	
	// Save the updated document
	System.out.println("Output Doc is: FormMA1_out1.pdf");
	pdfDocument.save("FormMA1_out1.pdf");
	System.out.println("END OF PROCESS. . . ");
}

}

This is the error I am getting on the unix environment (IBM AS400)

Exception in thread “main” com.aspose.pdf.internal.l20if.l12if: Requested font type subsetting is not supported.
at com.aspose.pdf.internal.l20if.l37y.l0p(Unknown Source)
at com.aspose.pdf.internal.l4k.l1h.l1h(Unknown Source)
at com.aspose.pdf.internal.l4k.l1p.lI(Unknown Source)
at com.aspose.pdf.internal.l4f.lu.lI(Unknown Source)
at com.aspose.pdf.internal.l5if.lI.lI(Unknown Source)
at com.aspose.pdf.ComboBoxField.lf(Unknown Source)
at com.aspose.pdf.WidgetAnnotation.lI(Unknown Source)
at com.aspose.pdf.Field.updateAppearances(Unknown Source)
at com.aspose.pdf.Field.le(Unknown Source)
at com.aspose.pdf.ChoiceField.setSelected(Unknown Source)
at rr.formpdf.FormPDFfill.main(FormPDFfill.java:36)

@mromero_rubinrothman_com

Thank you for elaborating it further.

This is likely to be a problem related with absent fonts so please make sure to install all essential fonts in your system and set the path for required fonts before starting the process.

FontRepository.addLocalFontPath("d:/fonts/Times/");

In order to further substitute an absent font, you can use built-in monitoring for substituted fonts:

final Map<String,String> names =  new HashMap<String,String>() ;

            pdfDocument.FontSubstitution.add(new Document.FontSubstitutionHandler()
            {
                public void invoke(Font font, Font newFont)
                {
                    //add substituted FontNames into map.
                    names.put(font.getFontName(), newFont.getFontName());
                    //or print the message into console
                    System.out.println("Warning: Font "+ font.getFontName() + " was substituted with another font -> " + newFont.getFontName());
                }
            });

Moreover, would you please also share the JAR file that you have created for this program. You may also take a look on similar scenario for your kind reference and share your valuable feedback with us.

Hi Farhan,

Thank you very much!!

For your recommendation, you were right, my problem was the location of the fonts.
your code --> FontRepository.addLocalFontPath(“d:/fonts/Times/”); fixed the my problem.

However i do have one more small issue, there are some missing fonts that i need to substitute.
QUESTION: can you please let me know where is i find a sample code on how to substitute a missing font.
the 2nd code snip you provided is good but i am not clear if it does substitute a font.
Please advise.

Once again thank you so much…

Marcos

@mromero_rubinrothman_com

Thank you for your kind feedback.

We are glad to know that your problem has been resolved by suggested approach. About setting specific font for substitution, an investigation ticket with ID PDFNET-46449 is already logged in our issue management system and will let you know as soon as any further update will be available in this regard.

The issues you have found earlier (filed as PDFNET-46449) have been fixed in Aspose.PDF for .NET 19.8.

@mromero_rubinrothman_com

About setting specific font for replacement, we would like to share below findings with you:

You can specify ReplacementFont property in textsegment.TextEditOptions. The specified font will be used (if accessible) in the case where specified TextState.Font can not display segment text.

segment.TextEditOptions = new TextEditOptions(TextEditOptions.NoCharacterAction.UseCustomReplacementFont)
{
    ReplacementFont = FontRepository.FindFont("ArialUnicodeMS")
};

We have used following code for testing:

//open
Document document = new Document(inFile);

//update
for (int i = 1; i <= document.Pages.Count; i++)
{
    Page page = document.Pages[i];

    //page margins need to be updated as well, otherwise the header will be truncated
    page.PageInfo.Margin.Right = 30;
    page.PageInfo.Margin.Left = 30;

    //prepare header of PDF page
    HeaderFooter pageHeader = new HeaderFooter
    {
        Margin = new MarginInfo(30, 0, 30, 20)
    };

    double headerWidth = page.Rect.Width - 60;

    #region Build table in header

    //create table in header
    Table table = new Table
    {
        Left = 0,
        Top = 0,
        ColumnWidths = headerWidth.ToString(System.Globalization.CultureInfo.InvariantCulture),
        DefaultCellBorder =
            new BorderInfo(
                BorderSide.All,
                0.1F,
                Color.FromRgb(System.Drawing.ColorTranslator.FromHtml("#d3d3d3"))),
        Margin = new MarginInfo
        {
            Top = 0f,
            Left = 0f,
            Bottom = 0f,
            Right = 0f
        }
    };

    Table rowTable = new Table
    {
        Left = 0,
        Top = 0,
        DefaultCellBorder =
            new BorderInfo(
                BorderSide.Left,
                0.1F,
                Color.FromRgb(System.Drawing.ColorTranslator.FromHtml("#d3d3d3"))),
        DefaultCellPadding = new MarginInfo
        {
            Top = 2f,
            Left = 2f,
            Bottom = 2f,
            Right = 2f
        }
    };

    Row row = rowTable.Rows.Add();

    TextSegment segment = new TextSegment("08 包括打印出来的与 LandscapePortrait")
    {
        TextState = new TextState
        {
            FontStyle = FontStyles.Regular,
            FontSize = 12,
            Font = FontRepository.FindFont("Times New Roman")
        }
    };

    double cellWidth = segment.Rectangle.Width + 5;

    rowTable.ColumnWidths = $"{(int)(headerWidth - cellWidth)} {(int)cellWidth}";

    Cell cell1 = row.Cells.Add();
    cell1.Alignment = HorizontalAlignment.Center;

    TextState textState = new TextState
    {
        FontSize = 12,
        HorizontalAlignment = cell1.Alignment,
        Font = FontRepository.FindFont("Times New Roman")
    };

    TextFragment textFragment1 = new TextFragment();
    textFragment1.Segments.Add(new TextSegment("Cell 1 data in Latin chars")
    {
        TextState = textState
    });
    cell1.Paragraphs.Add(textFragment1);

    Cell cell2 = row.Cells.Add();
    cell2.Alignment = HorizontalAlignment.Center;

    TextFragment textFragment2 = new TextFragment();
    segment = new TextSegment("08 包括打印出来的与 LandscapePortrait")
    {
        TextState = textState
    };
    segment.TextEditOptions = new TextEditOptions(TextEditOptions.NoCharacterAction.UseCustomReplacementFont)
    {
        ReplacementFont = FontRepository.FindFont("ArialUnicodeMS")
    };
    textFragment2.Segments.Add(segment);
    cell2.Paragraphs.Add(textFragment2);

    table.Rows.Add().Cells.Add().Paragraphs.Add(rowTable);

    #endregion

    pageHeader.Paragraphs.Add(table);

    page.Header = pageHeader;

    page.FreeMemory();
}

document.Save(outFile);

Please feel free to get back to us if you need any further assistance. We will be more than happy to assist you.