#1 2015-06-22 23:21:08

marcosfilho
Member
Registered: 2014-08-04

pdf render and chinese characters issues

Hello guys,

I have a script report that builds a html string containing the report.

then I export the report like this:

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

return new CompiledHtmlReportImpl(report)

the report contains some chinese words.. when I run the report in preview(on reportserver) or export it to HTML, the chineses words work fine however when i export them to PDF, the chinese words dont show up.

I believe that this render function uses a font that doesnt support chinese?

Is there any place where we can change this? What would be the best approach to fix this?

Thanks in advance

Regards,
Marcos

Offline

#2 2015-06-23 06:09:44

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: pdf render and chinese characters issues

Hi Marcos,

what we use behind the scenes is the flying-saucer library. Flying-saucer allows you to embed custom fonts via CSS as

@font-face {
        font-family: "UbuntuMono";
        src: url("UbuntuMono-R.ttf");
        -fs-pdf-font-embed: embed;
        -fs-pdf-font-encoding: Identity-H; 
}

* {
        font-family: "UbuntuMono";
}

For further reference have a look at https://code.google.com/p/flying-saucer/wiki/FAQPDF

Hope this helps.

Arno

Offline

#3 2015-06-24 00:34:22

marcosfilho
Member
Registered: 2014-08-04

Re: pdf render and chinese characters issues

Thanks for replying, Arno.

I tried to add a custom font but I got an error.

this is my script

import groovy.sql.Sql
import groovy.xml.*
import net.datenwerke.rs.base.service.reportengines.table.output.object.*
import java.util.Date;
import net.datenwerke.rs.core.service.datasourcemanager.entities.DatasourceDefinition;
import net.datenwerke.rs.core.service.datasourcemanager.DatasourceService;
import net.datenwerke.rs.base.service.datasources.definitions.DatabaseDatasource;
import net.datenwerke.dbpool.config.ConnectionPoolConfig;
import net.datenwerke.dbpool.DbPoolService;
import java.sql.Connection;
import java.util.concurrent.Future;
import java.text.SimpleDateFormat;
import net.datenwerke.rs.core.service.reportmanager.engine.basereports.CompiledHtmlReportImpl
import groovy.json.*
import org.apache.commons.lang.StringEscapeUtils


def report = """\
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<style>
			  
			    @font-face {
				        font-family: "UbuntuMono";
				        src: url("UbuntuMono-R.ttf");
				        -fs-pdf-font-embed: embed;
				        -fs-pdf-font-encoding: Identity-H;
				}

				* {
				        font-family: "UbuntuMono";
				}
			
		</style>

	</head>

	<body>

		<p>Enrollment Statement </p>

		<ul> 
			<li>Full name: <span> 朱凡鲁</span> </li>
		</ul>	
	</body>
</html>
""";

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

return new CompiledHtmlReportImpl(report)


 

it renders HTML ok, however when I export to pdf I get the following error :

Jun 24, 2015 9:38:00 AM net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl execute
WARNING: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
net.datenwerke.rs.core.service.reportmanager.exceptions.ReportExecutorRuntimeException: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at net.datenwerke.rs.scriptreport.service.scriptreport.generator.ScriptReportGenericOutputGenerator.export(ScriptReportGenericOutputGenerator.java:77)
	at net.datenwerke.rs.scriptreport.service.scriptreport.ScriptReportEngine.executeReport(ScriptReportEngine.java:91)
	at net.datenwerke.rs.scriptreport.service.scriptreport.ScriptReportEngine.doExecute(ScriptReportEngine.java:76)
	at net.datenwerke.rs.core.service.reportmanager.engine.ReportEngine.execute(ReportEngine.java:127)
	at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:186)
	at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:119)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exeucteReport(ReportExportServlet.java:561)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.doExportReport(ReportExportServlet.java:438)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exportReport(ReportExportServlet.java:364)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exportReportViaSession(ReportExportServlet.java:357)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.doGet(ReportExportServlet.java:171)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.CGLIB$doGet$10(<generated>)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d$$FastClassByGuice$$428cf904.invoke(<generated>)
	at com.google.inject.internal.cglib.proxy.$MethodProxy.invokeSuper(MethodProxy.java:228)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:66)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:110)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:52)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.doGet(<generated>)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.CGLIB$service$16(<generated>)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d$$FastClassByGuice$$428cf904.invoke(<generated>)
	at com.google.inject.internal.cglib.proxy.$MethodProxy.invokeSuper(MethodProxy.java:228)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:110)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:52)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.service(<generated>)
	at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
	at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
	at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
	at com.google.inject.persist.PersistFilter.doFilter(PersistFilter.java:89)
	at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
	at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
	at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at net.datenwerke.rs.scripting.service.scripting.engines.GroovyEngine.eval(GroovyEngine.java:67)
	at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:207)
	at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:253)
	at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:301)
	at net.datenwerke.rs.scriptreport.service.scriptreport.generator.ScriptReportGenericOutputGenerator.export(ScriptReportGenericOutputGenerator.java:66)
	... 56 more
Caused by: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:138)
	at net.datenwerke.rs.scripting.service.scripting.engines.GroovyEngine.eval(GroovyEngine.java:65)
	... 60 more
Caused by: javax.script.ScriptException: java.lang.NullPointerException
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:335)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:132)
	... 61 more
Caused by: java.lang.NullPointerException
	at org.xhtmlrenderer.swing.NaiveUserAgent.getBinaryResource(NaiveUserAgent.java:228)
	at org.xhtmlrenderer.pdf.ITextFontResolver.importFontFaces(ITextFontResolver.java:97)
	at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:178)
	at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)
	at org.xhtmlrenderer.pdf.ITextRenderer.setDocumentFromString(ITextRenderer.java:159)
	at net.datenwerke.rs.scriptreport.service.scriptreport.renderers.PdfRenderer.render(PdfRenderer.java:33)
	at net.datenwerke.rs.scriptreport.service.scriptreport.hooks.ScriptReportRenderer$render.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at Script5.run(Script5.groovy:225)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:332)
	... 62 more

Jun 24, 2015 9:38:00 AM net.datenwerke.rs.core.server.reportexport.ReportExportServlet doGet
WARNING: Der Bericht konnte nicht ausgeführt werden: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
net.datenwerke.rs.core.service.reportmanager.exceptions.ReportExecutorException: Der Bericht konnte nicht ausgeführt werden: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:218)
	at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:119)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exeucteReport(ReportExportServlet.java:561)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.doExportReport(ReportExportServlet.java:438)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exportReport(ReportExportServlet.java:364)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.exportReportViaSession(ReportExportServlet.java:357)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet.doGet(ReportExportServlet.java:171)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.CGLIB$doGet$10(<generated>)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d$$FastClassByGuice$$428cf904.invoke(<generated>)
	at com.google.inject.internal.cglib.proxy.$MethodProxy.invokeSuper(MethodProxy.java:228)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:66)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:110)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:52)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.doGet(<generated>)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.CGLIB$service$16(<generated>)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d$$FastClassByGuice$$428cf904.invoke(<generated>)
	at com.google.inject.internal.cglib.proxy.$MethodProxy.invokeSuper(MethodProxy.java:228)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at net.datenwerke.security.service.security.aop.SecurityCheckInterceptor.invoke(SecurityCheckInterceptor.java:110)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:72)
	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:52)
	at net.datenwerke.rs.core.server.reportexport.ReportExportServlet$$EnhancerByGuice$$d3a9b17d.service(<generated>)
	at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
	at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
	at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
	at com.google.inject.persist.PersistFilter.doFilter(PersistFilter.java:89)
	at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163)
	at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
	at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
	at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: net.datenwerke.rs.core.service.reportmanager.exceptions.ReportExecutorRuntimeException: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at net.datenwerke.rs.scriptreport.service.scriptreport.generator.ScriptReportGenericOutputGenerator.export(ScriptReportGenericOutputGenerator.java:77)
	at net.datenwerke.rs.scriptreport.service.scriptreport.ScriptReportEngine.executeReport(ScriptReportEngine.java:91)
	at net.datenwerke.rs.scriptreport.service.scriptreport.ScriptReportEngine.doExecute(ScriptReportEngine.java:76)
	at net.datenwerke.rs.core.service.reportmanager.engine.ReportEngine.execute(ReportEngine.java:127)
	at net.datenwerke.rs.core.service.reportmanager.ReportExecutorServiceImpl.execute(ReportExecutorServiceImpl.java:186)
	... 52 more
Caused by: net.datenwerke.rs.scripting.service.scripting.exceptions.ScriptEngineException: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at net.datenwerke.rs.scripting.service.scripting.engines.GroovyEngine.eval(GroovyEngine.java:67)
	at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:207)
	at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:253)
	at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:301)
	at net.datenwerke.rs.scriptreport.service.scriptreport.generator.ScriptReportGenericOutputGenerator.export(ScriptReportGenericOutputGenerator.java:66)
	... 56 more
Caused by: javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:138)
	at net.datenwerke.rs.scripting.service.scripting.engines.GroovyEngine.eval(GroovyEngine.java:65)
	... 60 more
Caused by: javax.script.ScriptException: java.lang.NullPointerException
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:335)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:132)
	... 61 more
Caused by: java.lang.NullPointerException
	at org.xhtmlrenderer.swing.NaiveUserAgent.getBinaryResource(NaiveUserAgent.java:228)
	at org.xhtmlrenderer.pdf.ITextFontResolver.importFontFaces(ITextFontResolver.java:97)
	at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:178)
	at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)
	at org.xhtmlrenderer.pdf.ITextRenderer.setDocumentFromString(ITextRenderer.java:159)
	at net.datenwerke.rs.scriptreport.service.scriptreport.renderers.PdfRenderer.render(PdfRenderer.java:33)
	at net.datenwerke.rs.scriptreport.service.scriptreport.hooks.ScriptReportRenderer$render.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at Script5.run(Script5.groovy:225)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:332)

Apparently more people have had this issue as well, and as per the following forum, the solution was removing custom font?
http://stackoverflow.com/questions/2823 … rexception

is there any way we can set a default font so we dont need to create a css custom font?

Offline

#4 2015-06-24 06:36:24

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: pdf render and chinese characters issues

Hi Marcos,

I haven't really looked at this yet, but on a first glance it seems that the script cannot locate the font. Have you tried providing
a proper URL for the font, that is, exchange  src: url("UbuntuMono-R.ttf"); for a URL which actually points to the correct ttf file?

Cheers
-Arno

Offline

#5 2015-06-24 22:51:40

marcosfilho
Member
Registered: 2014-08-04

Re: pdf render and chinese characters issues

yeah I tried that.

I tried the full http url as well as the path to the font in the file system and it doesnt work sad

Offline

#6 2015-06-25 02:56:52

marcosfilho
Member
Registered: 2014-08-04

Re: pdf render and chinese characters issues

just checking the source and found that:

public class PdfRenderer implements ScriptReportRenderer {

	@Override
	public String getName() {
		return "pdf";
	}

	@Override
	public CompiledReport render(Object input)  {
		ITextRenderer renderer = new ITextRenderer();
		try {
			renderer.getFontResolver().addFont("org/dejavu/fonts/ttf/DejaVuSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
		} catch (DocumentException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		renderer.setDocumentFromString((String) input);

		ByteArrayOutputStream os = new ByteArrayOutputStream();
		renderer.layout();
		try {
			renderer.createPDF(os);
			os.close();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}

		byte[] cReport = os.toByteArray();

		return new CompiledPdfReport(cReport);
	}

}

just considering changing that font DejaVuSans.ttf by one that could render chinese words?

Offline

#7 2015-06-25 04:11:52

marcosfilho
Member
Registered: 2014-08-04

Re: pdf render and chinese characters issues

alright I managed to get something working:

not pretty but works:

import groovy.sql.Sql
import groovy.xml.*
import net.datenwerke.rs.base.service.reportengines.table.output.object.*
import java.util.Date;
import net.datenwerke.rs.core.service.datasourcemanager.entities.DatasourceDefinition;
import net.datenwerke.rs.core.service.datasourcemanager.DatasourceService;
import net.datenwerke.rs.base.service.datasources.definitions.DatabaseDatasource;
import net.datenwerke.dbpool.config.ConnectionPoolConfig;
import net.datenwerke.dbpool.DbPoolService;
import java.sql.Connection;
import java.util.concurrent.Future;
import java.text.SimpleDateFormat;
import net.datenwerke.rs.core.service.reportmanager.engine.basereports.CompiledHtmlReportImpl
import groovy.json.*
import org.apache.commons.lang.StringEscapeUtils

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import net.datenwerke.rs.core.service.reportmanager.engine.CompiledReport;
import net.datenwerke.rs.core.service.reportmanager.engine.basereports.CompiledPdfReport;
import net.datenwerke.rs.scriptreport.service.scriptreport.hooks.ScriptReportRenderer;

import org.xhtmlrenderer.pdf.ITextRenderer;

import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;


def report = """\
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
        <style type='text/css'> 
            * { font-family: 'Arial Unicode MS'; }
        </style>
    </head>
    <body>
        <span> Full name: 朱凡鲁 </span>
    </body>
</html>

""";



ITextRenderer renderer = new ITextRenderer();
//renderer.getFontResolver().addFont("org/dejavu/fonts/ttf/DejaVuSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.getFontResolver().addFont("fonts/ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
renderer.setDocumentFromString((String) report.toString());
ByteArrayOutputStream os = new ByteArrayOutputStream();
renderer.layout();
renderer.createPDF(os);
os.close();

byte[] cReport = os.toByteArray();

return new CompiledPdfReport(cReport);

Offline

#8 2015-06-25 06:09:33

Arno Mittelbach
datenwerke
Registered: 2012-02-14

Re: pdf render and chinese characters issues

Hi Marcos,

thanks for this tip. I've create a ticket to see how we can make this a bit easier.

Cheers
-Arno

Offline

Board footer

Powered by FluxBB