From af728f58c0be7581ce261d11653fba6cdb59436e Mon Sep 17 00:00:00 2001 From: Rafal Niesler Date: Mon, 18 Sep 2017 16:23:32 +0200 Subject: [PATCH] Use OpenPDF instead of iText for generating PDF. --- build.gradle | 8 ++++++-- .../rendering/datauri/DataUriAwareITextUserAgent.groovy | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 35bd12f..4847981 100644 --- a/build.gradle +++ b/build.gradle @@ -53,9 +53,13 @@ dependencyManagement { } dependencies { + // flying-saucer-pdf declares a profile using openpdf instead of itext, but we cannot declare it in gradle, so we + // need to manually exclude itext and add openpdf dependency + compile("org.xhtmlrenderer:flying-saucer-pdf:9.1.7") { + exclude group: 'com.lowagie', module: 'itext' + } + compile('com.github.librepdf:openpdf:1.0.3') - compile("org.xhtmlrenderer:core-renderer:R8") - compile("com.lowagie:itext:2.1.0") testCompile("org.apache.pdfbox:pdfbox:1.0.0") { exclude module:'jempbox' } diff --git a/src/main/groovy/grails/plugins/rendering/datauri/DataUriAwareITextUserAgent.groovy b/src/main/groovy/grails/plugins/rendering/datauri/DataUriAwareITextUserAgent.groovy index 55eec69..1abd2d4 100644 --- a/src/main/groovy/grails/plugins/rendering/datauri/DataUriAwareITextUserAgent.groovy +++ b/src/main/groovy/grails/plugins/rendering/datauri/DataUriAwareITextUserAgent.groovy @@ -47,17 +47,17 @@ class DataUriAwareITextUserAgent extends ITextUserAgent { def image = Image.getInstance(dataUri.bytes) def factor = sharedContext.dotsPerPixel image.scaleAbsolute((image.plainWidth * factor) as float, (image.plainHeight * factor) as float) - resource = new ImageResource(new ITextFSImage(image)) + resource = new ImageResource(uri, new ITextFSImage(image)) _imageCache.put(uri, resource) resource } catch (Exception e) { GrailsUtil.deepSanitize(e) log.error("exception creating image from data uri (will use empty image): $dataUri", e) - new ImageResource(null) + new ImageResource(uri, null) } } else { log.error("data uri has a non image mime type (will use empty image): $dataUri") - new ImageResource(null) + new ImageResource(uri, null) } } else { super.getImageResource(uri)