Coordinate translation PdfViewer_ Canvas

Hi

I am trying to position a WPF TextBox on a point on a PDF page viewed using pdfviewer and I cannot find a way to relate the coordinates obtained through the pdfviewer_PageClicked event and the position to place the TextBox in the Canvas. Attached is the complete project and images of the difference

Thank you so much


Best Regards:

Jesús


Attachment: PDFViewAndCanvas_79963ce2.rar

10 Replies

KG Krithika Ganesan Syncfusion Team November 29, 2024 04:27 PM UTC

Hi Jesus,

 

Based on the provided details, adding a WPF TextBox to a Canvas does not persist while scrolling through the PDF pages. To better understand your requirement, could you please provide a detailed use case or clarify your specific scenario?

 

Additionally, in the WPF PdfViewer, it is possible to add a TextBox form field to the PDF at runtime. This can be achieved by utilizing the PageClicked event to determine the position where the TextBox form field should be placed within the PDF. Please let us know if you need further guidance on this.

 

Regards,

Krithika



JE Jesús November 29, 2024 04:49 PM UTC

Hi:

Thanks for the response.

The idea is that when clicking through the PageClicked event we obtain the rectangle where the text is located on the page

-hide that text using the textBox that would be positioned right on the rectangle. This TextBox, the only way I know, would be to add it from a canvas to remove it later

- Copy, extracting the text, the text in the TextBox (standard RichTextBox .

- Validate the changes made

- Delete the rectangle with the original text and rewrite it with the new text in the TextBox.

The extraction part identifying the size, color and font type of the original rectangle is done.

However I am stuck with positioning the TextBox right in the same position as the text rectangle on the PDF page.

Any help, suggestion or criticism will be welcome.


Best Regar


Jesús




KG Krithika Ganesan Syncfusion Team December 2, 2024 08:36 AM UTC

Hi Jesus,

 

At present, with the WPF PdfViewer, it is possible to dynamically add or remove a TextBox form field to a PDF document during runtime. We have adjusted the sample according to your needs. In the attached sample, users can click on the PDF pages to insert a TextBox form field at the selected position. Additionally, by clicking the button labeled 'Remove added TextBox,' the inserted TextBox will be removed from the designated page. We kindly request you to inform us if this suggestion and the accompanying sample meet your requirements.

 

Regards,

Krithika


Attachment: PDFView_8ad92086.zip


JE Jesús December 2, 2024 10:22 AM UTC

Hi  Krithika

Thanks for the information, it is a good idea and I will apply it. 

Two additional questions.

- Does the first:

 PdfTextBoxField support multilining and entering \n \r ?


- The second one  was the origin of the question:

 How do we obtain the position of the canvas corresponding to the position obtained in the PageClicked event, using args.Position?


 Thanks

Regards Jesús




JE Jesús December 2, 2024 10:32 AM UTC

Hi  Krithika

My apologies

I have consulted the API and I have seen that it is possible Multiline

. We only have original the questions of the coordinates :

How do we obtain the position of the canvas corresponding to the position obtained in the PageClicked event, using args.Position?



Thank you

regards, 

Jesús



KG Krithika Ganesan Syncfusion Team December 3, 2024 04:58 PM UTC

It is not possible to determine the position of the canvas by directly using the position obtained from the PageClicked event through the args.Position . However, an alternative approach to acquire the canvas position is by utilizing the canvas mouse down event. To assist you in understanding this method, we have included a code snippet along with a sample for your reference below.


private void mainCanvas_MouseDown(object sender, MouseButtonEventArgs e)

{

    Point mousePoint = e.GetPosition(sender as Canvas);

    MessageBox.Show("The point clicked is: " + mousePoint.ToString());

}


Attachment: CanvasSample_b5e645d4.zip


JE Jesús December 3, 2024 07:30 PM UTC

Hi  Krithika

In fact, not being able to correlate the coordinates is a problem. I am afraid that this path has no possible progress.

Thanks for the help.


Regards, Jesús





KG Krithika Ganesan Syncfusion Team December 4, 2024 11:07 AM UTC

Hi Jesus,

 

In order to incorporate and eliminate textboxes within a PDF document using the WPF PdfViewer, we have provided a sample that demonstrates how to manipulate a TextBox form field during runtime. It is feasible to extract the client point from the canvas, which can subsequently be transformed into a page point using ConvertClientPointToPagePoint. However, it is important to note that through the `PageClicked` event of the WPF PdfViewer, one can acquire the location of the components on the page. Unfortunately, at present, there are no available conversions that allow for the retrieval of the client point from the PageClicked event. Could you kindly confirm whether these recommendations align with your requirements.

 

Regards,

Krithika



JE Jesús December 4, 2024 11:44 AM UTC

Hi  Krithika:

I confirm that your recommendations are appropriate for my requirements.

Thank you!!!.


Regards,


Jesús



KG Krithika Ganesan Syncfusion Team December 5, 2024 05:30 AM UTC

We are glad to hear that our recommendations were helpful to you.


Loader.
Up arrow icon