batch download all pdf from one template

WooCommerce
19 March, 2023 02:11:43
j.durand
Topics: 8
Messages: 29
Hi,

I'm trying to create a plugin to download / save all the pdfs at once, for one template.
The template is used on wooc products. User can clic on the download shortcode to create a pdf with product infos.
My plugin creates a button in a custom admin page to batch generate all the pdfs and save them into a custom folder into /wp-uploads/. And a shortcode to display them on a front end page. It works but all the pdfs are 0 octets and are not readable...
Can you give some clues to achieve this please?

regards
19 March, 2023 03:41:03
E2Pdf
Support
Topics: 7
Messages: 3345
Hi,

"Bulk" export is available in the RC version: https://e2pdf.com/support/desk/how-to-update-plugin-to-rc-release-candidate-version-from-e2pdf-com at "E2Pdf" -> "Export" -> "Bulk Export".

However, if you still need your functionality we need to see the code that generates PDFs and the code that outputs it on a front-end page. You can share it on some 3rd party code share website or copy it to a file, zip and attach it to the next message. You can mark "message" private so only we can see the message.
We would really appreciate your feedback at WordPress.org!
19 March, 2023 12:45:59
j.durand
Topics: 8
Messages: 29
Hi,
The bulk option is perfect for my needs! Can you tell me where the file are stored. I manually import the files into a custom folder, but maybe I can use the same as the bulk function does?
thank you for the quick help!
19 March, 2023 13:17:30
E2Pdf
Support
Topics: 7
Messages: 3345
It creates a unique folder and zip with the unique name under wp-content/uploads/e2pdf/bulks/

It has some complex functionality due generation via "cron" so it seems the best way can be for us to add some additional filter to which you can connect your functionality to get the "zip" as soon as it will be finished export. Will it fit your needs? If so, we will add it next week.
We would really appreciate your feedback at WordPress.org!
20 March, 2023 06:16:02
E2Pdf
Support
Topics: 7
Messages: 3345
Hi,

We currently released an update to the RC version (1.19.20) with additional actions.

See please example usage: https://collabedit.com/xt867

If it still will not fit your needs, let us know please so we can provide you some solution to create a "bulk" export from your function.

We remain at your service.
We would really appreciate your feedback at WordPress.org!
21 March, 2023 01:36:45
j.durand
Topics: 8
Messages: 29
Hi,
Thank you for the update and for sharing your code!
What I have done:

I have created a custom action hook that triggers when the E2Pdf bulk export process is completed, and a ZIP file containing the generated PDFs is created.

The code performs the following steps:

Define the destination directory where the ZIP file will be moved and its content extracted.

If the destination directory doesn't exist, it creates the directory with appropriate permissions.

Move the generated ZIP file to the destination directory.

Open the ZIP file and iterate through each file in the archive. Before extracting each file, the code checks if a file with the same name already exists in the destination directory.

If a file with the same name exists, it deletes the existing file using the 'unlink()' function.

Extract the file from the ZIP archive to the destination directory, effectively overwriting any existing files with the same name.

Close the ZIP archive.

Optionally, delete the moved ZIP file after successful extraction.

The code ensures that the generated PDFs from the E2Pdf bulk export process are moved to the specified directory and extracted, overwriting any existing files with the same name in the destination directory.

Now my plugin can display all files from the new folder. The pdfs will be updated each time I bulk export them.

Many thanks. Telle me if you want to see the function.

best regards