GithubHelp home page GithubHelp logo

Comments (27)

pubpub-zz avatar pubpub-zz commented on August 17, 2024 1

let me have dinner!😫

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024 1

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.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024 1

Wow! Perfect. That worked. Thank you so much

from pypdf.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

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.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

Your form is in readonly. Can you remove this restriction for analysis

from pypdf.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

I've seen it but I would like to see how acrobat modifies the fields. In pdf.js the fields are visibles

from pypdf.

calixteman avatar calixteman commented on August 17, 2024

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.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

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.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

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.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

Thank you

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

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.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

what need to be modified? I am new to python, just trying understand

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

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.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

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.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

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.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

Tried it. Still no luck

Thanks

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

can you provide some test code please

from pypdf.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024
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.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

Any update?

from pypdf.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

Sorry for pushing . It is a blocker for my project.

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

any update ?

from pypdf.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

No luck. Still same

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

working for me 🤔
can you send me your output file ?

from pypdf.

thusharagokulnath avatar thusharagokulnath commented on August 17, 2024

FRA F 6180.55_1.pdf

from pypdf.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

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.

pubpub-zz avatar pubpub-zz commented on August 17, 2024

This should be part of next release

from pypdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.