Apache FOP and Arial font - java

My XSL style uses Arial font
<fo:block font-family="Arial" font-size="8pt" font-weight="normal">
Configuration file fonts.xml:
<?xml version="1.0"?>
<fop>
<renderers>
<renderer mime="application/pdf">
<fonts>
<base>file:///C:/windows/fonts</base>
</fonts>
</renderer>
</renderers>
</fop>
also tried using this:
<auto-detect/>
and
<directory>C:\windows\fonts</directory>
I am always getting:
WARNING: Font "Arial,normal,400" not found. Substituting with "any,normal,400".
What should I fix in order to use Arial font?

This worked for me, need to specify the Arial font explicitly in configuration file:
<?xml version="1.0"?>
<fop>
<renderers>
<renderer mime="application/pdf">
<fonts>
<font kerning="yes" embed-url="file:///C:/windows/fonts/arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>

Related

IntelliJ Idea Not showing GUI

For some reason my GUI is no longer showing up on the .form file, instead it is all the hard code for it like:
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="emroGUI">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="11" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="742" height="400"/>
</constraints>
<properties/>
<border type="none"/>
etc.
When I originally made the GUI I did it via 'drag and drop' and I saw the actual GUI form. How do I get the actual form back?
your XML content malformed now and I think you are missing following ending tags:
</grid> </form>
accurate structure is as following:
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="emroGUI">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="11" column-count="7" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="742" height="400"/>
</constraints>
<properties/>
<border type="none"/>
</grid>
</form>

Reflecting img.Xml into Java Objects Using JAXB

So I'm transitioning over from C# in Unity, where reflection in XML was quite easy. I wanted to apply the same process in Java to this to a slightly varied version of already existing XML of this type of format:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<imgdir name="0206.img">
<imgdir name="02060003">
<imgdir name="info">
<canvas name="icon" width="32" height="32">
<vector name="origin" x="0" y="32" />
</canvas>
<canvas name="iconRaw" width="32" height="31">
<vector name="origin" x="0" y="32" />
</canvas>
<int name="price" value="20" />
<int name="slotMax" value="1000" />
<int name="incPAD" value="4" />
</imgdir>
<imgdir name="bullet">
<canvas name="0" width="43" height="18">
<vector name="origin" x="23" y="10" />
<int name="z" value="0" />
</canvas>
<canvas name="1" width="41" height="9">
<vector name="origin" x="22" y="5" />
<int name="z" value="0" />
</canvas>
</imgdir>
</imgdir>
<imgdir name="02060005">
<imgdir name="info">
<canvas name="icon" width="26" height="25">
<vector name="origin" x="-3" y="25" />
<int name="z" value="0" />
</canvas>
<canvas name="iconRaw" width="20" height="18">
<vector name="origin" x="-6" y="25" />
<int name="z" value="0" />
</canvas>
<int name="slotMax" value="800" />
<int name="incPAD" value="10" />
<int name="reqLevel" value="10" />
<int name="tradeBlock" value="1" />
</imgdir>
<imgdir name="bullet">
<canvas name="0" width="36" height="19">
<vector name="origin" x="22" y="9" />
<int name="delay" value="150" />
</canvas>
<canvas name="1" width="40" height="22">
<vector name="origin" x="20" y="11" />
<int name="delay" value="150" />
</canvas>
<canvas name="2" width="43" height="21">
<vector name="origin" x="21" y="10" />
<int name="delay" value="150" />
</canvas>
<canvas name="3" width="46" height="23">
<vector name="origin" x="20" y="11" />
<int name="delay" value="150" />
</canvas>
</imgdir>
<imgdir name="hit">
<canvas name="0" width="55" height="38">
<vector name="origin" x="13" y="20" />
<int name="delay" value="90" />
</canvas>
<canvas name="1" width="43" height="55">
<vector name="origin" x="17" y="29" />
<int name="delay" value="100" />
</canvas>
<canvas name="2" width="51" height="65">
<vector name="origin" x="26" y="34" />
<int name="delay" value="100" />
</canvas>
<canvas name="3" width="62" height="87">
<vector name="origin" x="34" y="57" />
<int name="delay" value="100" />
</canvas>
</imgdir>
</imgdir>
The catch is that there are many of these XML files, and each one has different header names, such as 0206.img, 0207.img. Each one has a very similar structure to the previous one in that header category (leading digit determines what type of object it is unmarshaling).
I really only want to reflect properties such as price, slotMax, incPad, and ignore the rest if possible. I'm not sure how to go about this, since in all the unmarshal examples the XML is much simpler, such as
<Employees>
<Employee>
<id>1</id>
</Employee>
<Employee>
<id>2</id>
</Employee>
</Employees>
Where you'd probably define a class like Employees which contains List, and Employee can be unmarshalled into. To clarify, I know you have to set the RootElement to the name of the top element, such as in this case 0206.img, but how can this be dynamic for 0207?
As for code ... I mean the code base is pretty simple since it's just defining the structure for which to unmarshal into. Defining this structure in respect to the above XML I linked is harder for me atm.
If you're only interested in a few easy-to-detect elements, and not in the whole structure, JAXB may be a wrong tool. JAXB is good for the cases where you have an XML Schema, interested in (more or less) complete structure, unmarshalling as well as marshalling.
If you only need a few parts of XML there are easier ways to do this. In this particular case I would probably use STAX. Something along the lines:
private static final QName INT_ELEMENT_NAME = new QName("int");
// ...
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader reader = factory.createXMLStreamReader(is);
while (reader.hasNext()) {
if (XMLStreamConstants.START_ELEMENT == reader.next()) {
if (Objects.equals(INT_ELEMENT_NAME, reader.getName())) {
String name = reader.getAttributeValue(null, "name");
String value = reader.getAttributeValue(null, "value");
System.out.println(name + "=" + value);
}
}
}
Prints name/value paits from all the int elements. Can be easily extended to further cases. Very fast, does not have the JAXB overhead, would easily work with big XML files, no matter how huge.
There are other tools as well. There was one parser (I could not recall the name) where you define XPath-based rules and the parser returns data according to these rules. That would also be suitable, but I just don't recall the name. I think it was some Apache project.
Update: I've finally found it, I was talking about Digester. It allows configuring XPath-like binding rules and the creates objects for you. Still, I'd probably stay with the STAX solution unless you're sure you'll get more and more complex rules.

How are images handled in Microsoft Word

I am trying to embed images in xml document and save the document as a single document and be able to distribute the file just like microsoft word where both the text and images are saved in single docx file.
How is it done in Microsoft word. Do they use base64 encoding ?
It is quite hard to do it by hand and would look something like that:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:r>
<w:drawing>
<wp:inline distT="0" distB="0" distL="0" distR="0">
<wp:extent cx="5943600" cy="3717290"/>
<wp:docPr id="1" name="Picture 0" descr="vlcsnap-325726.png"/>
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:nvPicPr>
<pic:cNvPr id="0" name="myImage.png"/>
<pic:cNvPicPr/>
</pic:nvPicPr>
<pic:blipFill>
<a:blip r:embed="rId4"/>
<a:stretch>
<a:fillRect/>
</a:stretch>
</pic:blipFill>
<pic:spPr>
<a:xfrm>
<a:off x="0" y="0"/>
<a:ext cx="5943600" cy="3717290"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
</pic:spPr>
</pic:pic>
</a:graphicData>
</a:graphic>
</wp:inline>
</w:drawing>
</w:r>
</w:p>
</w:body>
</w:document>
You don't want to do it that way. I would recommend to use an external library like OpenXML SDK 2.0 (by Microsoft) or OpenXML4J (especially for Java). They will make your life way easier

Embedded font don't work in Apache FOP

I am using FOP to tranform xml to pdf, and I need to use Chinese characters.I did do something to use Chinese font,but it seems don't work at all.
I create the font xml file.
and registered in the fop.xconf
<font metrics-url="/home/zhufree/Tools/fop-2.1/conf/simkai.xml" kerning="yes" embed-url="/home/zhufree/Tools/fop-2.1/conf/kaiti.ttf">
<font-triplet name="simkai" style="normal" weight="normal" />
<font-triplet name="simkai" style="normal" weight="bold" />
<font-triplet name="simkai" style="italic" weight="normal" />
<font-triplet name="simkai" style="italic" weight="bold" />
</font>
the font xml file and font ttf file are in the same directory with fop.xconf,when I try to transform,it still show me cant find the font.
What should I do to show the Chinese character?
Update:
I solved the problem by using specific configuration file in java code, and it worked well.Thanks.

I can't change my Font Family using Apache FOP

I am trying to use fop Quick Start Guide to print a simple PDF file from a simple XML file and it works fine. but when I change <name>Frank</name> to <name>امیررضا</name> (change name to other encoding) I get #### in my printed PDF. I search through the Internet and couldn't find any feasible solution. I use many config files here are some of my them:
I use this command for creating pdf:
fop -c cfg.xml -xml name.xml -xsl name2fo.xsl -pdf name.pdf
When I use this command I get below warning:
WARNING: xHeight value could not be determined. The font may not work as
Sep 15, 2011 9:15:37 AM org.apache.fop.events.LoggingEventListener proce
WARNING: Glyph "╙" (0x633, afii57427) not available in font "Helvetica".
Sep 15, 2011 9:15:37 AM org.apache.fop.events.LoggingEventListener proce
WARNING: Glyph "╘" (0x634, afii57428) not available in font "Helvetica".
1- name.xml contains:
<name>امیررضا</name>
2-name2fo.xsl contains:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body">
<fo:block>
Hello, <xsl:value-of select="name"/>!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
3- have try many different config file (cfg.xml).
3.1:
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<substitutions>
<substitution>
<from font-family="Helvetica" />
<to font-family="SansSerif"/>
</substitution>
</substitutions>
<referenced-fonts>
<match font-family=".*"/>
</referenced-fonts>
<!-- register all the fonts found in a directory and all of its sub directories (use with care) -->
<directory recursive="true">G:\....\fop\fop-1.0\Core14_AFMs</directory>
<!-- automatically detect operating system installed fonts -->
<auto-detect/>
<font embed-url="C:\WINDOWS\Fonts\times.ttf">
<font-triplet name="Times New Roman" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
3.2:
<fop version="1.0">
<renderers>
<renderer mime="application/pdf">
<fonts>
<substitutions>
<substitution>
<from font-family="Helvetica" />
<to font-family="SansSerif"/>
</substitution>
</substitutions>
<referenced-fonts>
<match font-family=".*"/>
</referenced-fonts>
<!-- automatically detect operating system installed fonts -->
<auto-detect/>
</fonts>
</renderer>
</renderers>
</fop>
3.3: ......
The result output is:
Hello, #######!
Can anyone help me fix this?
Support for languages written with right-to-left scripts such as Arabic & Hebrew and full bidi support was added in Apache FOP 1.1. Based on the date of this question, an older Apache FOP version was used. For more information, see http://xmlgraphics.apache.org/fop/trunk/complexscripts.html.
I have never used Apache FOP but I found this article that allows you to create multiple language PDF.
Creating Multiple Language PDFs using Apache FOP
I would recommend that you use HelveticaWorld thatcontains arabic characters too or if you create the FOP input dynamically, then you can use Velocity or Freemarker variables to store the Font name.
I solve the problem by add font-family in XSL code:
name2fo.xsl after changes contains:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-portrait"
page-height="29.7cm" page-width="21.0cm" margin="2cm">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-portrait">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="10pt" font-family="Tahoma">
Hello, <xsl:value-of select="name"/>!
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>
But I still have problem which is my Farsi character printed in reverse order. I mean if I want to print "Hello" it was printed "oellH" (you can imagine Hello is written in Farsi character) and also have a second problem that is the character was printed separated.

Categories