You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by "dysign.ch" <ma...@dysign.ch> on 2010/05/08 11:17:09 UTC

Create PDF with Umlauts (ä,ö,ü)

Hello everybody

I recently started a java project where one of the tasks is to generate
pdf files from some stored texts. As I'm from Switzerland, many texts
contain umlauts like ä,ö or ü. When pdfbox parses my strings with e.g.
contentStream.drawString(str); the result looks qite crappy if the
string contains umlauts, all umlaut characters are replaced with squares
and between everu normal character there is an additional space (string
comes from document with 'normal' ascii coding). If I convert the source
document/string to use UTF 8, the result looks even worse.

How can I tell pdfbox to print such umlauts correctly (it doesn't matter
if I'd have to use embedded fonts or external ttfs, I'm just happy if it
works somehow).

Kind regards and thanks in advance for helpful answers

Nicolas


Re: Extract Text from PDF

Posted by Thomas Fischer <fi...@aon.at>.
Hello Pooja,

to create an issue you have to log in at https://issues.apache.org/jira/secure/Dashboard.jspa
And for an example, it is not (only) your Java program that is needed but a PDF file that shows the behaviour described.

All the best
Thomas Fischer


Re: Extract Text from PDF

Posted by Pooja4 G <po...@tcs.com>.
Daniel,

Is this (issues.apache.org) email id where I need to create an issue? As I 
am new so not aware of this email id. 
As per the understanding sending to 'users@issue.apache.org.

Also attaching the example file -

 Problem Description

In my application, its a Document Management application which manages PDF 
documents.

so while this PDF documents created in Version '1.4(5.x) or later' by 
Adobe Professional 9.0 then 1 revision will be uploaded and pdf generated 
successfully.
But If I am trying to create its new revision say 2, then at the time of 
creation of 'PDF difference file', the line# 11 below -

1// Text Stripper initialisation
2                       PDFTextStripper stripper = new PDFTextStripper();
3                       pdfStream = new ByteArrayInputStream(pdf_buf);
4
5                       // Open and load PDF document content.
6                       document = PDDocument.load(pdfStream);
7 // Get the document content in String format.
8                       // And suppress all non ascii characters
9                       //try
10                      //{
11                      PDF_text = stripper.getText(document);

will return null as 'PDF_text' instead of text document of the PDF file.


Thanks & Regards,
Pooja Gupta
Tata Consultancy Services
Mailto: pooja4.g@tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________



From:
Daniel Wilson <wi...@gmail.com>
To:
users@pdfbox.apache.org
Date:
05/27/2010 07:57 PM
Subject:
Re: Extract Text from PDF



Pooja,

Would you create an issue at issues.apache.org for this and attach an
example file?

Thanks.

Daniel

On Wed, May 26, 2010 at 12:03 AM, Pooja4 G <po...@tcs.com> wrote:

> I tried to use the pdfbox1.1.0 but with this pdf generation failed while
> we are checking for Encryption of documents.
> Do anyone have any idea while more API we can use other than PDFbox for
> creation of PDFdiff file in DMS.
> We are uploading documents from Adobe professional 9.0 and while we 
create
> the new revision of the documents, it will fail at creation of PDF diff
> file. It returns null as below
>  using the class PDFTextStripper.class method
>  getText().
>
>        String PDF_text = new String();
>        PDFTextStripper stripper = new PDFTextStripper();
>
> PDF_text = stripper.getText(document);
>
> So please help me in solving this.
>
> Thanks & Regards,
> Pooja Gupta
> Tata Consultancy Services
> Mailto: pooja4.g@tcs.com
> Website: http://www.tcs.com
> ____________________________________________
> Experience certainty.   IT Services
>                        Business Solutions
>                        Outsourcing
> ____________________________________________
>
>
>
> From:
> Andreas Lehmkuehler <an...@lehmi.de>
> To:
> users@pdfbox.apache.org
> Date:
> 05/20/2010 09:21 PM
> Subject:
> Re: Extract Text from PDF
>
>
>
> Hi,
>
> Thomas Fischer schrieb:
> > Hello Pooja,
> >
> > I don't have any Adobe 9.0 documents, but I know that in my tests the
> newer versions of PDFBox perform significantly better than version 7.3.
> > I would suggest you try the fairly recent version 1.1.0, this works 
very
> well at least on my Adobe Acrobat 8.1 documents.
> Which can be found at [1]
>
>
> BR
> Andreas Lehmkühler
>
> [1] http://pdfbox.apache.org/download.html
> >
> > Mit freundlichen Grüßen
> > Thomas Fischer
> >
> >
> > Am 20.05.2010 um 14:07 schrieb Pooja4 G:
> >
> >> Which version of the PDF documents are supported by PDFbox0.7.3, As 
we
> >> upload a document of version Adobe Professional writer 9.0 and while
> >> creating the difference files to compare, we will extract the text 
data
>
> >> from the PDF document using the class PDFTextStripper.class method
> >> getText().
> >>
> >>        String PDF_text = new String();
> >>        PDFTextStripper stripper = new PDFTextStripper();
> >>
> >> PDF_text = stripper.getText(document);
> >>
> >> But it will return null if the argument as document is created from
> adobe
> >> Professional 9.0 else it will run successfully.
> >> Please help or at least let us know if any upcoming new version 
PDFBox
> >> does support this.
> >>
> >> Thanks & Regards,
> >> Pooja Gupta
> >> Tata Consultancy Services
> >> Mailto: pooja4.g@tcs.com
> >> Website: http://www.tcs.com
> >> ____________________________________________
> >> Experience certainty.   IT Services
> >>                        Business Solutions
> >>                        Outsourcing
> >> ____________________________________________
> >> =====-----=====-----=====
> >> Notice: The information contained in this e-mail
> >> message and/or attachments to it may contain
> >> confidential or privileged information. If you are
> >> not the intended recipient, any dissemination, use,
> >> review, distribution, printing or copying of the
> >> information contained in this e-mail message
> >> and/or attachments to it are strictly prohibited. If
> >> you have received this communication in error,
> >> please notify us by reply e-mail or telephone and
> >> immediately and permanently delete the message
> >> and any attachments. Thank you
> >>
> >>
> >
>
>
>
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>


=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



Re: Extract Text from PDF

Posted by Daniel Wilson <wi...@gmail.com>.
Pooja,

Would you create an issue at issues.apache.org for this and attach an
example file?

Thanks.

Daniel

On Wed, May 26, 2010 at 12:03 AM, Pooja4 G <po...@tcs.com> wrote:

> I tried to use the pdfbox1.1.0 but with this pdf generation failed while
> we are checking for Encryption of documents.
> Do anyone have any idea while more API we can use other than PDFbox for
> creation of PDFdiff file in DMS.
> We are uploading documents from Adobe professional 9.0 and while we create
> the new revision of the documents, it will fail at creation of PDF diff
> file. It returns null as below
>  using the class PDFTextStripper.class method
>  getText().
>
>        String PDF_text = new String();
>        PDFTextStripper stripper = new PDFTextStripper();
>
> PDF_text = stripper.getText(document);
>
> So please help me in solving this.
>
> Thanks & Regards,
> Pooja Gupta
> Tata Consultancy Services
> Mailto: pooja4.g@tcs.com
> Website: http://www.tcs.com
> ____________________________________________
> Experience certainty.   IT Services
>                        Business Solutions
>                        Outsourcing
> ____________________________________________
>
>
>
> From:
> Andreas Lehmkuehler <an...@lehmi.de>
> To:
> users@pdfbox.apache.org
> Date:
> 05/20/2010 09:21 PM
> Subject:
> Re: Extract Text from PDF
>
>
>
> Hi,
>
> Thomas Fischer schrieb:
> > Hello Pooja,
> >
> > I don't have any Adobe 9.0 documents, but I know that in my tests the
> newer versions of PDFBox perform significantly better than version 7.3.
> > I would suggest you try the fairly recent version 1.1.0, this works very
> well at least on my Adobe Acrobat 8.1 documents.
> Which can be found at [1]
>
>
> BR
> Andreas Lehmkühler
>
> [1] http://pdfbox.apache.org/download.html
> >
> > Mit freundlichen Grüßen
> > Thomas Fischer
> >
> >
> > Am 20.05.2010 um 14:07 schrieb Pooja4 G:
> >
> >> Which version of the PDF documents are supported by PDFbox0.7.3, As we
> >> upload a document of version Adobe Professional writer 9.0 and while
> >> creating the difference files to compare, we will extract the text data
>
> >> from the PDF document using the class PDFTextStripper.class method
> >> getText().
> >>
> >>        String PDF_text = new String();
> >>        PDFTextStripper stripper = new PDFTextStripper();
> >>
> >> PDF_text = stripper.getText(document);
> >>
> >> But it will return null if the argument as document is created from
> adobe
> >> Professional 9.0 else it will run successfully.
> >> Please help or at least let us know if any upcoming new version PDFBox
> >> does support this.
> >>
> >> Thanks & Regards,
> >> Pooja Gupta
> >> Tata Consultancy Services
> >> Mailto: pooja4.g@tcs.com
> >> Website: http://www.tcs.com
> >> ____________________________________________
> >> Experience certainty.   IT Services
> >>                        Business Solutions
> >>                        Outsourcing
> >> ____________________________________________
> >> =====-----=====-----=====
> >> Notice: The information contained in this e-mail
> >> message and/or attachments to it may contain
> >> confidential or privileged information. If you are
> >> not the intended recipient, any dissemination, use,
> >> review, distribution, printing or copying of the
> >> information contained in this e-mail message
> >> and/or attachments to it are strictly prohibited. If
> >> you have received this communication in error,
> >> please notify us by reply e-mail or telephone and
> >> immediately and permanently delete the message
> >> and any attachments. Thank you
> >>
> >>
> >
>
>
>
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>

Re: Extract Text from PDF

Posted by Pooja4 G <po...@tcs.com>.
I tried to use the pdfbox1.1.0 but with this pdf generation failed while 
we are checking for Encryption of documents.
Do anyone have any idea while more API we can use other than PDFbox for 
creation of PDFdiff file in DMS.
We are uploading documents from Adobe professional 9.0 and while we create 
the new revision of the documents, it will fail at creation of PDF diff 
file. It returns null as below
 using the class PDFTextStripper.class method 
 getText().

        String PDF_text = new String();
        PDFTextStripper stripper = new PDFTextStripper();

PDF_text = stripper.getText(document);

So please help me in solving this.

Thanks & Regards,
Pooja Gupta
Tata Consultancy Services
Mailto: pooja4.g@tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________



From:
Andreas Lehmkuehler <an...@lehmi.de>
To:
users@pdfbox.apache.org
Date:
05/20/2010 09:21 PM
Subject:
Re: Extract Text from PDF



Hi,

Thomas Fischer schrieb:
> Hello Pooja,
> 
> I don't have any Adobe 9.0 documents, but I know that in my tests the 
newer versions of PDFBox perform significantly better than version 7.3.
> I would suggest you try the fairly recent version 1.1.0, this works very 
well at least on my Adobe Acrobat 8.1 documents.
Which can be found at [1]


BR
Andreas Lehmkühler

[1] http://pdfbox.apache.org/download.html
> 
> Mit freundlichen Grüßen
> Thomas Fischer
> 
> 
> Am 20.05.2010 um 14:07 schrieb Pooja4 G:
> 
>> Which version of the PDF documents are supported by PDFbox0.7.3, As we 
>> upload a document of version Adobe Professional writer 9.0 and while 
>> creating the difference files to compare, we will extract the text data 

>> from the PDF document using the class PDFTextStripper.class method 
>> getText().
>>
>>        String PDF_text = new String();
>>        PDFTextStripper stripper = new PDFTextStripper();
>>
>> PDF_text = stripper.getText(document);
>>
>> But it will return null if the argument as document is created from 
adobe 
>> Professional 9.0 else it will run successfully.
>> Please help or at least let us know if any upcoming new version PDFBox 
>> does support this.
>>
>> Thanks & Regards,
>> Pooja Gupta
>> Tata Consultancy Services
>> Mailto: pooja4.g@tcs.com
>> Website: http://www.tcs.com
>> ____________________________________________
>> Experience certainty.   IT Services
>>                        Business Solutions
>>                        Outsourcing
>> ____________________________________________
>> =====-----=====-----=====
>> Notice: The information contained in this e-mail
>> message and/or attachments to it may contain 
>> confidential or privileged information. If you are 
>> not the intended recipient, any dissemination, use, 
>> review, distribution, printing or copying of the 
>> information contained in this e-mail message 
>> and/or attachments to it are strictly prohibited. If 
>> you have received this communication in error, 
>> please notify us by reply e-mail or telephone and 
>> immediately and permanently delete the message 
>> and any attachments. Thank you
>>
>>
> 



=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



Re: Extract Text from PDF

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,

Thomas Fischer schrieb:
> Hello Pooja,
> 
> I don't have any Adobe 9.0 documents, but I know that in my tests the newer versions of PDFBox perform significantly better than version 7.3.
> I would suggest you try the fairly recent version 1.1.0, this works very well at least on my Adobe Acrobat 8.1 documents.
Which can be found at [1]


BR
Andreas Lehmkühler

[1] http://pdfbox.apache.org/download.html
> 
> Mit freundlichen Grüßen
> Thomas Fischer
> 
> 
> Am 20.05.2010 um 14:07 schrieb Pooja4 G:
> 
>> Which version of the PDF documents are supported by PDFbox0.7.3, As we 
>> upload a document of version Adobe Professional writer 9.0 and while 
>> creating the difference files to compare, we will extract the text data 
>> from the PDF document using the class PDFTextStripper.class method 
>> getText().
>>
>>        String PDF_text = new String();
>>        PDFTextStripper stripper = new PDFTextStripper();
>>
>> PDF_text = stripper.getText(document);
>>
>> But it will return null if the argument as document is created from adobe 
>> Professional 9.0 else it will run successfully.
>> Please help or at least let us know if any upcoming new version PDFBox 
>> does support this.
>>
>> Thanks & Regards,
>> Pooja Gupta
>> Tata Consultancy Services
>> Mailto: pooja4.g@tcs.com
>> Website: http://www.tcs.com
>> ____________________________________________
>> Experience certainty.   IT Services
>>                        Business Solutions
>>                        Outsourcing
>> ____________________________________________
>> =====-----=====-----=====
>> Notice: The information contained in this e-mail
>> message and/or attachments to it may contain 
>> confidential or privileged information. If you are 
>> not the intended recipient, any dissemination, use, 
>> review, distribution, printing or copying of the 
>> information contained in this e-mail message 
>> and/or attachments to it are strictly prohibited. If 
>> you have received this communication in error, 
>> please notify us by reply e-mail or telephone and 
>> immediately and permanently delete the message 
>> and any attachments. Thank you
>>
>>
> 


Re: Extract Text from PDF

Posted by Thomas Fischer <fi...@aon.at>.
Hello Pooja,

I don't have any Adobe 9.0 documents, but I know that in my tests the newer versions of PDFBox perform significantly better than version 7.3.
I would suggest you try the fairly recent version 1.1.0, this works very well at least on my Adobe Acrobat 8.1 documents.

Mit freundlichen Grüßen
Thomas Fischer


Am 20.05.2010 um 14:07 schrieb Pooja4 G:

> Which version of the PDF documents are supported by PDFbox0.7.3, As we 
> upload a document of version Adobe Professional writer 9.0 and while 
> creating the difference files to compare, we will extract the text data 
> from the PDF document using the class PDFTextStripper.class method 
> getText().
> 
>        String PDF_text = new String();
>        PDFTextStripper stripper = new PDFTextStripper();
> 
> PDF_text = stripper.getText(document);
> 
> But it will return null if the argument as document is created from adobe 
> Professional 9.0 else it will run successfully.
> Please help or at least let us know if any upcoming new version PDFBox 
> does support this.
> 
> Thanks & Regards,
> Pooja Gupta
> Tata Consultancy Services
> Mailto: pooja4.g@tcs.com
> Website: http://www.tcs.com
> ____________________________________________
> Experience certainty.   IT Services
>                        Business Solutions
>                        Outsourcing
> ____________________________________________
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain 
> confidential or privileged information. If you are 
> not the intended recipient, any dissemination, use, 
> review, distribution, printing or copying of the 
> information contained in this e-mail message 
> and/or attachments to it are strictly prohibited. If 
> you have received this communication in error, 
> please notify us by reply e-mail or telephone and 
> immediately and permanently delete the message 
> and any attachments. Thank you
> 
> 


Extract Text from PDF

Posted by Pooja4 G <po...@tcs.com>.
Which version of the PDF documents are supported by PDFbox0.7.3, As we 
upload a document of version Adobe Professional writer 9.0 and while 
creating the difference files to compare, we will extract the text data 
from the PDF document using the class PDFTextStripper.class method 
getText().

        String PDF_text = new String();
        PDFTextStripper stripper = new PDFTextStripper();

PDF_text = stripper.getText(document);

 But it will return null if the argument as document is created from adobe 
Professional 9.0 else it will run successfully.
Please help or at least let us know if any upcoming new version PDFBox 
does support this.

Thanks & Regards,
Pooja Gupta
Tata Consultancy Services
Mailto: pooja4.g@tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you



Re: Create PDF with Umlauts (ä,ö,ü)

Posted by "Michael Fischer v. Mollard" <li...@m-fvm.de>.
Am Donnerstag, den 20.05.2010, 13:06 +0300 schrieb Mikael Komu:
> Hi,
> 
> I had the same problem with ä and ö characters as I had to create pdf's from
> Finnish texts. I used the TextToPDF.createPDFFromText method so I'm not sure
> if the same solution works for you. I needed to change the encoding of the
> font to get it working. Here's an example:
> 
> String text = "opqrstuvwxyzåäö";
> org.apache.pdfbox.TextToPDF textToPdf = new org.apache.pdfbox.TextToPDF();
> EncodingManager encodingManager = new EncodingManager();
> textToPdf.getFont().setEncoding(encodingManager.getEncoding(COSName.WIN_ANSI_ENCODING));
> PDDocument doc = textToPdf.createPDFFromText(new StringReader(text));
> 
> Hope this helps.
> 

Hi,

it did, thank you. It works fine with latin-1 (i.e. U+0000 - U+00FF),
which is sufficient for me. Nevertheless a drawString which accepts more
than a subset of string (given the font can handle it) would be a nice
thing to have.

Regards
	Michael


Re: Create PDF with Umlauts (ä,ö,ü)

Posted by Mikael Komu <mi...@gmail.com>.
Hi,

I had the same problem with ä and ö characters as I had to create pdf's from
Finnish texts. I used the TextToPDF.createPDFFromText method so I'm not sure
if the same solution works for you. I needed to change the encoding of the
font to get it working. Here's an example:

String text = "opqrstuvwxyzåäö";
org.apache.pdfbox.TextToPDF textToPdf = new org.apache.pdfbox.TextToPDF();
EncodingManager encodingManager = new EncodingManager();
textToPdf.getFont().setEncoding(encodingManager.getEncoding(COSName.WIN_ANSI_ENCODING));
PDDocument doc = textToPdf.createPDFFromText(new StringReader(text));

Hope this helps.

  -Mikael


On Thu, May 20, 2010 at 4:04 AM, Michael Fischer v. Mollard
<li...@m-fvm.de>wrote:

> Am Samstag, den 08.05.2010, 16:51 +0200 schrieb Andreas Lehmkuehler:
> > Hi,
> >
> > dysign.ch schrieb:
> > > Hello everybody
> > >
> > > I recently started a java project where one of the tasks is to generate
> > > pdf files from some stored texts. As I'm from Switzerland, many texts
> > > contain umlauts like ä,ö or ü. When pdfbox parses my strings with e.g.
> > > contentStream.drawString(str); the result looks qite crappy if the
> > > string contains umlauts, all umlaut characters are replaced with
> squares
> > > and between everu normal character there is an additional space (string
> > > comes from document with 'normal' ascii coding). If I convert the
> source
> > > document/string to use UTF 8, the result looks even worse.
> > >
> > > How can I tell pdfbox to print such umlauts correctly (it doesn't
> matter
> > > if I'd have to use embedded fonts or external ttfs, I'm just happy if
> it
> > > works somehow).
> > You should use an external ttf which supports umlauts, see [1] how to do
> that.
> > Convert your text to UTF-8 before calling drawString().
> >
> > HTH
> > Andreas Lehmkühler
> >
> > [1]
> >
> http://svn.apache.org/repos/asf/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
>
> Sorry,
>
> but thats to fast for me. drawString expects a String, and a Java String
> is AFAIK always UTF-16.
>
> Playing a little bit with HelloWorldTTF.java i got poor results with
> /usr/share/fonts/truetype/ttf-bitstream-vera/VeraMoBI.ttf
>
> and
> java.io.IOException: Unknown cmap format:12
>        at
>
> org.apache.fontbox.ttf.CMAPEncodingEntry.initSubtable(CMAPEncodingEntry.java:157)
>        at org.apache.fontbox.ttf.CMAPTable.initData(CMAPTable.java:90)
>        at org.apache.fontbox.ttf.TTFParser.parseTTF(TTFParser.java:144)
>        at org.apache.fontbox.ttf.TTFParser.parseTTF(TTFParser.java:87)
>        at
>
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadDescriptorDictionary(PDTrueTypeFont.java:193)
>        at
>
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:153)
>        at
>
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:130)
>
> with the
> DejaVu-font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf.
>
> Can anybody point me some examples how to do it right?
>
> Regards
>         Michael
>
>
>
>

Re: Create PDF with Umlauts (ä,ö,ü)

Posted by "Michael Fischer v. Mollard" <li...@m-fvm.de>.
Am Samstag, den 08.05.2010, 16:51 +0200 schrieb Andreas Lehmkuehler:
> Hi,
> 
> dysign.ch schrieb:
> > Hello everybody
> > 
> > I recently started a java project where one of the tasks is to generate
> > pdf files from some stored texts. As I'm from Switzerland, many texts
> > contain umlauts like ä,ö or ü. When pdfbox parses my strings with e.g.
> > contentStream.drawString(str); the result looks qite crappy if the
> > string contains umlauts, all umlaut characters are replaced with squares
> > and between everu normal character there is an additional space (string
> > comes from document with 'normal' ascii coding). If I convert the source
> > document/string to use UTF 8, the result looks even worse.
> > 
> > How can I tell pdfbox to print such umlauts correctly (it doesn't matter
> > if I'd have to use embedded fonts or external ttfs, I'm just happy if it
> > works somehow).
> You should use an external ttf which supports umlauts, see [1] how to do that.
> Convert your text to UTF-8 before calling drawString().
> 
> HTH
> Andreas Lehmkühler
> 
> [1] 
> http://svn.apache.org/repos/asf/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java

Sorry,

but thats to fast for me. drawString expects a String, and a Java String
is AFAIK always UTF-16.

Playing a little bit with HelloWorldTTF.java i got poor results with
/usr/share/fonts/truetype/ttf-bitstream-vera/VeraMoBI.ttf

and
java.io.IOException: Unknown cmap format:12
	at
org.apache.fontbox.ttf.CMAPEncodingEntry.initSubtable(CMAPEncodingEntry.java:157)
	at org.apache.fontbox.ttf.CMAPTable.initData(CMAPTable.java:90)
	at org.apache.fontbox.ttf.TTFParser.parseTTF(TTFParser.java:144)
	at org.apache.fontbox.ttf.TTFParser.parseTTF(TTFParser.java:87)
	at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadDescriptorDictionary(PDTrueTypeFont.java:193)
	at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:153)
	at
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.loadTTF(PDTrueTypeFont.java:130)

with the
DejaVu-font /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf.

Can anybody point me some examples how to do it right?

Regards
	Michael




Re: Create PDF with Umlauts (ä,ö,ü)

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,

dysign.ch schrieb:
> Hello everybody
> 
> I recently started a java project where one of the tasks is to generate
> pdf files from some stored texts. As I'm from Switzerland, many texts
> contain umlauts like ä,ö or ü. When pdfbox parses my strings with e.g.
> contentStream.drawString(str); the result looks qite crappy if the
> string contains umlauts, all umlaut characters are replaced with squares
> and between everu normal character there is an additional space (string
> comes from document with 'normal' ascii coding). If I convert the source
> document/string to use UTF 8, the result looks even worse.
> 
> How can I tell pdfbox to print such umlauts correctly (it doesn't matter
> if I'd have to use embedded fonts or external ttfs, I'm just happy if it
> works somehow).
You should use an external ttf which supports umlauts, see [1] how to do that.
Convert your text to UTF-8 before calling drawString().

HTH
Andreas Lehmkühler

[1] 
http://svn.apache.org/repos/asf/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java