Free Support Forum - aspose.com

DOCX to PDF conversion issue with barcode rendering using Java

I couldn’t upload the files due to the extension:
Here is the link to usps4cb.ttf
Here is the link to my docx

@vecin2,

Can you please explain the issue and requirements on your end. What you are trying to do and which API version your are using. Please share the the source files, used sample code, output and desired output files with us along with explanation of issue.

barcode.zip (50.0 KB) contains four files:

  • barcode_issue.doc: is a example of the type of .doc that we will be converting (it contains a line which uses barcode font)

  • barcode_issue.pdf: shows the current issue we are having when converting from barcode.docx to a pdf. It does not show the font as barcode, but it shows regular characters instead.

  • barcode_working.pdf: this is how we expect our pdf to look like. We were able to achieve this by manually adding the font file to the document settings (see TestBarcode.java)

  • TestBarcode.java: its the test that we are running. If you uncomment the line that sets the font then it works as expected.

We want to install the font in our servers and then having Aspose using document default settings, without us having to change the settings for each document instance (as it is showed on the test).

@vecin2,

The sample code in your shared information refers to Aspose.Words. I am moving this thread to concerned forum where our respective team will assist you furher.

@vecin2

Please note that Aspose.Words requires TrueType fonts when rendering document to fixed-page formats (JPEG, PNG, PDF or XPS). You need to install fonts that are used in your document on the machine where you are converting documents to PDF.

Please make sure that the font ‘USPS4CB’ is installed on the machine where you are converting document to PDF.

If you still face problem, please ZIP and attach ‘USPS4CB’ font here for testing. We will investigate the issue and provide you more information on it.

I have installed the ‘USPS4CB’ font in the Windows 10 machine where Aspose words is running - I can see the font being created under ‘Windows/Fonts’.
This is the mentioned font: usps4cb.zip (846 Bytes)

@vecin2

We have tested the scenario using the latest version of Aspose.Words for Java 20.7 and have not found the shared issue. So, please use Aspose.Words for Java 20.7. We have attached the output PDF with this post for your kind reference. 20.7.pdf (16.1 KB)

I have tested with aspose 20.7 and I am getting the same issue.

It produces the barcode when my test sets the filefontSource manually, like this:

doc.getFontSettings().setFontsSources(new FontSourceBase[]{systemFontSource, fileFontSource});

However when we use the default document settings (system fonts) still shows barcode as characters.

Did you install the font on a windows 10 machine by simply running the attached usps4cb.ttf ? or did you do anything else?

@vecin2

Yes, we installed the font on Windows 10 by running the attached usps4cb.ttf. Please restart the system and convert the document. Please let us know if you still face the same issue.

I have restarted and still doesn’t work. This a company laptop and I dont have a user account with full privileges, I wonder if they’d be something wrong with the installation of font?

But I am able to see and use the font within Microsoft Word, so not sure why my test Aspose eclipse project still doesn’t pick it up.

@vecin2

We have not found this issue at our side. However, we found similar issue with David font and logged this issue as WORDSJAVA-2401.

You can use the same workaround for your issue.

Could you please test the same case with some other font and let us know if you still face the same issue? Thanks for your cooperation.

I have the issue with another font.
Ive downloaded the comicate font from dafont.com

I have attached the font, the Comicate.docx and the result of Converting to Comicate.pdf using the default settings.

You can see Comicate.pdf doesn’t match the Comicate font.

Thanks,
Davidcomicate.zip (32.1 KB)

@vecin2

We have opened ‘COMICATE.TTF’ and click on ‘Install’ button to install the font on Windows 10.

We have used following code example to generate the PDF file using the latest version of Aspose.Words for Java 20.7. We have not found any issue with output PDF. Please check the attached PDF. output.pdf (3.5 KB)

Document doc = new Document(MyDir + "Comicate.docx");
doc.setWarningCallback(new com.aspose.words.IWarningCallback() {
    @Override
    public void warning(com.aspose.words.WarningInfo warningInfo) {
        if(warningInfo.getWarningType() == WarningType.FONT_SUBSTITUTION)
            System.out.println(warningInfo.getDescription());
    }
});

doc.save(MyDir + "output.pdf"); 

You are using old version of Aspose.Words for Java. We suggest you please try the latest version of Aspose.Words for Java 20.7.

When I run your code using the latest version the console prints:

Font 'Comicate' has not been found. Using 'Arial' font instead. Reason: font info substitution.

I’ve used the evalution version but If it doesn’t work in the evaluation I’d expect the same issue with licence.
This is the output file: output.zip (40.4 KB)

@vecin2

You used the old version of Aspose.Words to generate the PDF. We suggest you please use the latest version of Aspose.Words for Java 20.7. You can get 30 days temporary license and apply it before document conversion.

Im not able to get a temporary license since I don’t represent my company.

I would expect the 20.7 evaluation version to match the full licence but just with some limitations around functionality.

Shouldn’t this issue be resolved on the evaluation 20.7 version?

@vecin2

This issue does not reproduce using Aspose.Words for Java 20.7 with a valid license.

You can also get 30 days temporary license by completing the steps of shared link in my previous post.