Q:
I am trying to re-create customized stamps, available from the Acrobat
7.0 default location
C:\Program Files\Adobe\Acrobat 7.0\Acrobat\plug_ins\Annotations\Stamps
\ENU\SignHere.pdf. However, as a client's requiremet and security
issues, we cannot deploy this customised signhere.pdf to all PCs
Acrobat's default location and the file has to be kept on the server.
Therefore, I need to re-create the stamps from a different location on
the server. I using the following approach
Open the pdf to display
get the annotations associated with this pdf from database
recreate the annotations through switch
if its a stamp annotation then
Open the pdf (customized signhere pdf)
iterate through all pages
get number of annotation for each page
iterate through all annotation on that page
get that annoation
get its appearance stream
apply the appearance stream to the annotation on
a different pdf
However, since i am trying to apply the appearance to another pdf i
get an exception that objects cannot belong to different
documnet.Detail exception is given at the end.
Here is the sample code which i am using at the minute
//open the pdf to display
PDFDoc doc = new PDFDoc(reviewFileBuffer, reviewFileBuffer.Length);
pdftron.PDF.Page page = doc.PageBegin().Current();
Obj annots = page.GetAnnots();
if (annots == null)
{
// If there are no annotations, create a new
annotation
// array for the page.
annots = Obj.CreateArray();
page.GetSDFObj().Put("Annots", annots);
}
AnnotationType annotationType =
(AnnotationType)Enum.Parse(typeof(AnnotationType), type);
//get the annotation type from the object and add it to the current
pdf
switch (annotationType)
{
case AnnotationType.Text: ...//for type text
case AnnotationType.Stamp:
Obj stamp_annot = doc.CreateIndirectDict();
if (type!=null)
stamp_annot.Put("Subtype", Obj.CreateName(type));
if (rect != null)
stamp_annot.Put("Rect",
pdftron.PDF.Rect.CreateSDFRect( rect.x1,rect.y1 ,rect.x2 ,rect.y2 ));
... //for other annotation attributes...
if (ap != null) {
//for normal stamps
if (ap.ToString().StartsWith("#"))
stamp_annot.Put("Name", Obj.CreateString(ap));
else
//its a customised stamps, we need to get the stamp appearance from
a document available on server and not from Acrobat default location
{
//open a new pdf available on server
pdftron.PDF.PDFDoc sign_here_doc = new PDFDoc("C:\\SignHere.pdf");
//page iterator
pdftron.PDF.PageIterator itr;
//loop through all pages for customised stamps
for (itr = sign_here_doc.PageBegin(); itr !=
sign_here_doc.PageEnd(); itr.Next()) {
//get the current page
Page stamp_page = itr.Current();
//get number of anots on this page
int num_of_annots =
stamp_page.GetNumAnnots();
//loop through number of annots, in most
cases it would be 1
for (int index = 0; index < num_of_annots;
index++) {
//get the stamp at specied index
Annot sign_here_stamp =
stamp_page.GetAnnot(index);
//get the widgetfiled
Field field =
sign_here_stamp.GetWidgetField();
//get the field name for comparison
string fieldName = field.GetName();
//get the stamp appearance
Obj appearance = sign_here_stamp.GetAppearance();
//compare the fieldname...just for testing purpose
if (fieldName == "Approved")
{
stamp_annot.Put("Name",
appearance); //exception happens at this point.
}
}
}
}
}
annots.PushBack(stamp_annot);
...
pdftron.Common.PDFNetException was caught
Message="Exception: \n\t Message: Objects cannot belong to different
StackTrace: at pdftron.SDF.Obj.Put(String key, Obj value)
The code works fine if replace everything in else {} with
stamp_annot.Put("Name", Obj.CreateString(ap)); and add the customized
signhere.pdf to default acrobat location.
I would really appriate any sort of help, pointers, tips or way round
it as the project is due soon and this functionality is at the heart
of it.
----
A:
pdftron.Common.PDFNetException was caught
Message="Exception: \n\t Message: Objects cannot belong to different
To go around this you need to copy this SDF/Cos object from the
destination to the target document. You could do this as follows:
Obj imported_appearance =
target_pdfdoc.GetSDFDoc().ImportObj(appearance, true);
...
// Use the appearance in the target_pdfdoc...
stamp_annot.Put("Name", imported_appearance);