PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Dec 11, 2017 6:48 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Sep 29, 2016 5:16 pm 
Offline

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 17
While working on AcroFields, i stumbled over a problem when setting a PdfStream's Value.

The problem manifested as described here: viewtopic.php?f=2&t=894
e.g. Field-Values did not show up in the Reader-Application (Foxit in my case), until you click inside the Field.

In my case the problem could be traced down to this:
- I opened an existing Document in modify-mode to fill existing Form-Fields
- Setting the Text-Property of a PdfTextField created a new Appearance-Stream with the RenderAppearance method
- Stream-Data was put into existing /AP - Entry

The last step is the important bit.
As the Field already had an Appearance-Dictionary, the existing value was simply overwritten.
The problem was, there was a /Filter - Entry present in the dictionary with a value of /FlateDecode...

I assume, the Reader-Application tried to decode the stream with the FlateDecode-Filter but failed, (because the data was NOT encoded) hence not displaying the Text written into the Field.

The proposed fix is to either respect the existing filter or to remove the /Filter - Entry.

I resorted to simply remove the /Filter - Entry from the parent-dictionary with this line at the end of the setter (PdfStream.Value)

Code:
this.owner.elements.Remove(Keys.Filter);


This fixed it at least for me, Field-Values were now showing up correctly when opening the document.


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 24, 2016 11:58 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2740
Location: Cologne, Germany
(void) wrote:
The proposed fix is to either respect the existing filter or to remove the /Filter - Entry.
I think it is a feature, not a bug: when setting a property (e.g. Text) you have to make sure that all related properties (Filter in this case) also get set accordingly.
You can also assign a filtered object to the Text property.

I think it would be nice to have a helper method that sets both Text and Filter at the same time.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 07, 2016 10:34 pm 
Offline

Joined: Tue Sep 30, 2014 12:29 pm
Posts: 17
Quote:
I think it is a feature, not a bug: when setting a property (e.g. Text) you have to make sure that all related properties (Filter in this case) also get set accordingly.
You can also assign a filtered object to the Text property.

I think, we might have a misunderstanding here.
Why should the average user had to deal with filters and the like, when setting the "Text"-Property of a PdfTextField ?
What kind of "filtered object" should that be ?

To clarify my point, the code-flow that leads to the problem:
- user sets the Text-Property of a PdfTextField
- from the PdfSharp sources, the Setter of the Text-Property :
Code:
set { Elements.SetString(Keys.V, value); RenderAppearance(); } //HACK in PdfTextField

- RenderAppearance creates a new ApperanceStream (or uses the existing one) and sets its value :
Quote:
xobj.Stream.Value = new RawEncoding().GetBytes(s);

The last line may cause a problem when the Stream already exists with a filter present.

This all happens inside of PdfSharp, so i thought, i point this out.

Quote:
I think it would be nice to have a helper method that sets both Text and Filter at the same time.

I agree, but not so much for the Text-Property of a PdfTextField, but more for the Value-Property of a PdfStream.
Setting the Text-Property should be a transparent operation for the user.


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 1 guest


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:  
Powered by phpBB® Forum Software © phpBB Group