We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Pdf Viewer Ink annotation points colection scale problem

Thread ID:

Created:

Updated:

Platform:

Replies:

146540 Aug 7,2019 03:11 PM UTC Aug 12,2019 10:28 AM UTC WPF 8
loading
Tags: PdfViewer
Jean Philippe Gagliardi
Asked On August 7, 2019 03:13 PM UTC

Hi, we are using the pdfviewer control in a wpf application and since the july update, we have a problem with ink annotations.

Previously we were using inkannotation inklist property to draw on pdf and it was working fine.

Since july update, it seems inklist is always empty so we are trying to use the InkPointsCollection(0) property and have access to the list of points but it seems that the scaling of these points is really smaller and we find ourselves with a drawing that is much smaller than what we are drawing in reality. 

What I mean is that the drawing is a good representation of what was drawn in the annotation but the size is like a fifth of the real scale...

This is the code sample, we tried with version 17.2450.0.34 and .39

If DirectCast(loadedPage, Syncfusion.Pdf.PdfPageBase).Annotations.Count > 0 Then
                        For Each a As Object In DirectCast(loadedPage, Syncfusion.Pdf.PdfPageBase).Annotations
                            If TypeOf a Is Syncfusion.Pdf.Interactive.PdfInkAnnotation Then
                                Dim an As Syncfusion.Pdf.Interactive.PdfInkAnnotation = DirectCast(a, Syncfusion.Pdf.Interactive.PdfInkAnnotation)
                                cb.SetColorStroke(New iTextSharp.text.BaseColor(an.Color.R, an.Color.G, an.Color.B))
                                If an.InkPointsCollection.FirstOrDefault IsNot Nothing Then
                                    cb.MoveTo(an.InkPointsCollection(0)(0), an.InkPointsCollection(0)(1))
                                    For i As Integer = 0 To an.InkPointsCollection(0).Count - 1 Step 2
                                        Dim NextX As Single = an.InkPointsCollection(0)(i)
                                        Dim NextY As Single = an.InkPointsCollection(0)(i + 1)
                                        cb.LineTo(NextX + 1, NextY + 1)
                                        cb.Stroke()
                                        cb.MoveTo(NextX + 1, NextY + 1)
                                    Next
                                End If
                            ElseIf TypeOf a Is Syncfusion.Pdf.Interactive.PdfFreeTextAnnotation Then
                                Dim an As Syncfusion.Pdf.Interactive.PdfFreeTextAnnotation = DirectCast(a, Syncfusion.Pdf.Interactive.PdfFreeTextAnnotation)
                                Dim loc As Drawing.PointF = an.Location

                                'Dim marginleft As Integer = 20
                                'Dim marginright As Integer = 20
                                'Dim margintop As Integer = 20
                                'Dim marginbottom As Integer = 20
                                Dim hasaddeddate As Boolean = False

                                If _contract IsNot Nothing AndAlso _contract.State >= SaleContractStatus.ContratExecute Then
                                    ApplyFreeTextPolicy(an)
                                    hasaddeddate = True
                                Else
                                    an.Text = Strings.Trim(an.MarkupText)
                                    hasaddeddate = False
                                End If

                                'prepare text
                                Dim ct As ColumnText = New ColumnText(cb)
                                Dim textfont As iTextSharp.text.Font = New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, Math.Max(an.Font.Size - 4, 6), 0, iTextSharp.text.BaseColor.BLUE)
                                Dim markupfont As iTextSharp.text.Font = New iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 4, 2, iTextSharp.text.BaseColor.RED)
                                Dim s As String = an.MarkupText
                                Dim arra = s.Split(vbCrLf)
                                Dim textlist As New List(Of String)
                                For i As Integer = 0 To arra.Length - 1
                                    arra(i) = arra(i).Replace(vbLf, String.Empty)
                                    textlist.Add(arra(i))
                                Next
                                If textlist.Count = 0 OrElse (hasaddeddate AndAlso textlist.Count = 2) Then Continue For
                                'define rectangle
                                Dim contentheight As Single = loadedPage.Size.Height
                                Dim contentwidth As Single = loadedPage.Size.Width
                                Dim tbheight As Single = an.Size.Height
                                Dim tbwidth As Single = an.Size.Width
                                Dim delta As Single = 0
                                If hasaddeddate = True Then
                                    'si on a ajouté une ligne de texte au début, il faut agrandir le rectangle.
                                    'car le texte ajouté ne fait pas partie de la textbox dessinée par l'utilisateur et ses dimensions sont importantes
                                    Dim OriginalNbRows As Integer = textlist.Count - 2 'vu qu'on a ajouté une row
                                    Dim heightperrow As Single = 8 ' tbheight / OriginalNbRows
                                    delta = heightperrow * 2
                                End If
                                Dim llx As Single = an.Location.X
                                Dim lly As Single = contentheight - an.Location.Y - tbheight
                                Dim urx As Single = an.Location.X + tbwidth
                                Dim ury As Single = contentheight - an.Location.Y + delta
                                Dim Rect = New iTextSharp.text.Rectangle(llx, lly, urx, ury)
                                Rect.Border = iTextSharp.text.Rectangle.BOX
                                cb.SetLineWidth(1)
                                Rect.BorderWidth = 1
                                Rect.BorderColor = New BaseColor(Colors.Blue.R, Colors.Blue.G, Colors.Blue.B)
                                'cb.Rectangle(Rect)
                                'cb.Stroke()



                                ct.SetSimpleColumn(Rect)
                                For Each str As String In textlist
                                    If (hasaddeddate AndAlso textlist.IndexOf(str) = 0) OrElse (hasaddeddate AndAlso textlist.IndexOf(str) = 1) Then
                                        ct.AddElement(New Paragraph(str, markupfont))
                                    Else
                                        ct.AddElement(New Paragraph(str, textfont))
                                    End If

                                Next

                                ct.Go()
                            End If

                        Next
                    End If


Thanks a lot

Surya Kumar [Syncfusion]
Replied On August 8, 2019 12:34 PM UTC

Hi Jean Philippe, 

Greetings from Syncfusion. 

Could you please let us know how you are inserting the ink annotation in PDF, whether using PdfViewer control or if you are adding annotation programmatically using Syncfusion PDF class library.  This will be helpful in finding the root cause of the issue. 

Please note that InkList property will return the single ink point collection present in the annotation and if the annotation contains multiple ink point collection it can be retrieved from InkPointsCollection  as shown in below code snippet. 
PdfLoadedInkAnnotation inkAnnotation = loadedDocument.Pages[0].Annotations[0] as PdfLoadedInkAnnotation; 
//Returns single ink list collection 
List<float> list =   inkAnnotation.InkList; 
// Returns multiple ink list collection if present in the ink annotation 
List<List<float>> listCollection = inkAnnotation.InkPointsCollection; 


Also, let us know if the issue is visible when viewing the PDF with ink annotation in Acrobat. Kindly provide us the output PDF which will be helpful in identifying the issue. 

Regards, 
Surya Kumar 


Jean Philippe Gagliardi
Replied On August 8, 2019 03:00 PM UTC

Hi, I am using the pdf viewer in a wpf app.

Previously we were using the ink annotation tool in that app with success using the inklist property. After we needed to include freetext annotations but there was a problem that was resolved with latest releases. But when we upgraded to latest versions, freetext was working but now ink annotations inklist property is always null and even if trying to use the  inkpointscollection, the scaling of the points list is wrong. 

We are using pdfsharp library to draw the annotation on the pdf using the points list and then we remove the annotations. Rendering was perfect for ink before and now scaling is wrong as I mentionned. We were using the inklist to lineto each point and the result was amazing. Now it is unusable. After some research we found that the bounding box defined in the annotation is inverted as we think the Height and Width of the bounding box are inverted and resulting in a bad inkpointcollection.

Here is a video of the example. In this example we are using .net 4.5 and synfusion wpf pdfviewer 17.2450.0.34. Same situation happens with .39. In this example, we draw an ink annotation in the viewer, then we loop for each annotation and draw the lines with pdfsharp. After the annotation is complete, we close the loaded document and reopen it in the pdf viewer. The problem is pretty easy to see.

Thanks a lot for your support.



Attachment: ice_video_20190808104653_edit_0_a4d5b7c8.rar

Jean Philippe Gagliardi
Replied On August 8, 2019 03:03 PM UTC

If you could also please tell me if there is a way to bypass this problem, even if it means a correction of the points list.

A note: in the video, we can see that when drawing a point there is no offset. The scaling issue occurs when I am drawing an ink annotation that has a larger bounding box... maybe this is a good starting point for investigation.

Aravindh Sathiyamoorthy [Syncfusion]
Replied On August 9, 2019 04:45 PM UTC

Hi Jean, 

We have tried to reproduce the issue The scaling of the points list is wrong in our side but the behavior is working as expected. The ink annotation drawn pdf document is loaded in PdfViewerControl after saved with the InkPointsCollection comes with proper scaling. We have seen the code snippet you were using ITextSharp is used which is third party dll. We suspect this might be behavior of ITextSharp and the scaling issue occurs because of Point to Pixel conversion is not happened there for InkAnnotationCollection points. So here, we have modified the code snippet that you provided and mentioned below, 

If DirectCast(loadedPage, Syncfusion.Pdf.PdfPageBase).Annotations.Count > 0 Then 
                    Dim unitConvertor As PdfUnitConvertor = New PdfUnitConvertor() 
                    For Each a As Object In DirectCast(loadedPage, Syncfusion.Pdf.PdfPageBase).Annotations 
                    If TypeOf a Is Syncfusion.Pdf.Interactive.PdfInkAnnotation Then 
                      Dim an As Syncfusion.Pdf.Interactive.PdfInkAnnotation = DirectCast(a, Syncfusion.Pdf.Interactive.PdfInkAnnotation) 
                      cb.SetColorStroke(New iTextSharp.text.BaseColor(an.Color.R, an.Color.G, an.Color.B)) 
                      If an.InkPointsCollection.FirstOrDefault IsNot Nothing Then 
                        cb.MoveTo(an.InkPointsCollection(0)(0), an.InkPointsCollection(0)(1)) 
                        For i As Integer = 0 To an.InkPointsCollection(0).Count - 1 Step 2 
                            Dim NextX As Single = an.InkPointsCollection(0)(i) 
                            Dim NextY As Single = an.InkPointsCollection(0)(i + 1) 
                            cb.LineTo(NextX + 1, NextY + 1) 
                            cb.Stroke() 
                            cb.MoveTo(NextX + 1, NextY + 1) 
                            Next 
                    End If 

Kindly use the above code snippet and let us know whether this meets your requirement or not. 

Regards, 

Aravindh Sathiyamoorthy. 


Jean Philippe Gagliardi
Replied On August 9, 2019 05:02 PM UTC

Thanks for your reply, I think I understand the issue. Though you mention you modified the snippet by adding a PdfUnitConvertor . I do not see how you use it in this case to translate the points from InkAnnotationCollection points ?

Thanks

Aravindh Sathiyamoorthy [Syncfusion]
Replied On August 9, 2019 05:07 PM UTC

Hi Jean, 

Sorry for the inconvenience caused. Please find the code snippet below, 

If DirectCast(loadedPage, Syncfusion.Pdf.PdfPageBase).Annotations.Count > 0 Then 
                    Dim unitConvertor As PdfUnitConvertor = New PdfUnitConvertor() 
                    For Each a As Object In DirectCast(loadedPage, Syncfusion.Pdf.PdfPageBase).Annotations 
                    If TypeOf a Is Syncfusion.Pdf.Interactive.PdfInkAnnotation Then 
                      Dim an As Syncfusion.Pdf.Interactive.PdfInkAnnotation = DirectCast(a, Syncfusion.Pdf.Interactive.PdfInkAnnotation) 
                      cb.SetColorStroke(New iTextSharp.text.BaseColor(an.Color.R, an.Color.G, an.Color.B)) 
                      If an.InkPointsCollection.FirstOrDefault IsNot Nothing Then 
                        cb.MoveTo(unitConvertor.ConvertToPixels(an.InkPointsCollection(0)(0), PdfGraphicsUnit.Point), unitConvertor.ConvertToPixels(an.InkPointsCollection(0)(1), PdfGraphicsUnit.Point)) 

                        For i As Integer = 0 To an.InkPointsCollection(0).Count - 1 Step 2 
                            Dim NextX As Single = unitConvertor.ConvertToPixels(an.InkPointsCollection(0)(i), PdfGraphicsUnit.Point) 
                            Dim NextY As Single = unitConvertor.ConvertToPixels(an.InkPointsCollection(0)(i + 1), PdfGraphicsUnit.Point) 
                            cb.LineTo(NextX + 1, NextY + 1) 
                            cb.Stroke() 
                            cb.MoveTo(NextX + 1, NextY + 1) 
                            Next 
                    End If 
 

Kindly let us know if the above code snippet is meet your requirement  or not. 

Regards, 
Aravindh Sathiyamoorthy. 


Jean Philippe Gagliardi
Replied On August 9, 2019 08:25 PM UTC

Hi, I tried the solution and this is very weird...

In a sample solution with same code, results are ok. and in the original solution it does not, still scaling issue. It seems the scaling issue is related to the zoom level also...

Could you please tell me why InkList property is now always null ?

Thanks

Aravindh Sathiyamoorthy [Syncfusion]
Replied On August 12, 2019 10:28 AM UTC

Hi Jean, 
 
We are able to reproduce the issue “InkList property is always null” in our side. We have forwarded this issue to our development team for further analysis and we will update further details on 14th August 2019. 
 
Regards,
Aravindh Sathiyamoorthy. 
  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon