Frequently Asked Question

Set custom annotation icon
Last Updated 11 months ago

Below you can find an example on how to set customized icon for sticky text note/file attachment annotation

Page mPage = m_doc.GetPage(m_pageno);
if (mPage != null) {
   mPage.ObjsStart();

   Annotation annotation = mPage.GetAnnot(mPage.GetAnnotCount() - 1);
   if (annotation != null) {
      Document.DocForm form = m_doc.NewForm();
      PageContent content = new PageContent();
      content.Create();

      Bitmap icon = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.pdf_custom_stamp);

      Document.DocImage dimg = m_doc.NewImage(icon, true);
      ResImage rimg = form.AddResImage(dimg);
      Matrix mat = new Matrix( 20, 20, 0, 0 );
      content.GSSetMatrix(mat);
      mat.Destroy();
      content.DrawImage(rimg);
      content.GSRestore();

      form.SetContent(content, 0, 0, 20, 20);

      boolean success = annotation.SetIcon("MyIcon", form);

      icon.recycle();
      content.Destroy();
   }
   mPage.Close();
}


Loading ...