I am trying to generate PDF from xml using apache Fop,
It works fine with english but while i try to disply arabic text the characters are separated as shown in the Image
1- I tried with 2.1, 2.5 and latest stable apache Fop version 2.6
2- I embded the font in Fop config file
3- I enabled complex-scripts
4- I tried with different fonts
but it didn't solve the issue
I attached Apache Fop configuration file below
<fop version="1.0">
<complex-scripts disabled="false" />
<renderers lang="ar">
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="src/main/resources/fonts/trado.ttf" embedding-mode="auto" encoding="UTF-8">
<font-triplet name="trado-ar-font" style="normal" weight="normal" />
</font>
</fonts>
</renderer>
</renderers>
</fop>
I also checked:
XSL-FO: displaying Arabic characters and
FOP Arabic letter spacing
but there is nothing worked with me
appriciate any support please
refrence to https://xmlgraphics.apache.org/fop/2.0/complexscripts.html
It was solved by adding script="arab" to the root tag like:
<fo:root script="arab">
Related
I have the following fop.conf, which works fine under Windows:
<?xml version="1.0" encoding="utf-8" ?>
<fop>
<renderers>
<renderer mime="application/pdf">
<fonts>
<fonts><font kerning="yes" embed-url="/Windows/Fonts/arial.ttf" embedding-mode="subset">
<font-triplet name="arial" style="normal" weight="400"/></font>
</fonts>
</renderer>
</renderers>
</fop>
But because the Application also needs to run on OS's which do not have Arial provided, I decided to add a the font to src/main/resources/fonts/Arial.ttf in the Java application.
So I'm trying to reference the font like this:
<?xml version="1.0" encoding="utf-8" ?>
<fop>
<renderers>
<renderer mime="application/pdf">
<fonts>
<directory>file:src/main/resources/fonts/</directory>
</fonts>
</renderer>
</renderers>
</fop>
But it does not use the font.
While debugging I saw the fopFactoryBuilder has a field called baseUri, is it possible to add this to the fop.conf and extend it to get the path to the Arial font?
I don't have the fopFactoryBuilder.setFontBaseURL() because I need to use an older version which does not provide it.
What is the best way to provide the relative path inside the fop.conf?
This did the trick:
<?xml version="1.0" encoding="utf-8" ?>
<fop>
<base>.</base>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="app/src/main/resources/fonts/Arial.ttf" embedding-mode="subset">
<font-triplet name="Arial" style="normal" weight="400"/></font>
<autodetect/>
</fonts>
</renderer>
</renderers>
</fop>
While using Apache FOP 2.2 from my Java application to print Hindi strings in PDF by using mangal.ttf, some Hindi characters are not displayed correctly.
I am Using JDK 1.8 and spring MVC.
I tried lohit.ttf, devanagari.ttf, aparajita.ttf and kokila.ttf but all have the same issue.
case 1:
When fop-conf.xml is set as below:
<font kerning="yes" embed-url="classpath:/mangal.ttf" >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>
Result: से is shown like this स े, as shown in this screenshot
case 2:
When fop-conf.xml is set as below:
<font kerning="yes" metrics-url="classpath:/mangal.xml" embed-url="classpath:/mangal.ttf" >
<font-triplet name="Mangal" style="normal" weight="normal"></font-triplet>
</font>
Result: problem listed in case 1 is resolved but I am facing another issue attached as shown in the following screenshot
You can see the expected output at the link https://www.fonts.com/font/microsoft-corporation/aparajita) using this sample text:
से and ग्रामीण should be printed in pdf
Other things I tried:
I tried PDFOne to generate the PDF. Yet the same issue. Windows however seems to show it correctly.
configuring complex-script: <fop version="1.0"> <complex-scripts disabled="true"/> ... </fop>
using the script attribute: <fo:block font-family="ARIALUNI" script="dev2" > देवी ग्रामीण</fo:block>
Is there any configuration setting in FOP that I am missing?
Shorter, general answer:
If the font is configured but the output is not correct, the problem could be FOP incorrectly determining which script mode to use.
Solution: explicitly set the script property in the FO file, using either a standard or an extended script code.
Note that Indic scripts have both a standard code and an extended one (for example deva and dev2 for Devanagari) and the resulting output is different, so you may need to try them both and choose the appropriate one.
Longer answer:
I don't have the fonts you mention available, so I tested using the Amiko Google Open Font.
More importantly, I know nothing about devanagari script, so I really cannot say whether the output is right or wrong, I can only compare it with your images.
This is the complete input file I used, with the sentence copied from your question:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simpleA4">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="Amiko" script="deva">deva: से and ग्रामीण should be printed in pdf</fo:block>
<fo:block font-family="Amiko" script="dev2">dev2: से and ग्रामीण should be printed in pdf</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Here is a minimal configuration:
<?xml version="1.0"?>
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
<font-triplet name="Amiko" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
which produces this output:
If I understand correctly, the output you are trying to achieve is the one with script="deva".
Note that the metrics-url attribute in your configuration is not needed.
Moreover, putting <complex-scripts disabled="true"/> in your configuration has the effect of disabling the "complex script" support, so I expect this to produce the wrong output.
This configuration
<?xml version="1.0"?>
<fop version="1.0">
<complex-scripts disabled="true"/>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="Amiko/Amiko-Regular.ttf">
<font-triplet name="Amiko" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
produces the following output:
This might help others who are struggling to get Indic language support in Apache FOP. I tried to render Hindi with Amiko font and it works like a charm.
I wanted to see if other Indian languages are supported in the same way, after a bit of struggle I could see Kannada can also be rendered .
<font kerning="yes" embed-url="Benne-Regular.ttf">
<font-triplet name="Benne" style="normal" weight="normal"/>
</font>
But its mandatory to mention the script in the XSL .
<fo:block font-family="Benne" script="knda" font-size="16pt"> ಕನ್ನಡ
ನನಗೆ ಇನ್ನೂ ಒಂದು ಪ್ರಶ್ನೆ ಇದೆ.</fo:block>
I have an issue configuring Batik PDFTranscoder for Svg to Pdf conversion.
I want to embed custom truetype fonts to PDF output, therefore I utilize Batik transcoder. I supply font configuration in fop config file, as described here: https://xmlgraphics.apache.org/fop/2.2/fonts.html
I tried conversion with org.apache.xmlgraphics.Fop versions 2.1 and 2.2. Without any success.
My pdf output, comes with 'Times New Roman' font instead of coming with embedded font 'Arial', as it should, based on example below:
My config file:
<?xml version="1.0" encoding="UTF-8"?>
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<directory>C:/path/to/fontsfolder</directory>
<auto-detect/>
</fonts>
</renderer>
</renderers>
</fop>
Here's my transcoder code:
import org.apache.batik.transcoder.*;
import org.apache.fop.svg.PDFTranscoder;
import org.w3c.dom.Document;
PDFTranscoder transcoder = new PDFTranscoder();
try {
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.buildFromFile(new File("path-to-xml-config-file"));
ContainerUtil.configure(transcoder, cfg);
} catch (Exception e) {
throw new TranscoderException(e);
}
transcoder.transcode(new TranscoderInput(doc),
new TranscoderOutput(os));
Sample svg file:
<defs>
<style type="text/css">
#font-face{font-family:'Arial';font-style: normal;font-weight:
400;src:url('C:/path/to/fontsfolder/arial.ttf')
format('truetype');}
</style>
</defs>
<text x="55" y="245" style="font-family: 'Arial'; font-weight:normal;
font-style: normal" >Sample text</text>
Can anyone tell me what I am missing here with Transcoder configuration? Embedding svg fonts into svg file is not an option in this case.
Update the config file and move fonts section outside the renderers section, like this:
My config file:
<?xml version="1.0" encoding="UTF-8"?>
<fop version="1.0">
<fonts>
<directory>C:/path/to/fontsfolder</directory>
<auto-detect/>
</fonts>
</fop>
Bulk font configuration from Apache website is simply wrong:
https://xmlgraphics.apache.org/fop/2.2/fonts.html
This answer was posted as an edit to the question Configure Batik to utilize custom fonts by the OP odoko under CC BY-SA 3.0.
I have an issue with Cyrillic font in Apache FOP 1.1 on CentOS: ######## is shown instead of symbols.
This is fragment from fop.xconf:
<fonts>
<font-triplet name="Arial" style="normal" weight="bold"/>
<auto-detect/>
</fonts>
On Windows 10 it works fine, on CentOS it produces ######.
Can anybody help me?
The font-triplet element should be inside a font element pointing to the font file, for example:
<font kerning="yes" embed-url="/usr/share/fonts/Arial.ttf" embedding-mode="subset">
<font-triplet name="Arial" style="normal" weight="bold"/>
</font>
Moreover, it seems like FOP cannot find a font folder in the "usual" positions; you can try explicitly adding a font folder
<directory>/usr/share/fonts/</directory>
The specific error message(s) you get could help pinpointing the specific problem.
I am defining a tagx file called "version.tagx". The responsibility of this tag is to emit an anchor tag whose display text is the version number of the application. Currently, the definition of the file looks like this:
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:spring="http://www.springframework.org/tags" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:output omit-xml-declaration="yes" />
<jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
<c:if test="${empty render or render}">
<spring:message code="global_version" />
<spring:url var="changelog" value="/resources/changelog.txt" />
<c:out value=": " />
${application_version}
</c:if>
</jsp:root>
My application is a Spring MVC application running in a Tomcat 7x container. I have the following line in my applicationContext.xml
<context:property-placeholder location="classpath*:META-INF/spring/*_${spring.profiles.active}.properties,classpath:app-info.properties"/>
I have confirmed through following the DEBUG log message the app-info.properties file is discovered by Spring and (presumably) the property values within that file have been loaded into my runtime.
Here is the log message
2012-05-09 23:45:24,237 [main] INFO org.springframework.context.support.PropertySourcesPlaceholderConfigurer - Loading properties file from class path resource [app-info.properties]
2012-05-09 23:45:24,237 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence
And here are the contents of my app-info.properties file:
application_version=1.0
application_buildTime=05-04-2012 00:00:00
application_builtBy=me
application_buildNumber=55
What I want is for my tagx to emit
Version: 1.0
And currently what I get is:
Version:
Does anyone know of a way to accomplish this? Should I be trying a completely different approach that forgoes properties files all togher?
In webmvc-config.xml add util:properties where /WEB-INF/spring/application.properties is the path to the properties file:
<util:properties id="applicationProps" location="/WEB-INF/spring/application.properties"/>
Then, simply add this before your anchor tag:
<spring:eval expression="#applicationProps['application_builtBy']" var="application_builtBy"/>
<spring:eval expression="#applicationProps['application_buildTime']" var="application_buildTime"/>
<spring:eval expression="#applicationProps['application_version']" var="application_version"/>
Hope it helps.
What you can also do that doesn't tie you to looking up properties in a single property placeholder, or if you are using java config and just instantiating a PropertySourcesPlaceholderConfigurer is use the environment object:
<spring:eval expression="#environment.getProperty('application_builtBy')" />