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

PDF generation scripts #17

Merged
merged 4 commits into from
Jan 5, 2024
Merged

PDF generation scripts #17

merged 4 commits into from
Jan 5, 2024

Conversation

dcbr
Copy link
Contributor

@dcbr dcbr commented Dec 16, 2023

I think I went down the rabbithole a bit too far with this PR, so sorry for the huge diff. But I think the end result is quite nice and I learned a lot about pdf structure along the way :)

Summary:

  • Backend: A generic script is added to generate the TOB pdfs from scratch. Modifications to the original pdf files are provided for all languages (dutch, french, german and english).
  • Form changes: All textfields now have the same height (and font size).
  • Form changes: Months in the heading are now formatted with a leading zero.
  • Form changes: Extra textfields for table b (taxes with cap) are added, but not used/fillable yet at this moment. That's a first step in dealing with IBKR partial fills exported as separate trades -> TOB ceiling not taken into account #11, but the logic implementation is definitely for another PR.
  • Form changes: Extra strikethrough annotations are added to clarify the identification.
  • Form changes: The files are now PDF/A compliant after filling the PDF. The document id is also made unique for each generated pdf and the metadata is updated to reflect the proper time of creation/modification.
  • Form changes: The signature name and capacity text fields are merged, such that the capacity appears right next to the name now.
  • Form changes & frontend: The formatMoney function is changed to support "thousand separators". The fillPdf function uses '|' as the thousand separator, to bring the style closer to the original forms.
  • Frontend: language selection box to switch between the different TOB forms.

Copy link

netlify bot commented Dec 16, 2023

Deploy Preview for tobcalc ready!

Name Link
🔨 Latest commit 6d3f0b0
🔍 Latest deploy log https://app.netlify.com/sites/tobcalc/deploys/659820c566116000080d7112
😎 Deploy Preview https://deploy-preview-17--tobcalc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

const formattedDecimals = decimals < 10 ? `0${decimals}` : `${decimals}`;
export function formatMoney(value: number, currencyCode = "€", separators: {decimal?: string, thousand?: string} = {}) {
// First obtain formatted value with '.' as decimal separator and ',' as thousand separator (US notation).
let formattedValue = (Math.ceil(value) / 100).toLocaleString("en-US", {minimumFractionDigits: 2, maximumFractionDigits: 2});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the Math.ceil here, but I was wondering if this makes sense? You can't really pay a 0.1 c€ right? So I wondered if this shouldn't be replaced by Math.round or even Math.floor.

@samjmck
Copy link
Owner

samjmck commented Dec 18, 2023

Initial impressions look very good! I have exams coming up soon but will try my best to properly review the PR and merge ASAP.

@dcbr
Copy link
Contributor Author

dcbr commented Dec 18, 2023

No hurry, take your time and good luck with the exams!
The only thing I was wondering at the moment is why the tests failed; as I ran them locally (in a github codespace) and there everything worked fine. So I'm not sure what's causing the failure here.

@samjmck
Copy link
Owner

samjmck commented Dec 18, 2023

The downloading of deno dependencies sometimes throws an error for some reason.

error: TS2498 [ERROR]: Module '"deno:///missing_dependency.d.ts"' uses 'export =' and cannot be used with 'export *'.
export * from "./objects.d.ts";
              ~~~~~~~~~~~~~~~~
    at https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=types/cjs/api/index.d.ts:6:15
Error: Process completed with exit code 1.

This is despite locking the dependencies to a fixed version. I've rerun the tests and it's all fine.

@samjmck samjmck self-requested a review January 5, 2024 14:54
@samjmck samjmck merged commit 0d1810b into samjmck:master Jan 5, 2024
4 checks passed
@samjmck
Copy link
Owner

samjmck commented Jan 5, 2024

Amazing work, I really appreciate the time and effort you put into this. I received an email a few months ago asking to add different languages to the PDFs, so I'm sure many users will be happy with this PR as well. The PDF generation code seems like it would've been a real hassle to learn and write, I remember uploading the base PDF to a site to add input boxes manually. Great job!

@dcbr
Copy link
Contributor Author

dcbr commented Jan 5, 2024

Thanks, I hope it will be useful indeed :) And to be honest, I wouldn't have been able to write it entirely from scratch either. I had some experience with PDF text modifications in python already, so that helped a lot. And the pdf-lib library also does a great job to simplify a lot of things. The whole PDF specification is actually quite insane really, it keeps on surprising me whenever I learn something new about it (mostly in a bad way 😆). But it's always nice if you can get it to work properly at the end of the day :)

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

Successfully merging this pull request may close these issues.

2 participants