Search code examples
c#pdfitext

Apply Formatting to pdf bookmarks using itextsharp


This is further to my question Add Page bookmarks to an existing PDF using iTextSharp using C# code

With the guidence of Bruno Lowagie i managed to add pdf bookmarks using iTextShrp, but now i need to add color and bold formatting to the bookmarks.

Please help...

I am sure that it is possible , becuase i used ExportToXML to retrieve an already formatted bookmark, then it is having formatting info as well.


Solution

  • Just like in my previous answer, I would like you to please read the documentation.

    What you are asking is explained in the CreateOutlineTree example. If bookmark is of type PdfOutline, you can change the style and font like this:

     bookmark.setStyle(Font.BOLD);
     bookmark.setColor(BaseColor.BLUE);
    

    If you look at the C# port of the example, you'll discover a slight difference in iTextSharp:

     bookmark.Style = Font.BOLD;
     bookmark.Color = BaseColor.BLUE;