1

I'm trying to enlarge the icon of a PDF sticky note. Here's an image showing the sticky icon that I've stamped on the first page of the PDF for context:

enter image description here

I was under the impression the icon was guided by a rectangle that could be manipulated. Here's my code that has not been effective yet:

using (PdfStamper stamp = new PdfStamper(reader, fs))
{
    PdfWriter attachment = stamp.Writer;
    foreach (string file in files_to_attach)
    {
        PdfFileSpecification pdfAttch = PdfFileSpecification.FileEmbedded(attachment, file, file, null);
        stamp.AddFileAttachment(file, pdfAttch);
    }

    //Create Note for first page
    Rectangle rect = new Rectangle(850, 850, 650, 650);
    PdfAnnotation annotation = PdfAnnotation.CreateText(stamp.Writer, rect, "TITLE OF NOTE", "Body text of the note", false, "Comment");

    //Enlarge the Sticky Note icon
    PdfDictionary page = reader.GetPageN(1);
    PdfArray annots = page.GetAsArray(PdfName.ANNOTS);
    PdfDictionary sticky = annots.GetAsDict(0);
    PdfArray stickyRect = sticky.GetAsArray(PdfName.RECT);
    PdfRectangle stickyRectangle = new PdfRectangle(
        stickyRect.GetAsNumber(0).FloatValue - 50, stickyRect.GetAsNumber(1).FloatValue - 20,
        stickyRect.GetAsNumber(2).FloatValue, stickyRect.GetAsNumber(3).FloatValue - 30);
    sticky.Put(PdfName.RECT, stickyRectangle);

    //Apply the Note to the first page
    stamp.AddAnnotation(annotation, 1);

    stamp.Close();
}

I thought I could change the float values and that would change the shape of the icon but so far it has not effected it all. Thank you for any suggestions.

mkl
  • 90,588
  • 15
  • 125
  • 265
DBlair
  • 9
  • 3

1 Answers1

1

You can't. The icon that is displayed for the "Comment" annotation is supplied by the viewer. The rect property is only used to define the lower left corner of where the icon gets placed on the page by the viewer. According to the PDF specification for annotations with the type "Text", "Conforming readers shall provide predefined icon appearances for at least the following standard names: Comment, Key, Note, Help, NewParagraph, Paragraph, Insert.

You can, however, create your own image, of any size, and use it as the appearance for a "Stamp" annotation. It can even look exactly like a "Comment" icon, just bigger. It would end up functioning in the same way for the end user.

joelgeraci
  • 4,606
  • 1
  • 12
  • 19
  • So in order to have it "function in the same way to the end user" it would need to still be represented as an annotation, right? As in: PdfAnnotation annotation = PdfAnnotation.CreateText(stamp.Writer, rect, "TITLE OF NOTE", "Body text of note", false, "Comment"); but instead of "comment" I would pass in an image. "Comment" is a string, what syntax allows a image to become a string? – DBlair Apr 07 '17 at 15:41
  • 1
    See the AddStamp example by Bruno. It's Java but you'll get the idea. http://developers.itextpdf.com/examples/actions-and-annotations/clone-creating-and-adding-annotations#2260-addstamp.java – joelgeraci Apr 07 '17 at 16:29