#1 2022-06-10 06:10:43

Johann
Member
Registered: 2022-05-30

Groovy Script Reports - CSS not applied in exported PDF

I have created a Groovy Script Report and am currently able to export it as HTML. I am now trying to export the report as a PDF but the CSS (which I specify using a file URL in my script) is not being applied.

If I were to specify the styles within the Groovy HTML Markup itself then the styles would be applied:

h1(style: 'color: #F00', 'Hello World')

I am not sure if the CSS file URL is accessed upon the generation of the report, or if it is not accessed at all before the exporting to PDF. How should exporting of Groovy Script Reports to PDF be done properly?

Last edited by Johann (2022-06-10 06:21:27)

Offline

#2 2022-06-10 08:23:08

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Groovy Script Reports - CSS not applied in exported PDF

Hi Johann,

if it works when you insert the styles in the HTML markup itself, you can use it like this.

For the file-based case, pls provide a minimal example and we will rise a ticket if this is a reportserver issue.

Regards,
Eduardo

Offline

#3 2022-06-10 09:25:06

Johann
Member
Registered: 2022-05-30

Re: Groovy Script Reports - CSS not applied in exported PDF

The issue with in-line styles for me is that it is not scalable and maintainable. Additionally, because my server requires a VPN to be accessed, users who do not have access to the VPN are not able to access these file URLs. (hence I am trying to generate the styles **before** actually sending the report, rather than have the CSS loaded client-side.

As a simple example, the following script generates a `h1` and `p` tag which should be styled with red and green respectively.

import groovy.xml.*

def writer = new StringWriter()

new MarkupBuilder(writer).html {
    head {
        link(href: <<CSS_LINK_HERE>>, rel: "stylesheet", type: "text/css")
    }
    body {
        h1(style: 'color: red', "Hello World")
        p("Give this p tag `color: green` in the CSS file.")
    }
}

if(outputFormat  == 'pdf')
    return renderer.get("pdf").render(writer.toString())

return renderer.get("html").render(writer.toString())

I am unable to provide a CSS link because as mentioned a particular VPN connection is required for access, but I have in my own file simply the following to style the `p` tag green:

p {
    color: green
}

Offline

#4 2022-06-10 09:28:37

Johann
Member
Registered: 2022-05-30

Re: Groovy Script Reports - CSS not applied in exported PDF

Here is how I configured the Groovy Report on ReportServer:
https://ibb.co/LYv8nrn

In fact, after creating this simple example, when I try to export to PDF the addition of the CSS link causes the following error: https://ibb.co/HN89fkn

Type Exception Report

Message Filter execution threw an exception

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: Filter execution threw an exception
Root Cause

java.lang.NoClassDefFoundError: javax/security/auth/x500/X500Principal
	org.bouncycastle.jcajce.provider.asymmetric.x509.X509CertificateImpl.getSubjectX500Principal(Unknown Source)
	org.bouncycastle.jcajce.provider.asymmetric.x509.X509CertificateObject.getSubjectX500Principal(Unknown Source)
	sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:102)
	sun.security.validator.Validator.getInstance(Validator.java:181)
	sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:312)
	sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:171)
	sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:184)
	sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
	sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1596)
	sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
	sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
	sun.security.ssl.Handshaker.process_record(Handshaker.java:987)
	sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
	sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
	sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
	sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
	sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
	sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
	sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
	sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
	java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
	sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347)
	org.xhtmlrenderer.swing.NaiveUserAgent.onHttpConnection(NaiveUserAgent.java:174)
	org.xhtmlrenderer.swing.NaiveUserAgent.openConnection(NaiveUserAgent.java:157)
	org.xhtmlrenderer.swing.NaiveUserAgent.openStream(NaiveUserAgent.java:142)
	org.xhtmlrenderer.swing.NaiveUserAgent.resolveAndOpenStream(NaiveUserAgent.java:129)
	org.xhtmlrenderer.swing.NaiveUserAgent.getCSSResource(NaiveUserAgent.java:218)
	org.xhtmlrenderer.context.StylesheetFactoryImpl.parse(StylesheetFactoryImpl.java:91)
	org.xhtmlrenderer.context.StylesheetFactoryImpl.getStylesheet(StylesheetFactoryImpl.java:179)
	org.xhtmlrenderer.context.StyleReference.readAndParseAll(StyleReference.java:124)
	org.xhtmlrenderer.context.StyleReference.setDocumentContext(StyleReference.java:112)
	org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:189)
	org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:156)
	org.xhtmlrenderer.pdf.ITextRenderer.setDocumentFromString(ITextRenderer.java:173)
	org.xhtmlrenderer.pdf.ITextRenderer.setDocumentFromString(ITextRenderer.java:166)
	net.datenwerke.rs.scriptreport.service.scriptreport.renderers.PdfRenderer.render(PdfRenderer.java:42)
	net.datenwerke.rs.scriptreport.service.scriptreport.hooks.ScriptReportRenderer$render.call(Unknown Source)
	Script99.run(Script99.groovy:18)
	org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
	org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71)
	net.datenwerke.rs.scripting.service.scripting.engines.GroovyEngine.eval(GroovyEngine.java:74)
	net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:217)
	net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:263)
	net.datenwerke.rsenterprise.license.service.EnterpriseCheckInterceptor.invoke(EnterpriseCheckInterceptor.java:35)
	net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:317)
	net.datenwerke.rsenterprise.license.service.EnterpriseCheckInterceptor.invoke(EnterpriseCheckInterceptor.java:35)
	net.datenwerke.rs.scriptreport.service.scriptreport.generator.ScriptReportGenericOutputGenerator.export(ScriptReportGenericOutputGenerator.java:72)
	net.datenwerke.rs.scriptreport.service.scriptreport.ScriptReportEngine.executeReport(ScriptReportEngine.java:91)
	net.datenwerke.rs.scriptreport.service.scriptreport.ScriptReportEngine.doExecute(ScriptReportEngine.java:76)
	net.datenwerke.rs.core.service.reportmanager.engine.ReportEngine.execute(ReportEngine.java:143)
	net.datenwerke.rsenterprise.license.service.EnterpriseCheckInterceptor.invoke(EnterpriseCheckInterceptor.java:35)
	net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:211)
	net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:144)
	net.datenwerke.rs.core.server.reportexport.ReportExportServlet.executeReport(ReportExportServlet.java:574)
	net.datenwerke.rs.core.server.reportexport.ReportExportServlet.doExportReport(ReportExportServlet.java:452)
	net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exportReport(ReportExportServlet.java:375)
	net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exportReportViaSession(ReportExportServlet.java:366)
	net.datenwerke.rs.core.server.reportexport.ReportExportServlet.doGet(ReportExportServlet.java:169)
	com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:64)
	net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:109)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:109)
	com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:290)
	com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:280)
	com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:184)
	com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:89)
	com.google.inject.persist.PersistFilter.doFilter(PersistFilter.java:94)
	com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:121)
	com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:133)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/9.0.27

Offline

#5 2022-06-10 09:40:55

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Groovy Script Reports - CSS not applied in exported PDF

Hi Johann,

how exactly did you replace <<CSS_LINK_HERE>> ? can you pls post a concrete example of this?
I raised ticket RS-5900 for this issue, it is maybe a bug or an incorrect configuration.

Regards,
Eduardo

Offline

#6 2022-06-10 14:57:19

Johann
Member
Registered: 2022-05-30

Re: Groovy Script Reports - CSS not applied in exported PDF

Hi Eduardo,

One example I can give, similar to the file URL on the demo site (e.g. https://demo.raas.datenwerke.net/report … s?id=7398) is as such:

https://<<MY_IP_ADDRESS>>/reportserver/fileServerAccess?id=<<ID_OF_CSS_FILE>>

I hope this helps. Let me know if more information is needed!

Offline

#7 2022-06-10 14:58:38

Johann
Member
Registered: 2022-05-30

Re: Groovy Script Reports - CSS not applied in exported PDF

I also tried simulating the link with a link to the raw content of a GitHub gist, but I was not able to get it to work. (could be a firewall issue on my end, not too sure)

Offline

Board footer

Powered by FluxBB