diff --git a/engines/misc/src/main/java/org/alfresco/transform/misc/transformers/TextToPdfContentTransformer.java b/engines/misc/src/main/java/org/alfresco/transform/misc/transformers/TextToPdfContentTransformer.java index afa910ec8..319a1f471 100644 --- a/engines/misc/src/main/java/org/alfresco/transform/misc/transformers/TextToPdfContentTransformer.java +++ b/engines/misc/src/main/java/org/alfresco/transform/misc/transformers/TextToPdfContentTransformer.java @@ -399,6 +399,7 @@ public void setFont(String aFontName) private PDFont getFont(PDDocument doc, String name) { PDFont font = null; + InputStream fontIS = null; if (name == null && !fontChanged) { @@ -410,33 +411,38 @@ private PDFont getFont(PDDocument doc, String name) if (name != null) { String location = "fonts" + System.getProperty("file.separator") + name + ".ttf"; - ClassLoader loader = TextToPdfContentTransformer.class.getClassLoader(); - File fontFile = null; + ClassLoader loader = PagedTextToPDF.class.getClassLoader(); if (null != loader) { - URL resource = loader.getResource(location); - if (resource != null) - { - String file = resource.getFile(); - if (file != null && !file.isEmpty()) - { - fontFile = new File(file); - } - } + fontIS = loader.getResourceAsStream(location); } - if (null != fontFile) + if (null != fontIS) { PDDocument documentMock = new PDDocument(); - font = PDType0Font.load(documentMock, fontFile); + font = PDType0Font.load(documentMock, fontIS); } } } - catch (IOException e) + catch (IOException ioe) + { + String msg = "Error loading font " + name + " :" + ioe.getMessage(); + logger.error(msg, ioe); + } + finally { - String msg = "Error loading font " + name + " :" + e.getMessage(); - logger.error(msg, e); + if (fontIS != null) + { + try + { + fontIS.close(); + } + catch (Exception e) + { + logger.error("Error closing font inputstream: " + e.getMessage()); + } + } } if (font == null)