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
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
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
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
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
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
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()); } |
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
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
Hi Krithika:
I confirm that your recommendations are appropriate for my requirements.
Thank you!!!.
Regards,
Jesús
We are glad to hear that our recommendations were helpful to you.