We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copy Annotations in PDF without using XFDF - Aspose.PDF

Hello,

I have experienced an issue when trying to copy the annotations from one document to another one.

Actually when I try to add a pdf page entirely to the new document, all the information, which means the page, the annotations, etc, will be copied correctly to the new document.

But there are some cases where I need to zoom the page, and then I need to adjust the annotation to adapt to the new page size and position. But here I faced some issues for certain types of annotations like the squareAnnotation and StampAnnotation.

Both of the two types of annotations are created from Adobe Acrobat Reader (Rectangle, Stamp with a drawing), I can load them from the pdf document with Aspose.Pdf. Then I tried to copy them to my new document page, I noticed that I can find only the information about the name, title, contents, but I didn’t find anything about the resource about the annotations, like images, drawing, etc.

And I tried to find some documents about these annotations, but not too much useful information.

Can you please help on this?

Thanks,
Rui

@rui.jia0408

Would you please share some sample PDF files and sample code snippet so that we can test the scenario in our environment and address it accordingly. Furthermore, you can check export/import annotations via XFDF feature in the API if it helps.

Hello,

Thanks for your feedback. Actually I have checked the export/import annotations but it doesn’t fulfill our requirement, as we need to zoom out the page and then add additional contents to it.

The issue come from the fact that during the conversion/resizing of the page, the annotations cannot be kept. So that we have to process all the annotations and then convert/resize them and add them to the newly created page. We have managed to make it work concerning the inkannotation, but for other types of annotations like the stampannotation or the squareAnnotation, I cannot find the contents which I should copy.

Please check the codes as below:

            'pdfPath : file path
            Dim pdfDoc As Aspose.Pdf.Document = New Aspose.Pdf.Document(pdfPath)
            Dim mNewPtoDoc As New Aspose.Pdf.Document()

            Dim newPage As Aspose.Pdf.Page = mNewPtoDoc.Pages.Add()
            newPage.PageInfo.Margin = New MarginInfo(0, 0, 0, 0)
            newPage.SetPageSize(595, 842)

            Dim page As Aspose.Pdf.Page = pdfDoc.Pages(2)

            'Normally we need to zoom out the page here, but it seem that we cannot keep the annotations when creating a PdfPageStamp with a page.
            Dim pageStamp As New Aspose.Pdf.PdfPageStamp(page)
            pageStamp.Width = 595
            pageStamp.Height = 842
            pageStamp.XIndent = 0
            pageStamp.YIndent = 0

            newPage.AddStamp(pageStamp)

            'Copy original annotation to new page
            If page.Annotations.Count > 0 Then
                Dim annProcessedList As New List(Of String)

                For Each ann As Annotations.Annotation In page.Annotations
                    Select Case ann.AnnotationType
                        Case Annotations.AnnotationType.Ink
                            Dim inkAnn As Annotations.InkAnnotation = CType(ann, Aspose.Pdf.Annotations.InkAnnotation)

                            Dim rect As Aspose.Pdf.Rectangle = ann.Rect 
                            Dim inkList As IList(Of Aspose.Pdf.Point()) = inkAnn.InkList                                 
                            Dim newAnn As New Aspose.Pdf.Annotations.InkAnnotation(newPage, rect, inkList)

                            newAnn.Name = inkAnn.FullName
                            newAnn.Title = inkAnn.Title
                            newAnn.Contents = inkAnn.Contents
                            newAnn.Subject = inkAnn.Subject

                            newPage.Annotations.Add(newAnn)               
                        Case Annotations.AnnotationType.Square
                            Dim stAnn As Annotations.SquareAnnotation = CType(ann, Aspose.Pdf.Annotations.SquareAnnotation)

                            Dim rect As Aspose.Pdf.Rectangle = ann.Rect
                            Dim newAnn As New Aspose.Pdf.Annotations.SquareAnnotation(newPage, rect)

                            newAnn.Name = stAnn.FullName
                            newAnn.Title = stAnn.Title
                            newAnn.Contents = stAnn.Contents

                            'We have for example an annotation with a signature, unfortunately I cannot find anything in the SquareAnnotation/StampAnnotation, the only thing I noticed is that the Appearance, but still it's not the annotation content.
                            'Dim form As XForm = stAnn.Appearance.Item("N")
                            'Dim newForm As XForm = XForm.CreateNewForm(newPage, newDoc)
                            'newForm.Contents.Add(New Aspose.Pdf.Operator.GSave())
                            'newForm.Contents.Add(New Aspose.Pdf.Operator.ConcatenateMatrix(100, 0, 0, 100, 1, 1))
                            'newForm.Resources.Images.Add(form.Resources.Images.Item(1))
                            'newForm.Contents.Add(New Aspose.Pdf.Operator.Do(newForm.Resources.Images.Item(1).Name))
                            'newForm.Contents.Add(New Aspose.Pdf.Operator.GRestore())

                            'newAnn.Appearance.Add("N", newForm)

                            newPage.Annotations.Add(newAnn)

                        Case Annotations.AnnotationType.Stamp
                            Dim stAnn As Annotations.StampAnnotation = CType(ann, Aspose.Pdf.Annotations.StampAnnotation)

                            Dim rect As Aspose.Pdf.Rectangle = AsposeRenditionHelper.CalculateRectangleCoordinate(ann.Rect, pageWidth, pageHeight, pageStamp.Width, pageStamp.Height, pageStamp.XIndent, pageStamp.YIndent)
                            Dim newAnn As New Aspose.Pdf.Annotations.StampAnnotation(newPage, rect)

                            newAnn.Name = stAnn.FullName
                            newAnn.Title = stAnn.Title
                            newAnn.Contents = stAnn.Contents
                            newAnn.Image = stAnn.Image

                            newPage.Annotations.Add(newAnn)
                        Case Else
                            'Other type of annotations
                    End Select
                Next
            End If

            mNewPtoDoc.Save(outputPath)

I have aready simplified the codes which we use to copy an annotation to a new page in same size, else there are too many codes to copy.

I attahced this example file with different type of annotations, inkAnnotation, SquareAnnotation and StampAnnotation.

Test Record of Settlement Cute1 comment.pdf (110.4 KB)

Can you please provide some details how I can copy the SquareAnnotation and the StampAnnotation to the newly generated document?

Thanks,
Rui

@rui.jia0408

Could you please share following information as well:

  • Definition of Method AsposeRenditionHelper
  • An output generated at your end using the code snippet above

We will compare your output PDF with the one generated at our end and share our feedback with you accordingly.

Hi @asad.ali,

Here is the sample:

For the rectangle signature : i could still not be able to reproduce it my self (and I can’t share the document our client give us). So I’ll give you another document with the rectangle signature as soon as I can reproduce it.

So to begin, in the sample there is a stamp signature we are struggling to handle properly. This signature is on the bottom right corner of the second page of the document.

Thanks,

Nicolas

@nparisse

While running your shared application, we were able to produce the attached output PDF where you can see the signature stamp with an image. Please also note that we used Aspose.PDF for .NET 20.10 at our side to test the scenario.

result.pdf (144.5 KB)

Would you please check the attached output and let us know if you find any issue or your expected output is different than this. We will further proceed accordingly.

Hi @asad.ali,

Indeed the Aspose.pdf .NET 20.10 solve the issue for the stamp signature on this document.
But the issue is still there for both the square and stamp when the document has been created through an iPhone.

Here is the document where the issue is still there even with Aspose.PDF .NET 20.10:
sample-signature.pdf (91.9 KB)

Do you have a solution/workaround to handle this?

Thx,

Nicolas

@nparisse

We were able to notice that API was not generating a PDF with all annotations in the source document. Therefore, an issue as PDFNET-49025 has been logged in our issue tracking system for the sake of correction. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like

Hi @asad.ali,

Do you have any news about the current investigation on your side?

Thx,

Nicolas

@nparisse

We are afraid that earlier logged ticket is not yet resolved. Please note that we will surely look into its details and fix it, however it will be resolved on a first come first serve basis. We will certainly update you within this forum thread as soon as we have some definite updates in this regard. Please give us some time.

We apologize for the inconvenience caused.

Hi @asad.ali,

Could you tell me if the correction of the issue logged on the ticket send above is coming soon ?

Thanks,

Nicolas

@nparisse

We are afraid that the earlier logged ticket is not yet resolved. Please note that the ticket is more about a new feature which needs to be implemented in the API and it requires significant amount of time to get fully investigated and resolved. We will surely inform you as soon as we have some updates regarding its resolution. Please give us some time.

We apologize for the inconvenience.

Hi @asad.ali,

Any news about the evolution of this item?

Thx,

Nicolas

EDIT : I tested it with the latest stable version and it now works.
Thx !

@nparisse

It is nice to hear that your issue is resolved by using the latest version of the API. Please keep using our API and feel free to let us know in case you face any issue.

Hi @asad.ali,

It appears the copy of annotations is not working anymore. Can you open this ticket again ?

As a reminder : the problem comes from annotation not handled when creating a PdfPageStamp.

Below the dropbox url to get the sample which reproduces the issue:

Thx,

Nicolas

@nparisse

We have updated the ticket information as per provided information and will let you know as soon as the ticket is resolved. Please give us some time.

We apologize for the inconvenience.

Hi @asad.ali,

Could you give us some feedback about where is the progress of this fix?

Thx,

Nicolas

@nparisse

We are afraid that the investigation against the earlier logged ticket is not yet completed. As soon as we have some definite updates regarding its resolution, we will update you in this forum thread. Please be patient and spare us some time.

We are sorry for the inconvenience.

Hi @asad.ali

How is going the investigation on this ticket?

Thx,

Nicolas

@nparisse

We are afraid that the investigation against this ticket could not get completed due to other issues in the queue logged prior to it. However, we have recorded your concerns and will certainly take care of them during issue analysis. We will let you know as soon as the some updates are available regarding ticket resolution or fix ETA. Your patience and cooperation is highly appreciated in this regard.

We apologize for the inconvenience.