<Fonts><Problem Severity="Error" Clause="6.3.7" ObjectID="8" Page="1" Convertable="True">Non-symbolic TrueType font 'Arial' contains Encoding entry with Differences array which is prohibited for these kinds of fonts</Problem><Problem Severity="Error" Clause="6.3.7" ObjectID="16" Page="1" Convertable="True">Non-symbolic TrueType font 'Arial' contains Encoding entry with Differences array which is prohibited for these kinds of fonts</Problem></Fonts>
Here is the Java Code:
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import com.aspose.pdf.ConvertErrorAction;
import com.aspose.pdf.Document;
import com.aspose.pdf.Font;
import com.aspose.pdf.FontCollection;
import com.aspose.pdf.FontSubsetStrategy;
import com.aspose.pdf.License;
import com.aspose.pdf.Page;
import com.aspose.pdf.PdfFormat;
import com.aspose.pdf.XForm;
import com.aspose.pdf.XFormCollection;
public class TestCaseAsposePDF {
@Test
void testPDFA() throws Exception {
try ( InputStream is = AsposePlugin.class.getResourceAsStream( "Aspose.Total.Java.lic" )) {
new License().setLicense( is );
}
File source = new File( "FAH_AUSWERTFBNEU1-1.pdf" );
File target = new File( "FAH_AUSWERTFBNEU1-PDFA.pdf" );
try ( InputStream is = new FileInputStream( source );
Document doc = new Document( is )) {
embedFonts( doc, false );
convert2Pdfa( doc, PdfFormat.PDF_A_2B );
doc.optimizeResources();
doc.save( target.getAbsolutePath() );
}
}
static void convert2Pdfa ( Document doc, PdfFormat format ) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
boolean ok = doc.convert( baos, format, ConvertErrorAction.Delete );
if ( !ok ) {
String error = baos.toString( StandardCharsets.UTF_8 );
throw new RuntimeException( error );
} else if ( baos.size() > 0 ) {
String warn = baos.toString( StandardCharsets.UTF_8 );
AsposePlugin.log.warn( "PDF/A convert warnings: {}", warn );
}
}
static void embedFonts ( Document doc, boolean subset ) {
Set < String > embedFonts = new HashSet<>();
for ( Page page : doc.getPages() ) {
FontCollection fonts = page.getResources().getFonts();
if ( fonts != null ) {
for ( Font font : fonts ) {
if ( !font.isEmbedded() ) {
font.setEmbedded( true );
embedFonts.add( font.getFontName() );
}
}
}
XFormCollection forms = page.getResources().getForms();
for ( XForm form : forms ) {
FontCollection fonts2 = form.getResources().getFonts();
if ( fonts2 != null ) {
for ( Font font : fonts2 ) {
if ( !font.isEmbedded() ) {
font.setEmbedded( true );
embedFonts.add( font.getFontName() );
}
}
}
}
}
// use only subset of fonts
if ( subset ) {
doc.getFontUtilities().subsetFonts( FontSubsetStrategy.SubsetEmbeddedFontsOnly );
}
}
}
@depi
I reproduced - I have an exception thrown when calling doc.optimizeResources();
If this line is removed, the document is generated without errors.
Please check - you also?
Sorry, I couldn’t continue the case due to vacation.
The example works without an exception. If I remove the optimizeResource(), the result is the same. The text is illegible. Do you have a T3 font installed?
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.