-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Openpdf does not apply font #1218
Comments
I created a test case based on the code you provided. According to ChatGPT the image has the font Trebuchet Ms. Can you please create a full Junit test which demonstrates how you create the full PDF file, how you initialize the fonts and create the text. Here are the results: This PDF file was generated: Java test case:
|
Hi @andreasrosdal, I can't upload the application's code for legal reasons, but honestly, it's quite strange. However, I later tried implementing another test that calls the method in my service to export PDFs, where I do exactly the same to register and use the font, and here it's not applying it. I made sure to have the trebuc.ttf font in the classpath of my project and verified that it’s loading correctly with No exception occurs when registering the font either, but in the generated PDF, if I check the document properties and look at the fonts used, TrebuchetMS doesn’t appear. What could be happening here? With ItexPdf, I don't have this kind of issue. I am attaching the PDF generated by my export service, where it doesn’t have the TrebuchetMS font |
Any clue about what could be going on here? |
We are trying to migrate our application from the Itextpdf to Openpdf and we are finding problems with openpdf registering the font and styles we were already using.
It does not apply them correctly and seems to be picking up a default font and size making it sloppy.
/** The Constant PDF_INF_FONTS. */
private static final String PDF_INF_FONTS = "/reports/fonts/trebuc.ttf";
/** The Constant MAIN_FONT. */
private static final String MAIN_FONT = "trebuchet ms";
static {
try {
FontFactory.register(PDF_INF_FONTS, MAIN_FONT);
} catch (final Exception e) {
LOG.error("Specific font could not be registered for pdf generation", e);
}
}
private static void registerFonts(final ParametersExport parametrosExportacion) {
letraCabeceras =
FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9, Font.NORMAL, new Color(53, 46, 109));
letraFechasPar =
FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7, Font.NORMAL, new Color(53, 46, 109));
letraFechasImpar =
FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7, Font.NORMAL, new Color(255, 255, 255));
black = FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7, Font.NORMAL, Color.BLACK);
blackBold = FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7, Font.BOLD, Color.BLACK);
etiquetaIndicadores =
FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6, Font.NORMAL, new Color(80, 88, 91));
letraIndicadores = FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 1, Font.NORMAL, Color.BLACK);
red = FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7, Font.NORMAL, new Color(178, 34, 34));
blue = FontFactory.getFont(MAIN_FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7, Font.NORMAL, new Color(0, 0, 205));
}
On the left side an example of what the code generates using ItextPDF and on the right what OpenPDF generates, not applying the font, nor the size or style
Screenshots
The text was updated successfully, but these errors were encountered: