3

I am trying to put a sticky note at some x,y location. For this i am using the pdfclown annotation class in .net. Below is what is available.

    using files = org.pdfclown.files;
    public override bool Run()
    {
        files::File file = new files::File();
        Document document = file.Document;
        Populate(document);
        Serialize(file, false, "Annotations", "inserting annotations");
        return true;
    }

    private void Populate(Document document)
    {
        Page page = new Page(document);
        document.Pages.Add(page);
        PrimitiveComposer composer = new PrimitiveComposer(page);
        StandardType1Font font = new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false);
        composer.SetFont(font, 12);
        annotations::Note note = new annotations::Note(page, new Point(78, 658), "this is my annotation...");
        note.IconType = annotations::Note.IconTypeEnum.Help;
        note.ModificationDate = new DateTime();
        note.IsOpen = true;
        composer.Flush();
    }

Link for annotation This is putting a sticky note at 78, 658 cordinates in a blank pdf.

The problem is that i want that sticky note in a particular pdf which has some data. How can i modify it...thanks for the help..

user1853803
  • 649
  • 3
  • 8
  • 27

1 Answers1

4

I'm the author of PDF Clown -- this is the right way to insert an annotation like a sticky note into an existing page:

using org.pdfclown.documents;
using annotations = org.pdfclown.documents.interaction.annotations;
using files = org.pdfclown.files;
using System.Drawing;

. . .

// Open the PDF file!
using(files::File file = new files::File(@"C:\mypath\myfile.pdf"))
{
  // Get the document (high-level representation of the PDF file)!
  Document document = file.Document;
  // Get, e.g., the first page of the document!
  Page page = document.Pages[0];

  // Insert your sticky note into the page!
  annotations::Note note = new annotations::Note(page, new Point(78, 658), "this is my annotation...");
  note.IconType = annotations::Note.IconTypeEnum.Help;
  note.ModificationDate = new DateTime();
  note.IsOpen = true;

  // Save the PDF file!
  file.Save(files::SerializationModeEnum.Incremental);
}

Please consider that there are lots of options about the way you can save your file (to an output (in-memory) stream, to a distinct path, as a compacted file, as an appended file...).

If you look at the 50+ samples accompanying the library's distribution, along with the API documentation, you can discover how expressive and powerful it is. Its architecture strictly adheres to the official Adobe PDF Reference 1.7.

enjoy!

  • thanks stefano and nice to talk to the author itself....one more question i have....i have parsed the pdf and i am geting lot of Tm{1,0,0,1,345,234}/Tj...what does it mean....and if 345 and 234 are x,y cordinates of the pdf pointing to some word...if i mark the same x,y cordinates to another pdf using annotation class for sticky notes....i get some different position...is this a bug or i need to change something or i am understand this wrong....actually my intention is to compare to pdf word by word, color by color, line by line, image by image and every possible thing....hats of to ur work... – user1853803 Dec 24 '12 at 18:48
  • its really very powerfull api in comparsion to isharp, pdfnet and other which i have used so far.... – user1853803 Dec 24 '12 at 18:50
  • you have to make clear in your mind how to match your objectives to the actual PDF content model. The same content representation can be achieved through a virtually infinite combination of content stream operators: if you are interested to a _low-level_ comparison, you can dig through Tm/Tj/and so on operations using `ContentScanner` class, but this can be a bit complex as you have to consider the current `GraphicsState`; if you are interested to _high-level_ entities like text, graphics shapes and images, `ContentScanner` exposes abstracted entities derived from `GraphicsObjectWrapper`. – Stefano Chizzolini Dec 24 '12 at 23:22
  • when you parse (low-level) content operations like Tm and Tj, the coordinate values expressed by their parameters are _relative_ to the current (bottom-up) coordinate system, which may have been subject to transformations! Thus they _cannot_ be directly used to place (high-level) sticky note annotations, as the latter are expressed in default user space unit (top-down) coordinates. Therefore, you have to transform low-level coordinate parameters according to the current transformation matrix and invert their y-axis orientation in order to get homogeneous locations. – Stefano Chizzolini Dec 24 '12 at 23:50
  • 1
    moral of the story: if you want to exploit advanced functionalities you have to delve into the intricacies of the PDF specification. :-) – Stefano Chizzolini Dec 24 '12 at 23:55