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.
Related
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">
I have an XFDF files contain some Annotations but not Fields, I would like to know is it able to import those Annotations into PDF file with PDFBox
I have tried to import the XFDF into PDF in Acrobat Reader DC and it's successful to show the imported annotations. However it is not success to show the annotations via used the function importFDF in PDAcroForm. It only import the fields but not annotations.
below is my sample XFDF
<?xml version="1.0" encoding="UTF-8" ?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields />
<annots>
<ink page="0" rect="414.755559,308.987191,564.755559,365.356617" color="#000000" flags="print" name="a74a6f8a-4149-d913-6ee6-34ba434bc254" title="annotationTest" subject="Signature" date="D:20190808175939+08'00'" creationdate="D:20190808175827+08'00'">
<inklist>
<gesture>415.23,342.9;415.23,342.9;417.62,345.77;422.4,349.11;441.98,357.24;456.79,361.53;470.17,364.88;471.12,364.88;471.6,362.97;468.74,355.8;464.44,346.25;456.79,333.35;440.07,314.72;432.91,310.9;429.56,309.46;429.09,309.46;427.65,312.81;427.65,316.15;429.09,319.02;432.91,322.36;445.81,324.27;454.41,323.8;463,320.45;472.56,317.11;488.32,315.2;499.31,315.68;505.52,318.06;509.82,320.45;514.12,322.36;514.6,322.36;515.55,322.36;517.94,322.36;526.06,322.36;530.36,322.36;535.14,322.36;539.44,322.36;541.83,322.36;542.78,322.36;543.26,322.36;544.69,322.36;546.6,322.84;548.51,322.84;549.47,322.84;550.42,323.8;552.34,325.23;553.29,325.71;554.25,326.66;554.72,327.14;556.63,328.1;559.98,329.05;564.28,330.48</gesture>
</inklist>
</ink>
<circle page="0" rect="464.76803,505.088095,546.727124,576.052676" color="#FF8D00" flags="print" name="96f7f067-0811-a87f-3d94-0b654a720d7d" title="annotationTest" subject="Ellipse" date="D:20190808175825+08'00'" width="6" creationdate="D:20190808175813+08'00'"/>
<polygon page="0" rect="184.107608,217.431165,445.578111,277.002438" color="#E44234" flags="print" name="8523798b-3d79-d612-40bb-bcdec2789dcd" title="annotationTest" subject="Polygon" date="D:20190808175810+08'00'" style="cloudy" interior-color="#92E8E8" width="9" opacity="0.58" creationdate="D:20190808175742+08'00'" intensity="2">
<vertices>191.9,269.21;438.78,270.21;433.78,225.23;191.9,224.23;190.9,224.23;191.9,269.21</vertices>
</polygon>
<freetext page="0" rect="376.81193,778.184946,500.283994,807.936941" flags="print" name="373b558a-4892-5fb4-a9aa-b4d7175d3966" title="annotationTest" subject="Free text" date="D:20190808175721+08'00'" width="0" creationdate="D:20190808175700+08'00'" TextColor="#00CC63" FontSize="17">
<contents>Some words...</contents>
<defaultappearance>0 0 0 rg /Arial 17 Tf</defaultappearance>
<defaultstyle>font: Arial 17pt; text-align: left; color: #00CC63</defaultstyle>
</freetext>
<square page="0" rect="196.901725,719.980841,436.781998,752.964378" color="#E44234" flags="print" name="31250d16-7ee0-c34e-027c-5e11e66cf2b1" title="annotationTest" subject="Rectangle" date="D:20190808175655+08'00'" interior-color="#FFC67B" opacity="0.23" creationdate="D:20190808175653+08'00'"/>
<link page="0" rect="36.507,555.18,136.6,581.705" color="#000000" flags="print" name="null" title="null" subject="null" date="D:20190808175651+08'00'" width="0" style="solid"/>
</annots>
<pages>
<defmtx matrix="1.3333333333333333,0,0,-1.3333333333333333,0,1122.559973" />
</pages>
</xfdf>
Or any other library recommended? Many thanks.
After loaded xfdf file, get the COSObject from FDAnnotation and then use it to create a PDAnnotation
PDAnnotation pdfannot = PDAnnotation.createAnnotation(fdfannot.getCOSObject());
And then add to page
List<PDAnnotation> pdfannots = new ArrayList<PDAnnotation>;
pdfannots.add(pdfannot);
page.setAnnotations(pdfannots);
Save it, and you will see the annotations on the PDF
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'm writing some code to parse GPX files. These are produced by a number of different sources, from route planning websites to satnav recordings.
I'm having trouble with JAXB. It seems that it won't load the file if it uses the default name space.
For example when I try to parse the following file only the root gpx element is loaded and the child meta is not loaded and java leaves the field blank.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<time>2015-01-24T18:13:23Z</time>
<bounds minlat="52.058110" minlon="-2.218540" maxlat="52.347110" maxlon="-1.943840" />
</metadata>
<!-- snip -->
</gpx>
However the following file loads just fine. The only difference being that the default namespace has been changed to a named one (ns1).
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ns1:gpx xmlns:ns1="http://www.topografix.com/GPX/1/1" version="1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<time>2015-01-24T18:13:23Z</time>
<bounds minlat="52.058110" minlon="-2.218540" maxlat="52.347110" maxlon="-1.943840" />
</metadata>
<!-- snip -->
</ns1:gpx>
My package-info.java is currently defined with:
/**
* Pojos Representing the GPX xml.
*/
#XmlSchema(
elementFormDefault = XmlNsForm.UNQUALIFIED,
namespace = "http://www.topografix.com/GPX/1/1",
location = "http://www.topografix.com/GPX/1/1/gpx.xsd",
xmlns= {
#XmlNs(namespaceURI = "http://www.topografix.com/GPX/1/1", prefix = "gpx"),
}
)
package couling.gpxTools.pojo;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;
Is this something anyone else has seen before and are there any suggestions of how to get round it?
In your second XML all the elements should have the ns1 prefix to be equivalent to the first XML document.
To load the first document you need to specify elementFormDefault=XmlNsForm.QUALIFIED on the #XmlSchema annotation. Then all mapped elements within this package will default to having this namespace. Since you specified UNQUALIFIED only top level elements get the namespace qualification.
I'm still newbie in SmartGWT, currently having a strange problem..
I am using Windows XP and SmartGWT version 3.0,
GWT SDK 2.4.0 (using Eclipse IDE).
So my problem is, I kind of copied examples from the SmartGWT showcase: Styled ComboBox
DynamicForm df = new DynamicForm();
ComboBoxItem cb = new ComboBoxItem();
cb.setValueMap("cat", "dog", "bird");
cb.setTitle("Select:");
df.setItems(cb);
...
layout.addMember(df);
And when I run it as Web Application, the valuemap doesn't appear.
I mean, the [v] button is there but nothing happens when i clicked it..
Sorry for the noob question, and thanks for your help! :D
UPDATE - 05/03/2012
Here is what appears on my browser:
screenshot removed
Here is the full standalone code:
HelloWorld.java
package com.example.helloworld.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
VLayout layout = new VLayout();
layout.setWidth100();
layout.setHeight100();
DynamicForm df = new DynamicForm();
ComboBoxItem cb = new ComboBoxItem();
cb.setTitle("Select :");
cb.setValueMap("Cat", "Dog", "Bird");
df.setItems(cb);
layout.addMember(df);
layout.draw();
}
}
HelloWorld.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='helloworld'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<inherits name="com.smartgwt.SmartGwt" />
<!-- Specify the app entry point class. -->
<entry-point class='com.example.helloworld.client.HelloWorld'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
On the 'Development Mode' tab in Eclipse (the one that shows you link to run on browser),
i get this message:
[INFO] [helloworld] - Your *.gwt.xml module configuration prohibits
the use of the current doucment rendering mode (document.compatMode='
CSS1Compat').Modify your application's host HTML page doctype, or
update your custom 'document.compatMode' configuration property
settings.
There is also a single warning:
The following classpath entry 'C:\some-path\smartgwt-3.0\smartgwt.jar'
will not be available on the server's classpath.
UPDATE 2 - HTML and CSS file
HTML:
<!doctype html>
<!-- The DOCTYPE declaration above will set the -->
<!-- browser's rendering engine into -->
<!-- "Standards Mode". Replacing this declaration -->
<!-- with a "Quirks Mode" doctype is not supported. -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<link type="text/css" rel="stylesheet" href="HelloWorld.css">
<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Web Application Starter Project</title>
<!-- -->
<!-- This script loads your compiled module. -->
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
<script type="text/javascript" language="javascript" src="helloworld/helloworld.nocache.js"></script>
</head>
<!-- -->
<!-- The body can have arbitrary html, or -->
<!-- you can leave the body empty if you want -->
<!-- to create a completely dynamic UI. -->
<!-- -->
<body>
<!-- OPTIONAL: include this if you want history support -->
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
<!-- RECOMMENDED if your web app will not function without JavaScript enabled -->
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
</body>
</html>
and the CSS file:
/** Add css rules here for your application. */
/** Example rules used by the template application (remove for your app) */
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
.sendButton {
display: block;
font-size: 16pt;
}
/** Most GWT widgets already have a style name defined */
.gwt-DialogBox {
width: 400px;
}
.dialogVPanel {
margin: 5px;
}
.serverResponseLabelError {
color: red;
}
/** Set ids using widget.getElement().setId("idOfElement") */
#closeButton {
margin: 15px 6px 6px;
}
IMPORTANT UPDATE
I forgot to inform you that I am currently using Google Chrome(18.0.1025.168) for debug / test build. When I ran it on Firefox, it runs OK!
I noticed this thread a bit late.. So this is currently a known bug.
conclusion: do NOT use google chrome for GWT / smartGWT development mode (for now).
Thank you for your help! :D
I forgot to inform you that I am currently using Google Chrome(18.0.1025.168) for debug / test build. When I ran it on Firefox, it runs OK!
I noticed this thread (smartclient forum) a bit late.. So this is currently a known bug.
conclusion: do NOT use google chrome for GWT / smartGWT development mode (for now).
Thank you for your help! :D
ComboBox is not SmartGWT. Where is it coming from ?
This code works as expected :
DynamicForm df = new DynamicForm();
ComboBoxItem cb = new ComboBoxItem();
cb.setValueMap("cat", "dog", "bird");
cb.setTitle("Select");
df.setItems(cb);
HLayout layout = new HLayout();
layout.addMember(df);
layout.draw();
DynamicForm df = new DynamicForm();
ComboBox cb = new ComboBox();
cb.setValueMap("cat", "dog", "bird");
cb.setTitle("Select:");
//other fields
df.setFields(cb); // Use this to add fields
layout.addMember(df);
Have a look At Show Case
Try this..
DynamicForm df = new DynamicForm();
ComboBox cb = new ComboBox();
Map<String,String> valuesMap = new HashMap<String,String>();
valuesMap.put("cat","cat");
valuesMap.put("dog","dog");
valuesMap.put("bird","bird");
cb.setValueMap(valuesMap);
cb.setTitle("Select:");
df.setItems(cb);
...
layout.addMember(df);
If you are in debug mode you never will see the content of this selectItem or comboBox, but if you select down with the keyboard you will see the content. You should be in "production" mode for see everything correctly
Is a problem with chrome, if you work with firefox you will see the content