You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Andrew Stevens <at...@hotmail.com> on 2007/03/05 15:57:25 UTC

Font problem using SVG text in PDFs

Can anyone help with this, or point me to a better place to ask?

I'm generating some PDFs using the FOP block in Cocoon 2.1.7.  These include 
a company logo, which is done using an SVG file that is copied into a 
fo:instream-foreign-object node by the XSL (the SVG file is passed into the 
XSL as a map:aggregate part).  The graphical part of the logo is fine, but 
I'm having a few problems getting the text part to display properly.

The text is in Times, which should be available in any viewer as it's one of 
the base 14 fonts mandated by the PDF spec.  The relevant SVG is
<svg:text xml:space="preserve" 
style="font-size:22px;font-style:normal;font-weight:normal;fill:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Times,serif;" 
x="0.79575568" y="18.302387" id="text1871">OURNAMEHERE</svg:text>
Running on a Windows-based server this displays fine, the logo text appears 
in Times as expected.  However, when deployed to our Solaris-based servers 
(which will be the production environment) the logo text appears in a 
sans-serif font - I assume this is Courier, which appears to be the default 
font according to the Batik docs.  I've tried many variations and 
combinations of the font-family value, Times/TimesNewRoman/Times New 
Roman/serif, on the svg:text node and/or a nested tspan element (where 
Inkscape originally had it), but all to no avail.

The FOP documentation states "If possible, Batik will use normal PDF text 
when inserting text. It does this by checking if the text can be drawn 
normally and the font is supported." But it doesn't really say just what 
"supported" means; I would have hoped that the base 14 fonts were always
supported, but it appears this isn't the case.  We're using the JPA library 
on the Solaris boxes as they're headless and don't have X windows installed, 
and 
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames() 
only returns a handful of fonts (various Lucida variants and a few generic 
default ones like "Serif"); on the Windows box this also has the various 
standard Windows fonts, in particular including "Times New Roman".  So I 
tried embedding the Windows server's times.ttf font in the PDF, according to 
the instructions in the FOP documentation, but even that makes no 
difference.

Before I start trying to convert Times to an SVG font, or the text to a 
series of paths, I thought I'd ask whether anyone else here has had similar 
problems, and how they got around them?  Or would I be better off asking on 
the FOP and/or Batik lists?


Andrew.
--
http://pseudoq.sourceforge.net/  Open source java Sudoku application

_________________________________________________________________
Find a local pizza place, movie theater, and moreĀ….then map the best route! 
http://maps.live.com/?icid=hmtag1&FORM=MGAC01


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Font problem using SVG text in PDFs

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 3/5/07, Andrew Stevens <at...@hotmail.com> wrote:
> ...Or would I be better off asking on
> the FOP and/or Batik lists?..

As this looks like a FOP-specific problem, it might be better to ask there.

-Bertrand

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Font problem using SVG text in PDFs

Posted by Jasha Joachimsthal <j....@hippo.nl>.
> > > -----Original Message-----
> > > From: Andrew Stevens [mailto:ats37@hotmail.com]
> > > Sent: maandag 5 maart 2007 15:57
> > > To: users@cocoon.apache.org
> > > Subject: Font problem using SVG text in PDFs
> > >
> [snip]
> > > particular including "Times New Roman".  So I tried embedding the 
> > > Windows server's times.ttf font in the PDF, according to the 
> > > instructions in the FOP documentation, but even that makes no 
> > > difference.
> 
> Sorry, Jasha, BTDTGTTS :-)  
Had to look that up, which size ;)

I even tried embedding the font 
> with an alternative name "MyTimes", but that didn't work 
> either (although it's a bit hard to tell if it's actually 
> been embedded, as so long the metrics-file and embed-file 
> attributes include a file: prefix there's no error message 
> written to the sitemap.log even when I specify a bogus filename).

Do you see the Times in the text content if you set it? I mean is it
just the SVG that renders with the wrong font or the whole PDF?

Jasha Joachimsthal

Hippo
Oosteinde 11
1017 WT Amsterdam
The Netherlands
+31 (0)20 5224466 

www.hippo.nl

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Font problem using SVG text in PDFs

Posted by Andrew Stevens <at...@hotmail.com>.
>From: "Jasha Joachimsthal" <j....@hippo.nl>
>Date: Mon, 5 Mar 2007 16:37:10 +0100
>
>Hi Andrew,
>
>It's a bit a PITA but you can add fonts to your PDF. I hope it works for
>your SVG too. The info below came from
>http://xmlgraphics.apache.org/fop/0.20.5/fonts.html and
>http://cocoon.apache.org/2.1/userdocs/pdf-serializer.html
>
[snip]
>
>Cocoon is now ready to embed fonts into the PDF.
>
>Regards,
>
>Jasha Joachimsthal
>
>Hippo
>Oosteinde 11
>1017 WT Amsterdam
>The Netherlands
>+31 (0)20 5224466
>
>www.hippo.nl
>
> > -----Original Message-----
> > From: Andrew Stevens [mailto:ats37@hotmail.com]
> > Sent: maandag 5 maart 2007 15:57
> > To: users@cocoon.apache.org
> > Subject: Font problem using SVG text in PDFs
> >
[snip]
> > particular including "Times New Roman".  So I tried embedding
> > the Windows server's times.ttf font in the PDF, according to
> > the instructions in the FOP documentation, but even that
> > makes no difference.

Sorry, Jasha, BTDTGTTS :-)  I even tried embedding the font with an 
alternative name "MyTimes", but that didn't work either (although it's a bit 
hard to tell if it's actually been embedded, as so long the metrics-file and 
embed-file attributes include a file: prefix there's no error message 
written to the sitemap.log even when I specify a bogus filename).

I also noticed a reference to the strokeSVGText setting in the docs and 
tried setting that to false, but that just makes it produce the error 
message
org.apache.batik.gvt.text.GVTAttributedCharacterIterator$TextAttribute: 
field STROKE not found
in System.err whether the font is embedded or not; this was on the NT server 
that does have Times available.


Andrew.
--
http://pseudoq.sourceforge.net/  Open source java Sudoku application

_________________________________________________________________
Mortgage rates as low as 4.625% - Refinance $150,000 loan for $579 a month. 
Intro*Terms  
https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h27f6&disc=y&vers=743&s=4056&p=5117


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Font problem using SVG text in PDFs

Posted by Jasha Joachimsthal <j....@hippo.nl>.
Hi Andrew,

It's a bit a PITA but you can add fonts to your PDF. I hope it works for
your SVG too. The info below came from
http://xmlgraphics.apache.org/fop/0.20.5/fonts.html and
http://cocoon.apache.org/2.1/userdocs/pdf-serializer.html 

 

If you want to use a specific fonts:

    * the font has to be present on the file system of the server;
    * all used variants (normal, bold, italic, bolditalic) are available
as seperate font. They cannot be simulated like in a text editor!

As an example Arial is used (sorry, bit lazy with copy-paste).

First you have to extract the fonts to xml files. You have to repeat
this for every variant. To do this, you need the jars of fop,
xercexImpl, and xml-apis that come with Cocoon (below the standard
Cocoon 2.1.8 is used).

C:\projects\COCOON_2_1_8\lib>java -cp
optional\fop-0.20.5.jar;endorsed\xercesImpl-2.7.1.jar;endorsed\xml-apis-
1.3.02.jar
 org.apache.fop.fonts.apps.TTFReader c:\windows\fonts\arial.ttf
c:\hippo\fop-fonts\arial.ttf.xml TTF Reader v1.1.1

Repeat this for arialbd (bold), arialbi (bolditalics) and ariali
(italics) and be sure to change the destination xml filename. Create a
folder named fop-fonts and move the font xml files into that folder.
Then create a file called fop-fonts.xml with these contents. Note the
difference between the uri's in metrics-file and embed-file.

<configuration>
  <fonts>
    <font metrics-file="file:///C:/fop-fonts/arial.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIAL.TTF">
      <font-triplet name="Arial" style="normal" weight="normal"/>
    </font>
    <font metrics-file="file:///C:/fop-fonts/ariali.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIALI.TTF">
      <font-triplet name="Arial" style="italic" weight="normal"/>
    </font>
    <font metrics-file="file:///C:/fop-fonts/arialbd.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIALBD.TTF">
      <font-triplet name="Arial" style="normal" weight="bold"/>
    </font>
    <font metrics-file="file:///C:/fop-fonts/arialbi.ttf.xml" 
      kerning="yes" embed-file="C:\WINDOWS\Fonts\ARIALBI.TTF">
      <font-triplet name="Arial" style="italic" weight="bold"/>
    </font>
  </fonts>
</configuration>

The last step is to reference to this file from Cocoon.

<map:serializer name="fo2pdf"
       src="org.apache.cocoon.serialization.FOPSerializer"
       mime-type="application/pdf"
       logger="sitemap.serialization.FOPSerializer">
    <user-config>cocoon:/fop/fop-fonts.xml</user-config>
  </map:serializer>

Although the location of the config file can be referenced using the
cocoon protocol, its contents must contain absolute paths on the
filesystem.

Cocoon is now ready to embed fonts into the PDF.

Regards,

Jasha Joachimsthal

Hippo
Oosteinde 11
1017 WT Amsterdam
The Netherlands
+31 (0)20 5224466 

www.hippo.nl 

> -----Original Message-----
> From: Andrew Stevens [mailto:ats37@hotmail.com] 
> Sent: maandag 5 maart 2007 15:57
> To: users@cocoon.apache.org
> Subject: Font problem using SVG text in PDFs
> 
> Can anyone help with this, or point me to a better place to ask?
> 
> I'm generating some PDFs using the FOP block in Cocoon 2.1.7. 
>  These include a company logo, which is done using an SVG 
> file that is copied into a fo:instream-foreign-object node by 
> the XSL (the SVG file is passed into the XSL as a 
> map:aggregate part).  The graphical part of the logo is fine, 
> but I'm having a few problems getting the text part to 
> display properly.
> 
> The text is in Times, which should be available in any viewer 
> as it's one of the base 14 fonts mandated by the PDF spec.  
> The relevant SVG is <svg:text xml:space="preserve" 
> style="font-size:22px;font-style:normal;font-weight:normal;fil
> l:black;fill-opacity:1;stroke:none;stroke-width:1px;stroke-lin
> ecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:T
> imes,serif;" 
> x="0.79575568" y="18.302387" id="text1871">OURNAMEHERE</svg:text>
> Running on a Windows-based server this displays fine, the 
> logo text appears in Times as expected.  However, when 
> deployed to our Solaris-based servers (which will be the 
> production environment) the logo text appears in a sans-serif 
> font - I assume this is Courier, which appears to be the 
> default font according to the Batik docs.  I've tried many 
> variations and combinations of the font-family value, 
> Times/TimesNewRoman/Times New Roman/serif, on the svg:text 
> node and/or a nested tspan element (where Inkscape originally 
> had it), but all to no avail.
> 
> The FOP documentation states "If possible, Batik will use 
> normal PDF text when inserting text. It does this by checking 
> if the text can be drawn normally and the font is supported." 
> But it doesn't really say just what "supported" means; I 
> would have hoped that the base 14 fonts were always 
> supported, but it appears this isn't the case.  We're using 
> the JPA library on the Solaris boxes as they're headless and 
> don't have X windows installed, and
> java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().get
> AvailableFontFamilyNames()
> only returns a handful of fonts (various Lucida variants and 
> a few generic default ones like "Serif"); on the Windows box 
> this also has the various standard Windows fonts, in 
> particular including "Times New Roman".  So I tried embedding 
> the Windows server's times.ttf font in the PDF, according to 
> the instructions in the FOP documentation, but even that 
> makes no difference.
> 
> Before I start trying to convert Times to an SVG font, or the 
> text to a series of paths, I thought I'd ask whether anyone 
> else here has had similar problems, and how they got around 
> them?  Or would I be better off asking on the FOP and/or Batik lists?
> 
> 
> Andrew.
> --
> http://pseudoq.sourceforge.net/  Open source java Sudoku application
> 
> _________________________________________________________________
> Find a local pizza place, movie theater, and more....then map 
> the best route! 
> http://maps.live.com/?icid=hmtag1&FORM=MGAC01
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org