Question

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..

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top