New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating field's default value doesn't update rendered text #84
Comments
Yeah, I'd like to have code for that, too. I haven't really looked at how that works yet. |
Hi |
I dont know if there's been any movement on this, but this would be fantastic. I'll see if I can find any relevant information in the spec. FYI this is the one I'm looking at: https://wwwimages2.adobe.com/content/dam/acom/en/devnet/pdf/PDF32000_2008.pdf |
As a workaround, I was able have the fields show up by setting an empty string to the appearance dictionary (AP):
The fields are then visible in Preview (Mac OS 10.13.4), but not Acrobat Reader DC. I suspect that Preview detects the invalid appearance dictionary and sets it to a default value. |
I have the same problem. Same experience with preview and the appearance dictionary. |
Did anyone find a solution for this? |
+1 |
I still have this problem. I'm trying to populate a few annotate fields. Some readers display the new annotate values correctly, however Adobe Reader leaves them blank. |
I have 2 documents. Copies of each other. One is a blank Form (A). The other I have filled in the first field with a number and saved it in Acrobat Reader (B). When I open B again the number shows in the field. |
If I then open B (with a value added and saved in Acrobat Reader) in the interpreter, change the value of the field and output the PDF. When I open it in Acrobat Reader the original value is still shown, but when I click on the field the NEW value is shown.
When I change the value. Making sure to use the pdfrw.PdfString object. There are no round brackets. If I try to add the round brackets when creating the value they are escaped and included in the field. Does someone who knows more about pdfrw than me know what these brackets mean? |
Characters enclosed in parentheses denotes literal string (type of PDF object). |
Thanks Peter. If I do pdfrw.PdfString.encode() then I get the brackets. Unfortunately this still doesn't make the value visible. |
@Eddiedigits I'm having the exact same issue. PDF's created and filled with pdfrw cannot be opened correctly in Adobe reader, while other PDF readers view them fine. The fields only appear while putting focus on them. See my other issue #158 . Even if I just read a pdf file and write it directly to a new file, without editing anything, all the annotate keys are added recursively. So I believe there is something wrong with the writing process of pdfrw. |
@Eddiedigits As am I. Opening the written file in Acrobat, I can only see the written fields - they are there - when focus is placed on them with mouse. Also, this only works for 2 of the 3 fields written. The 3rd, an email address, is apparently not written at all. Weird! |
You need to modify /V and also appearance stream (indirect reference object specified by /AP). /V contains value of the field and /AP specify how to present it. PDF reference 1.7 page 692
See "Tj" lines in example 8.18, it contains the text that will be displayed as default when you open pdf document (since /AP dictionary contains /N = annotation's normal appearance). I don't have time right now to investigate if it is possible to easily update appearance stream XObject using pdfrw. |
I used example pdf from #132 . Code below will add "im field_1 value" to the first text field. Please note that it's just a proof of concept rather than anything else:
See section 5 of PDF reference manual for more text formating/painting options. |
I'm trying to update the appearance stream with your code. However, I get an error:
However this results in disappearing fields in all pdf readers... |
You're correct, the error is because no appearnace stream is associated with the field, but you've created it in a wrong way. You've just assigned and stream to AP dictionary. What you need to do is to assign an indirect Xobject to /N in /AP dictionary; and you need to crate Xobject from scratch.
FYI: /Type, /FormType, /Resorces are optional (/Resources is strongly recomended). |
@PeterSlezak This works for me. I just changed the font to /TiRo because that's what is already used in my PDF and changed the stream to 1.0 1.0 Td because the number was appearing too high in the Form Field and cutting off the top half of the number. |
@PeterSlezak |
Hi @jancoow, |
All data for testing are in under link: Which field in PDF array need to by changed to get updated value to appear in new PDF? |
Hi @PeterSlezak, I got this error: I'm using this:
with |
I've got the same problem. I think the pdfrw library only deals with ASCII characters, for the message "ordinal not in range(256)". Probably it can't modify it with unicode, even though it's possible by manual typing. A solution for know may be to use reportlab. If someone has something better using pdfrw would be way more appreciated, I believe. I see that you're not using a unicode string too. try using the following:
|
@ZarakiiKenpachi |
Hi @Efk3
It should display "im field_1 value" |
Or you could use:
This adds the NeedAppearances key/value to the AcroForm dict. If I'm understanding your problem correctly.
|
@tlk3 Worked for me, thanks! |
@tlk3 That did the trick for me having the same problem with Adobe not showing the fields. |
@tlk3 that totally saved my day. Thank you! |
@tlk3 boom! works great |
@tlk3 It works for me too, thank you so much !! |
@tlk3 your solution helps very much, thanks! It also works for PyPDF2 in a similar way. However in my case I still have some fields (date field and checkboxes) that remain empty (not rendered). It seems to be a general PDF problem, not pdfrw one. |
@tlk3 It works! Thank you! |
@tlk3 |
@tlk3 Thank you! Any clue why in a big dict of items, some of the filled fields show up, and every tenth or so form some just randomly dont appear? |
TLK3's solution works with Acrobat and macOS Preview, but it doesn't work with PDFjs. If I open a file created this way with Acrobat and save it from there, it will then show the field values in PDFjs. |
Putting all your help on a simple Script, This works for me in Windows 10
|
Below is something that I threw together quick, I was able to iterate through and produce individual PDFs just fine, fields seemed visible (slightly different code). When I added the merge code in order to produce a multi-page PDF containing results of objects in Many thanks.
|
This is the second time I've bounced of pdfrw because of this issue :( The fixes above don't work for me. I've had to go back to pdftk. |
Seeing the same issue. PDF form has the values but its not displaying them till I click on these each field in a viewer. The moment I click out it goes away. Viewing the PDF in Mac on both Preview and Acrobat Reader & Pro. So in pro the form field still shows as unfilled (ie it has that blue color indicator of a unfilled form field). So I guess I need to look at pdftk or some other solution beyond pdfrw? |
@pmilano1 Yours is a slightly different issue (see here: #171) and it's regarding merging PDFs. For anyone else reading this and finding that setting the |
@tlk3 you are the best. It worked for Acrobat |
@davidmacneil Your solution works perfectly for preview in Mac. Thank you! |
@tlk3 Thank you buddy |
I had a rendering problem with my fields and I've been trying for a lot of hours to solve it. I used your help from here and the holy Stack Overflow but the problem remained. I decided to leave the AP as blank (AP='') when it was not present in the file just to see what happens. I also used Foxit Reader to open the file and everything was perfect. Even printed the pages on paper and it was correct. The same with the browser PDF reader. BUT the Adobe Acrobat did not render the text until I clicked the field and when I previewed the pages for printing, the fields were blank. Does anyone know what doesn't work well with Acrobat? Is something special needed to work properly with Adobe? |
Review a simple example I created. I spent hours to make it work. I don’t really remember what made it work. Check my samples:
https://github.com/cemoga/pdf_form_filler <https://github.com/cemoga/pdf_form_filler>
… On Aug 4, 2020, at 2:59 AM, Dimitris Athanasiadis ***@***.***> wrote:
I had a rendering problem with my fields and I've been trying for a lot of hours to solve it. I used your help from here and the holy Stack Overflow but the problem remained. I decided to leave the AP as blank (AP='') when it was not present in the file just to see what happens. I also used Foxit Reader to open the file and everything was perfect. Even printed the pages on paper and it was correct. The same with the browser PDF reader. BUT the Adobe Acrobat did not render the text until I clicked the field and when I previewed the pages for printing, the fields were blank. Does anyone know what doesn't work well with Acrobat? Is something special needed to work properly with Adobe?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#84 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AMPHAWHWPKLQHOEP6RLXX73R66WVPANCNFSM4DGK3RFQ>.
|
I'm having the same problem as others here. Everything appears fine in Preview. But Adobe doesn't display the fields till clicked. The solutions above don't seem to me to fix that. Anyone solved that yet? |
I found this blog: (https://medium.com/@vivsvaan/filling-editable-pdf-in-python-76712c3ce99) and corresponding repo (https://github.com/vivsvaan/filling_editable_pdf_python). It seems to work at least on Reader DC and chrome. I did notice that some fields don't appear filled in on preview, but that could just be me. I only tried the code an hour ago. |
Please make sure input pdf is flattern**** |
I have a pdf form filler using pdfrw and it almost works. I can fill out the form from my custom dictionary to replace blank text fields from the template form which happens to be IRS F941. But the saved from does not display the saved entries even though I have used the code to update the NeedAppearances suggested by many. My script concludes by reopening the saved file and dumps out the values that were saved but invisible so the substitution code worked. Further, when I open the form with a PDF editor, in addition to not being able to see any of the field values, when I click on any field, I get a message saying I cannot make any changes and resave the file which I was intending to do to handle the check boxes which I have not yet coded. |
I have form fields in my PDF (that make it interactive - you can fill them and print with your data). I want to programatically fill those fields based on their names (template.Root.Pages.Kids[x].Annots[y] - name in 'T', default value in 'V'). The problem is that when I do so it's updated in metadata, but the old value is displayed until I edit the PDF in some desktop editor (I can see new default value and it starts to be displayed when I make any change to this field). I'd love it to be updated as well.
Example:
The text was updated successfully, but these errors were encountered: