Comments (27)
let me have dinner!😫
from pypdf.
We are only volunteers spending spare time for the benefit of the community....
a few more abs shall be added:
line 773:
font_height = abs(rct.height) - 2
line 776:
y_offset = abs(rct.height) - 1 - font_height
from pypdf.
Wow! Perfect. That worked. Thank you so much
from pypdf.
One thing I found about it is there is data on the field. It display data when I click on the field , it disappear just show the blue editable field when I move the cursor.
For me I am generating the PDF as readonly in above examples, there I cannot see the data at all
from pypdf.
Your form is in readonly. Can you remove this restriction for analysis
from pypdf.
from pypdf.
I've seen it but I would like to see how acrobat modifies the fields. In pdf.js the fields are visibles
from pypdf.
With pdf.js the values of the fields are correct because we use their V
entry. But if you try to print the pdf then the indicated fields are empty, so it's likely an issue in the appearance stream of those annotations (Acrobat and Chrome use the AS).
from pypdf.
Below is the editable pdf generated
FRA F 6180.55_2022-09-01_2022-09-30_2024-06-25_17-35-06.pdf
Looking forward for a solution asap. It is a blocker for my project deployment
Thanks
from pypdf.
I've understood : the boxes ("/Rect") are upside down Rect[1] is greater than Rect[3]. Just checking but a fix/patch should be available soon
from pypdf.
Thank you
from pypdf.
can you try to modify _writer.py line 879:
for line_number, line in enumerate(txt.replace("\n", "\r").split("\r")):
if line in sel:
# may be improved but cannot find how to get fill working => replaced with lined box
ap_stream += (
f"1 {y_offset - (line_number * abs(font_height) * 1.4) - 1} {abs(rct.width) - 2} {abs(font_height) + 2} re\n" #<------------
f"0.5 0.5 0.5 rg s\n{da}\n"
).encode()
from pypdf.
what need to be modified? I am new to python, just trying understand
from pypdf.
start the python idle,
press alt+M
open "pypdf._writer.py"
press alt+G
goto line 879
it should starts with :
f"1 {y_offset -
replace it with
f"1 {y_offset - (line_number * abs(font_height) * 1.4) - 1} {abs(rct.width) - 2} {abs(font_height) + 2} re\n" #<---------
save file, rerun your script. check result
from pypdf.
Thank you.
This line of code is in line 843, so got confused.
Even though I tried changing it and rerun the script. but not worked. still the same
from pypdf.
at line 839, you can find:
ap_stream = f"q\n
(...)
replace it with
ap_stream = f"q\n/Tx BMC \nq\n1 1 { abs(rct.width) - 1} {abs(rct.height) - 1} re\nW\nBT\n{da}\n".encode()
from pypdf.
Tried it. Still no luck
Thanks
from pypdf.
can you provide some test code please
from pypdf.
import json
import getdata
from ReadConfig import read_config
from pypdf import PdfReader,PdfWriter
import argparse
import os
from datetime import datetime
from pypdf.constants import UserAccessPermissions as UAP
todayDate = datetime.today().strftime("%Y-%m-%d_%H-%M-%S")
config = read_config()
input_pdf = f""+config['FilePaths']['input_pdf']+"FRA F 6180.55.pdf"
def fill_pdf():
try:
merger = PdfWriter()
merger.encrypt(user_password="",owner_password="",permissions_flag=UAP.PRINT)
reader = PdfReader(input_pdf)
writer = PdfWriter(clone_from=reader)
writer.set_need_appearances_writer(True)
writer.encrypt(user_password="",owner_password="",permissions_flag=UAP.PRINT)
for page in writer.pages:
writer.update_page_form_field_values(
page,
{
"RailroadName": "A" ,
"RailroadCode": "B" ,
"ReportMonthYear": "06/2024" ,
"County": "MX" ,
"ReportingOfficerName": "C" ,
"ReportingOfficerTitle": "D" ,
"ReportingOfficerAddress": "E" ,
"ReportingOfficerTelephoneNumber": "F" ,
"Date1": "" ,
"Date2": "" ,
"FreightTrainMiles": "2323" ,
"PassengerMilesOperated": "34324" ,
"YARDMILE": "23324" ,
"OtherTrainMiles": "45435" ,
"WORKERHR": "5346" ,
"PassengerTrainMiles": "65746",
"PassengersTransported": "4653" ,
"FatalEmployee": "3" ,
"FatalEmployeeNotOnDuty": "1" ,
"FatalPassengers": "4" ,
"FatalNontrespassers": "5" ,
"FatalTrespassers": "6" ,
"FatalContractor": "8" ,
"FatalContractorOher": "34" ,
"FatalVolunteer": "64" ,
"FatalVolunteerOther": "3" ,
"FatalNonTrespassersOffRailroad": "34" ,
"FatalGrandTotal": "35" ,
"NonFatalEmployee": "3" ,
"NonFatalEmployeeNotOnDuty": "5" ,
"NonFatalPassenger": "5" ,
"NonFatalNontrespassers": "34" ,
"NonFatalTrespassers": "3" ,
"NonFatalVolunteerOther": "43" ,
"NonFatalContractor": "2" ,
"NonFatalContractorOther": "64" ,
"NonFatalVolunteer": "2" ,
"NonFatalNonTrespassersOffRailroad": "23" ,
"NonFatalGrandTotal": "23" ,
"F618054": "2" ,
"F618055A": "3",
"F618056": "3",
"F618057": "4" ,
"F618081": "5" ,
"Description1": "D" ,
"Description2": "E" ,
"Description3": "F" ,
"Description4": "G" ,
"Description5": "H",
"State": "NJ"
},
auto_regenerate = False
)
merger.append(writer)
output_pdf= f""+config['FilePaths']['output_pdf']+"FRA F 6180.55_1.pdf"
with open(output_pdf , "wb") as output_stream:
merger.write(output_stream)
except Exception as e:
print(e)
fill_pdf()
Below is the input file
FRA F 6180.55.pdf
from pypdf.
Any update?
from pypdf.
Sorry for pushing . It is a blocker for my project.
from pypdf.
any update ?
from pypdf.
No luck. Still same
from pypdf.
working for me 🤔
can you send me your output file ?
from pypdf.
from pypdf.
I think it should be good now : I missed the /BBox field
for line 745
rct = RectangleObject((0, 0, abs(_rct[2] - _rct[0]), abs(_rct[3] - _rct[1])))
from pypdf.
This should be part of next release
from pypdf.
Related Issues (20)
- Broken docs link on PyPI HOT 3
- Filled Choice Fields Not Rendered Correctly By Adobe Acrobat HOT 6
- `TypeError` in `_cmap.py` when calling `extract_text()` HOT 7
- Documentation: Adding internal link code snippet is incorrect. HOT 2
- git tag was not created for 4.3.0 HOT 14
- [4.3.0] Regression when decoding strings
- PdfWriter unable to add reader HOT 8
- Paragraph field not showing correct HOT 4
- Using PdfReader causes a crash HOT 9
- Add viewport (bbox) of image rendered in the page to the FileImage class HOT 6
- `merge_page` increases file size of resulting pdf superlinearly HOT 10
- Ability to set font when updating form fields
- PdfWriter created from file stream does not work in 4.3.x (worked in 4.2.0) HOT 14
- New lines no longer included in extract_text() on 4.3 for a specific PDF file HOT 1
- PDF-Form not editable after filling out text field (after upgrade from 3.9.* to 4.3*) HOT 3
- Unhandled ZeroDivisionError in _extended_image_frombytes HOT 1
- transfer_rotation_to_content and annotations HOT 1
- Freeze/huge memory use for one page of PDF file HOT 12
- ENH: compress PDF merging identical objects
- Type hint for page.images needs adjusting HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pypdf.