PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 19, 2024 10:25 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Jun 24, 2016 1:25 pm 
Offline

Joined: Fri Jun 24, 2016 1:20 pm
Posts: 1
Hi there,

I have posted recently a question on StackOverflow: http://stackoverflow.com/questions/38002868/pdfsharp-how-to-get-an-acrofield-position.
My intent is to get an textField from the pdf to use it as a basis to render other objects in the same column.

There goes two questions:

- Is this the best way to go? Could I replicate a line of objects somehow and insert it as a list somehow?
- If I can't, how do I pick a AcrofieldPosition inside my loop?
Code:
if (field.Name == "TxtGenerationDate")
                field.Value = new PdfString(reportData.generation_date);

if (field.Name == "TxtInitialDate")
                field.Value = new PdfString(reportData.initial_date);

if (field.Name == "TxtFinalDate")
    field.Value = new PdfString(reportData.final_date);


I wanted to do something around, like so:

Code:
if (field.Name == "TxtDate")
    var pos = GetAcroFieldPosition(field);


Any help would be appreciated.

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 26, 2016 8:58 pm 
Offline

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 36
To explain this, a little bit of background may be useful.
I will refer to public available Pdf-Reference from Adobe, found here:
http://www.adobe.com/devnet/pdf/pdf_reference.html
(The last link on the Page is the main Reference, the others explain Adobe's extensions)

First of all, an Field in a PDF (a PdfAcroField in terms of PdfSharp) is not a visual entity.
It is merely a container to store and organize data of some sort. (see Chapter 12.7 in the reference)
The visual appearance of a Field is controlled by a WidgetAnnotation.
(Chapter 12.5.6.19, but see also 12.5.2)
Both a WidgetAnnotation and an AcroField are represented by a Dictionary (a PdfDictionary in PdfSharp).
As the reference states (and that's also what i have observed), these Dictionaries may be merged together.
(in fact, from my experience, this seems always to be the case)

So, if you have the Dictionary of an AcroField, you can be quite sure, you also have the Dictionary of it's Annotation.
To get the Position and Size of a PdfAcroField you can use the following:

Code:
PdfRectangle fieldRect = myAcroField.Elements.GetRectangle(PdfAnnotation.Keys.Rect);


(Please note, the position is measured from the lower left of a Page !)
You may also be interested in the Page, where the Field resides (if you're working with multi-page documents):

Code:
PdfReference pageRef = myAcroField.Elements.GetReference("/P");
if (pageRef != null)
   PdfPage pageOfField = (PdfPage)pageRef.Value;


As another note, keep in mind, an AcroField may have child-fields, which could contain the information you're after.
So, in the case you do not find a field-rectangle or the Page for a field, make sure to also check the child-fields !

I hope, this will get you started; for more details study the reference, it's really helpful !

Regards,
Thomas


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 218 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