Print Page | Close Window

CapturePage and Existing Comments/Annotations

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2855
Printed Date: 25 Sep 25 at 11:54AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: CapturePage and Existing Comments/Annotations
Posted By: NBachus
Subject: CapturePage and Existing Comments/Annotations
Date Posted: 31 Mar 14 at 9:17PM
When using CapturePage() and DrawCapturedPage() (we're transforming the image to add margins), the existing Comments/Annotations entered in on Adobe Reader are not transferred over to the new "page".  I've tried to use CombineContentStreams() to combine all of the content into one stream, but this does not help the issue.  Does anyone have any ideas on how to solve this?



Replies:
Posted By: AndrewC
Date Posted: 01 Apr 14 at 6:43AM
NBachus,

Annotations are not part of the normal content stream which the CapturePage functions uses. Either are formfields as they are also based on annotations.

Annotations are a special type of object that is draw after the rest of the page is drawn.  They are not designed to be scaled easily.  You can adjust their bounding box but that is the easy bit.  You would need to adjust for line thickness and font height also.

There is going to be no elegant or easy solution to this.  

Another option to scaling the page may be to create a new content stream at the start of the file and another at the end to simulate the CapturePage/DrawCapturePage.  See the code below.  This will keep all of the annots but you will need to move each one manually into position.

// Pseudo code

  QP.LoadFromFile("myfile.pdf", "");

  // add a loop here for multipage documents to process each page.

  int idx = QP.NewContentStream();
  string s = "q 0.7 0 0 0.7 72 96 cm "; // space at the end, set transformation matrix
  QP.SetContentStreamFromString(s);
  QP.MoveContentStream(idx, 1);        // move the content stream to the front of the list.

  idx = QP.NewContentStream();
  string s = "Q ";   // space at the end, restore State command
  QP.SetContentStreamFromString(s);
  
  QP.SaveToFile .....

-------------------------------------------------------------------------------------------

// C# version

            QP.LoadFromFile("myfile.pdf", "");

            Byte[] b;
            ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            int idx = QP.NewContentStream();

    // This does all of the scaling.
            // A transformation matrix -  0.7 = xscale, 2nd 0.7 = yscale, 72 = horz offset, y = vert offset
            // The scale is for the overall size and the offsets move the page from the bottom corner
            // and position it where required.
            string s = "q 0.7 0 0 0.7 72 96 cm "; // space at the end, set transformation matrix

            b = encoding.GetBytes(s);
            QP.SetContentStreamFromString(b);
            QP.MoveContentStream(idx, 1);        // move the content stream to the front of the list.

            idx = QP.NewContentStream();
            s = "Q ";   // space at the end, restore State command
            b = encoding.GetBytes(s);
            QP.SetContentStreamFromString(b);

            QP.SaveToFile("out.pdf");

Andrew.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk