Skip to content
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

[thanks] This looks very useful for my tax needs #6

Closed
tbrowder opened this issue Apr 7, 2020 · 9 comments
Closed

[thanks] This looks very useful for my tax needs #6

tbrowder opened this issue Apr 7, 2020 · 9 comments

Comments

@tbrowder
Copy link
Contributor

tbrowder commented Apr 7, 2020

David, thanks for all your tremendous work in this area!

I have seen your module updats reported from CPAN on #raku often and didn't think I had any use for them. I have been generating PostScript files by hand and Perl and now Raku for over 25 years and started converting the PS to pdf as soon as ps2pdf came along.

However, this year I see how your modules can help me greatly! This year, for the first time ever, I signed on with a local CPA so my wife can have financial help in the event of my demise.

He requires us to fill out detailed pdf forms so he can have controlled input for his work flow. Today, while wrestling with some tax stuff for him, I find that it would be nice if I can programmatically update some or all of his 16-page pdf form from my records via Raku filtering from csv dumps from our financial accounts. With the help of your wonderful modules I hope to have some success soon!

Blessings.

-Tom (@tbrowder)

@dwarring
Copy link
Contributor

dwarring commented Apr 8, 2020

Hi Tom,
I also came to PDF from PostScript. Was using it extensively in a mail-house before moving to a PDF based print operation.

Hope that Raku and the PDF modules can help take the pain our of form-filling. Let me know how you go.

  • David

@tbrowder
Copy link
Contributor Author

tbrowder commented Apr 8, 2020 via email

dwarring added a commit that referenced this issue Apr 8, 2020
backported from Raku FDF (WIP). In turn based on CAM::PDF's
fillpdffields.pl
@dwarring
Copy link
Contributor

dwarring commented Apr 8, 2020

Hi Tom,
I added examples/pdf-fields.raku to the repo with the last commit. Happened to have a script that I adapted unreleased module https://github.com/p6-pdf/FDF-p6

Usage is:

  • pdf-fields.raku --list <pdf> - to list fields
  • pdf-fields.raku --fill key val [key2 val2 ...] <pdf> - to populate fields

Based on fillpdffields.pl from the Perl CAM::PDF module. Which is doing a bit more with setting up field appearances.

Probably only works on text fields at the moment. Might also have more to do if CAM::PDF is doing a better job. It doing work on setting up field appearances that I have ported yet.

@tbrowder
Copy link
Contributor Author

tbrowder commented Apr 8, 2020 via email

@dwarring
Copy link
Contributor

dwarring commented Apr 9, 2020

Thanks Tom,
This PDF is useful as an example and I'm still working through it.

It illustrates the point that sometimes fields are laid out in rows and columns, and don't have useful labels. I.e. that script isn't the right approach. Could be that processing fields in tab order would work better.

Agree it's a mute point if its being manual copied! Hope they're at least cutting and pasting.

I've moved from Australia to the South Island of New Zealand, so wasn't affected by the fires this time. We're both far south.

  • David

@dwarring
Copy link
Contributor

dwarring commented Apr 9, 2020

PS was living in Melbourne when in Aussie, so was near Damien, who held some interesting talks at Melbourne PM group.

@dwarring
Copy link
Contributor

dwarring commented Apr 10, 2020

Have done some more experimentation on this. I can see what CAM::PDF is doing and why. It's not just a matter of setting the form value. The API also needs to rebuild the appearance dictionary (AP) for the updated values to display reliably on Acrobat Reader.
More work needed, I've raised #7

@dwarring
Copy link
Contributor

Hi Tom,
I've come up with a quick solution for populating form fields when the fields are arranged in a table. The fields are ordered left to right from top to bottom.

I needed to fix a bug in PDF::Class fields() method, so please upgrade to 0.4.3.

This script also sets a NeedAppearances flag and clears the field appearances (AP). I need to do this to ensure the updated values are displayed.

use PDF::API6;
use PDF::Field;
use PDF::Class:ver<0.4.3+>;

sub clear-fields-display($pdf) {
    # remove displayed values (Appearence) for each field
    .<AP>:delete for $pdf.fields;
    # dynamically display field appreances instead
    $pdf.Root.AcroForm.NeedAppearances = True;
}

sub MAIN($pdf-file, $save-as, Bool :$rebuild) {
    note "opening: $pdf-file";
    my PDF::API6 $pdf .= open: $pdf-file;

    note "clearing fields...";
    clear-fields-display($pdf);

    note "setting fields...";
    constant ColumnsPerRow = 5;
    my @page-fields = $pdf.page(1).fields;
    my $rows = @page-fields.elems div ColumnsPerRow;
    my @table-fields[$rows; ColumnsPerRow] Z= @page-fields;

    my $j = 0;
    for 1 .. $rows -> $row {
        for 1 .. ColumnsPerRow {
            @table-fields[$row-1; $_-1].V = "Row $row Col $_";
        }
    }

    with $save-as {
        note "saving: $_";
        $pdf.save-as($_, :$rebuild);
    }
    else {
        note "updating...";
        $pdf.update;
    }
}

@tbrowder
Copy link
Contributor Author

tbrowder commented Apr 14, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants