Create FreeTextAnnotations with Rich Text using Aspose.PDF for Java

Share on FacebookTweet about this on TwitterShare on LinkedIn

We are gratified to announce that latest version Aspose.PDF for Java 18.10 has been released. As per regular monthly revision, quite exciting features and enhancements have been included in latest release in order to make API more user friendly and usable while creating and manipulating PDF documents. Release notes page of Aspose.PDF for Java 18.10 contains detailed information of what has been changed and introduced new in the latest release. In case you are planning to use latest version in your Java Applications, it is strongly recommended to go through release notes page of the API.

Following section includes insights into worth-mentioning features that latest version of the API includes:

FreeTextAnnotation with Rich Text

RichText is now supported in FreeTextAnnotation. Please note that rich text is HTML-like text markup and in order to use this in FreeTextAnnotaiton, you need to use setRichText() method offered by the API as following sample:

freeTextAnnot.setRichText("<?xml version=\"1.0\"?>" " + 
"<body xmlns=\"\" " + "xmlns:xfa=\"\" xfa:APIVersion=\"Acrobat:11.0.23\" " + "xfa:spec=\"2.0.2\" style=\"font-size:12.0pt;color:#00eeff;font-weight:normal;font-style:normal;" + "font-family:Arial;font-stretch:normal\"><p dir=\"ltr\">This <p style=\"color:#00ff00;" + "font-style:italic\">is </p> a</p> rich text</body>");

If you need just plain text, you should use Contents Property instead of RictText but, you may assign plain text to RichText and this would also work:

freeTextAnnot.setContents("Annotation Text");
// or
freeTextAnnot.setRichText("Annotation Text");

Please also notice that, using DefaultAppearance.FontSize can set the font size manually as shown below:

DefaultAppearance defaultAppearance = new DefaultAppearance();
// or 
DefaultAppearance defaultAppearance =
new DefaultAppearance("Arial", 12, java.awt.Color.BLACK);

Miscellaneous Fixes

Along with the feature mentioned above, following are some useful improvement which have been made to the latest version of the API:

  • Support of custom fonts is tested and verified for IBM iSeries
  • HOCR to PDF conversion has been improved for multithreaded maven scenarios
  • Text Stamping has further been improved
  • PDF to PDF/A Conversion engine is further improved

As it is always recommended to use latest release of our API’s because they include latest features/improvements and fixes related to issues reported in earlier released versions. Therefore, please download the latest release of Aspose.PDF for Java 18.10.