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

Add PDFtk wrapper to /src/pdftk #39

Open
tertek opened this issue May 30, 2024 · 4 comments
Open

Add PDFtk wrapper to /src/pdftk #39

tertek opened this issue May 30, 2024 · 4 comments

Comments

@tertek
Copy link
Contributor

tertek commented May 30, 2024

It could be useful to have a wrapper around php-pdftk that could be residing at /src/Pdftk analog to Filesystem.
Only useful if we can save code duplication though.

@tertek
Copy link
Contributor Author

tertek commented May 30, 2024

/storage
-- /documents/folder_id/document_id <> pdftk free and scan (upload)
-- /outputs/job_id/output_id <> pdftk fill and merge (document, data)
-- /tempDir

// Important: We will work with pdftk-php->getTmpFile (https://github.com/mikehaertl/php-pdftk?tab=readme-ov-file#temporary-file)

// Case create document

$fileUpload = $_FILES['pdf-upload']
$fileUpload['path']

$pdf = new Pdf($path);
$pdf->operation()->execute();
$content = $pdf->getTmpFile();

$file = $this->storage-write($content);

// case create job

$document = $this->storage->read(/documents/$folder_id / $document_id);
// if we cannot give abs path to pdftk_php, we need workaround wiht tmpfile, $tmpFfile = $document
$document_path = $this->storage->getPath($document);
$pdf = new($document_path);

$pdf->fill(..);

$size === 1 only:
$pdf->execute();
$content = $pdf->getTmpFile();

$this->storage->write(/outputs/job_id/output_uid, $content);

@tertek
Copy link
Contributor Author

tertek commented Jun 12, 2024

@edenst-TPH
I tested the file upload via form, also swapped the PSR7 Implementation and finally found out, that the problem was the VS Code Plugin Rest Client. It seems that some file types cannot be submitted or require a specific syntax that we are not aware of.

I have tested the same requests via Postman which worked fine.
I also created commented on an issue for our currently used Rest Client: Huachao/vscode-restclient#1235

Consequently, we can stay with nyholm/psr7 and test the API with Postman or another more stable client. I hope that the authors of vscode-restclient will fix it soon.

@tertek
Copy link
Contributor Author

tertek commented Jun 12, 2024

Added tests dae20cf

@tertek
Copy link
Contributor Author

tertek commented Jul 4, 2024

@edenst-TPH
I have formalized our concept for pdftk & storage from Tuesday.

pdftk & storage concept

Where is pdftk required?

  1. Initial actoion to identify form fields of a PDF.
  2. Final action of filling and flattening a PDF.

Action Summary

  1. Create Document Action:
    User sends multipart post request to create document.
  • validate request (required data, existing relations)
  • validate document (pdf format, max_limits)
  • new pdftk instance from tmp_path of upload, run pdftk --dump_form_fields
  • generate uuid
  • write to storage
  • save to database
  1. Create Job Action / Create Output Action:
    User sends field data with Post Request as part of Create Job Action.
    (job creation.. triggers output creation in some kind of queue)
  • read document from storage and write into tmp_file
  • loop through job, and do for each:
    -- new pdftk instance from tmp_file, run pdftk fill and flatten
    if n>1:
    -- keep as file in array
  • zip all files in array
    endif
  • generate output uuid
  • write to storage as final output
  • save/update database (output and job data)
  1. Stream Output Action
  • Read from Storage
  • Stream to Browser as zip (n>1) or pdf (n=1)

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

1 participant