| PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
| Get the PDFPage that contains the PdfTextField https://forum.pdfsharp.net/viewtopic.php?f=2&t=2185 |
Page 1 of 1 |
| Author: | ase69s [ Mon Oct 29, 2012 2:27 pm ] |
| Post subject: | Get the PDFPage that contains the PdfTextField |
We need to get the PpdfPage that contains an especific PdfTextField, how can we do it? Code: PdfDocument document = PdfReader.Open("C:\\filex.pdf", PdfDocumentOpenMode.Modify); // Get the root object of all interactive form fields PdfAcroForm form = document.AcroForm; // Get all form fields of the whole document PdfAcroField.PdfAcroFieldCollection fields = form.Fields; PdfTextField textfield1= (PdfTextField)fields["textfield1"]; //how to get the correct page reference respect the especified field? PdfPage page= textfield1.Owner.Pages[???]; (we need the page reference in order to insert an image in the position where the pdftextfield is, more details: http://stackoverflow.com/questions/13120562/pdfsharp-insert-an-image-in-a-pdf-using-a-pdftextfield-as-the-position-and-size) |
|
| Author: | ase69s [ Tue Oct 30, 2012 7:49 am ] |
| Post subject: | Re: Get the PDFPage that contains the PdfTextField |
In the end we solved it creating this function: Code: protected int PaginaCampo(string campofirma, PdfDocument document) { for (int i = 0; i < document.Pages.Count; i++) { PdfAnnotations anotations = document.Pages[i].Annotations; for (int j = 0; j < anotations.Count; j++) { if (anotations[j].Title != campofirma) continue; return i; } } return -1; } Not the best solution but it works...if someone can provide a better one we will be grateful |
|
| Author: | Thomas Hoevel [ Tue Oct 30, 2012 11:03 am ] |
| Post subject: | Re: Get the PDFPage that contains the PdfTextField |
I would have tried searching document.Pages[i].Elements - so your approach is better than my idea. Thanks for your feedback. |
|
| Page 1 of 1 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|