PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Wed Dec 17, 2025 2:43 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Oct 29, 2012 2:27 pm 
Offline

Joined: Mon Oct 29, 2012 2:23 pm
Posts: 2
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)


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2012 7:49 am 
Offline

Joined: Mon Oct 29, 2012 2:23 pm
Posts: 2
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 :D


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 30, 2012 11:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3139
Location: Cologne, Germany
I would have tried searching document.Pages[i].Elements - so your approach is better than my idea.
Thanks for your feedback.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 335 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group