Free Support Forum - aspose.com

Encoding of Bookmarks

I could not see, how to set the encoding of the bookmarks. If I create a bookmark like ‘Schriftsätze’ the resulting pdf contains something like ‘Schrifts#&stze’.



best regards

Arne

Hi Arne,


Thanks for contacting support and sorry for replying you late.

I have tested the scenario using following code snippet using Aspose.Pdf.Kit for Java 4.4.0 and I am unable to notice any issue. Can you please try using Aspose.Pdf.Kit for Java 4.4.0 and see if it can resolve your problem. We are sorry for this inconvenience.

[Java]

//create BookmarkEditor object and bind
PDF
<o:p></o:p>

PdfBookmarkEditor editor = new PdfBookmarkEditor();

editor.bindPdf("d:/pdftest/Sample.Signed.pdf");

//create Bookmark object and set appropriate attributes

Bookmark bm11 = new Bookmark();

bm11.setAction("GoTo");

bm11.setDestination("wen");

bm11.setTitle("firstchildoffirstchild");

//create another bookmark

Bookmark bm1 = new Bookmark();

bm1.setPageNumber(1);

bm1.setTitle("firstchild");

//create a list and add bookmarks in it

ArrayList aList1 = new ArrayList();

aList1.add(bm11);

bm1.setChildItem(aList1);

Bookmark bm2 = new Bookmark();

bm2.setPageNumber(2);

bm2.setTitle("secondchild");

Bookmark bm = new Bookmark();

bm.setPageNumber(1);

bm.setTitle("Schriftsätze");

ArrayList aList = new ArrayList();

aList.add(bm1);

aList.add(bm2);

bm.setChildItem(aList);

//create bookmarks in the PDF file

editor.createBookmarks(bm);

//save output PDF file

editor.save("d:/pdftest/testCreateBookmarksOut.pdf");

Hi codewarior


Thank you for your reply. Maybe it depends on the pdf file you used to bind. The file I used (example dok.pdf created with aspose.word) shows the result in the described manner. I used your code snippet and changed the page 2 to page 1 (because the pdf contains only one page).

best regards Arne

aspose.pdf.kit 4.4.0
mac osx -10.8
java 1.6
java file encoded utf8



Hi Arne,


Thanks for sharing the details and sorry for replying you late.

I am earlier attempt, I tried to test the scenario on Windows 7 X64 with JDK 1.6. However I when I have again tested the scenario while using the source PDF file which you have shared on similar machine, the string Schriftsätze is properly being displayed in Bookmark area. But when I have tried replicating the issue over Red Hat Linux Enterprise 5 with JDK 1.7.0_09 and I have used the following code line to compile the code, I am getting following error message.

[root@VM1 bin]# ./javac -encoding UTF8 -cp .:aspose-pdf-kit-4.4.0.jar code.java
code.java:1: error: illegal character: \65279
import com.aspose.pdf.kit.;
^
code.java:1: error: class, interface, or enum expected
import com.aspose.pdf.kit.;

The java code file is having UTF8 encoding. Same problem is occurring when I have used [root@Vm1 bin]# ./javac -cp .:aspose-pdf-kit-4.4.0.jar code.java

I will also try to replicate/test this scenario over MAC OSX and will share my findings shortly. We are sorry for this delay and inconvenience.

I think there is one simple solution


As far as I understand the representation off String in java is always ‘UTF-8’ or in some special cases ‘UTF-16’. But when you need bytes I guess you call something like

string.getBytes();

The result depends on the vendor and the default platform encoding, in our case of the java file encoding wich is ‘UTF-8’. Changing this to ‘ISO_8859_1’ (which we dont want to) will solve the problem. Setting

System.setProperty("file.encoding", "ISO_8859_1");

work either, so I guess you make a getBytes call, wich is intended to be encoded in ISO_8859_1. I dont really want to set the default encoding in our whole project to ISO_8859_1, but I think if you will call

string.getBytes("ISO_8859_1");

instead of

string.getBytes();

that will solve the problem

best regards

Arne

PS: there ist no difference between mac, windows or linux, because we will use utf-8 on all plattforms.

Hi Arne,


I am glad to hear that your problem is resolved by following above stated changes. However please note that I did not use any code lines i.e. string.getBytes(); etc and I simply used the code snippet specified below to add Bookmark to PDF file. The same code is working fine when tested with Aspose.Pdf.Kit for Java 4.4.0 in Eclipse project running over Windows 7(X64) with JDK 1.7.

Once again, thanks for sharing the details and solution to resolved similar issues.

[Java]
//create BookmarkEditor object and bind
PDF

PdfBookmarkEditor editor = new PdfBookmarkEditor();

editor.bindPdf("c:/pdftest/dok.pdf");

//create Bookmark object and set appropriate attributes

com.aspose.pdf.kit.Bookmark bm11 = new com.aspose.pdf.kit.Bookmark();

bm11.setAction("GoTo");

bm11.setDestination("wen");

bm11.setTitle("firstchildoffirstchild");

//create another bookmark

com.aspose.pdf.kit.Bookmark bm1 = new com.aspose.pdf.kit.Bookmark();

bm1.setPageNumber(1);

bm1.setTitle("firstchild");

//create a list and add bookmarks in it

ArrayList aList1 = new ArrayList();

aList1.add(bm11);

bm1.setChildItem(aList1);

Bookmark bm2 = new Bookmark();

bm2.setPageNumber(1);

bm2.setTitle("secondchild");

Bookmark bm = new Bookmark();

bm.setPageNumber(1);

bm.setTitle("Schriftsätze");

ArrayList aList = new ArrayList();

aList.add(bm1);

aList.add(bm2);

bm.setChildItem(aList);

//create bookmarks in the PDF file

editor.createBookmarks(bm);

//save output PDF file

editor.save(“c:/pdftest/testCreateBookmarksOut.pdf”);

Hi Codewarior


[edited]
I think the call

string.getBytes()

is used within the library of aspose.pdf when creating a bookmark. I assume, that in your libs you need the text representation von the bookmark as a byte-array and for this there was a call like

string.getBytes()

which should be

string.getBytes(“ISO-8859-1”)

if there is a need for a ISO-8859-1 encoding.

The problem is, that aspose.pdf does not work correct if the java file(s) is(are) encoded in utf-8.

best regards
Arne


PS.: please try to set the encoding of your testapplication java-file in eclipseto “utf-8”. In this case you have to correct the ‘umlauts’ in the file.

Hi Arne,


Thanks for sharing the details.

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””>For
the sake of correction, I have logged it in our issue tracking system as PDFKITJAVA-33276. We
will investigate this issue in details and will keep you updated on the status
of a correction. <o:p></o:p>

We apologize for your inconvenience.