gpc / rendering

Provides rendering of GSPs as PDFs, JPEGs, GIFs and PNGs
http://gpc.github.com/rendering
Apache License 2.0
31 stars 45 forks source link

Issues with Grails PDF Renderer after using XWPF PDF Converter #43

Open ilan18 opened 6 years ago

ilan18 commented 6 years ago

Existing Grails Code is as follows:

FileOutputStream os = new FileOutputStream(filename)
ITextRenderer renderer = new ITextRenderer()
configureRenderer(renderer)
org.w3c.dom.Document document = getTheDocument()
renderer.setDocument(document, grailsApplication.config.grails.serverURL)
renderer.layout()
renderer.createPDF(os)

Now added

org.apache.poi.xwpf.converter.pdf.PdfOptions options = org.apache.poi.xwpf.converter.pdfPdfOptions.create();
OutputStream outputStream = new FileOutputStream(fileNameWithDirectory)
PdfConverter.getInstance().convert(docxDocument, outputStream, options)
outputStream.close()

Now call the original code again. Get an Exception on line creating new ITextRenderer() :

java.lang.RuntimeException: Font 'Courier-BoldOblique' with 'Cp1252' is not recognized.
    at org.xhtmlrenderer.pdf.ITextFontResolver.createInitialFontMap(ITextFontResolver.java:470) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextFontResolver.<init>(ITextFontResolver.java:40) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextRenderer.<init>(ITextRenderer.java:124) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextRenderer.<init>(ITextRenderer.java:110) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextRenderer.<init>(ITextRenderer.java:106) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextRenderer.<init>(ITextRenderer.java:102) ~[flying-saucer-pdf-9.1.12.jar:na]
Caused by: com.lowagie.text.DocumentException: Font 'Courier-BoldOblique' with 'Cp1252' is not recognized.
    at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:696) ~[itext-4.2.1.jar:na]
    at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:603) ~[itext-4.2.1.jar:na]
    at com.lowagie.text.pdf.BaseFont.createFont(BaseFont.java:438) ~[itext-4.2.1.jar:na]
    at org.xhtmlrenderer.pdf.ITextFontResolver.createFont(ITextFontResolver.java:483) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextFontResolver.createFont(ITextFontResolver.java:479) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextFontResolver.addCourier(ITextFontResolver.java:491) ~[flying-saucer-pdf-9.1.12.jar:na]
    at org.xhtmlrenderer.pdf.ITextFontResolver.createInitialFontMap(ITextFontResolver.java:459) ~[flying-saucer-pdf-9.1.12.jar:na]

build.gradle is as follows:

compile 'org.xhtmlrenderer:flying-saucer-core:9.1.12'
compile 'org.xhtmlrenderer:flying-saucer-pdf:9.1.12'
compile 'org.xhtmlrenderer:flying-saucer-log4j:9.1.12'

compile ('org.grails.plugins:rendering:2.0.3') {
        exclude group: 'org.xhtmlrenderer', module: 'core-renderer'
}

compile("com.lowagie:itext:4.2.1")