Export all books to pdf #1606

Closed
opened 2026-02-05 01:24:26 +03:00 by OVERLORD · 17 comments
Owner

Originally created by @Buliwif on GitHub (Mar 24, 2020).

Hi,

Maybe this is an existant feature but I didn't found it.
Is there a way to export all books to pdf format ?

It should be great after a long work of documentation integration .

Thank you :) Bookstack is amazing

Originally created by @Buliwif on GitHub (Mar 24, 2020). Hi, Maybe this is an existant feature but I didn't found it. Is there a way to export all books to pdf format ? It should be great after a long work of documentation integration . Thank you :) Bookstack is amazing
Author
Owner

@Dayflare commented on GitHub (Mar 25, 2020):

there is a python script which can do this
https://www.reddit.com/r/selfhosted/comments/b50154/bookstack_auto_export_all/

@Dayflare commented on GitHub (Mar 25, 2020): there is a python script which can do this https://www.reddit.com/r/selfhosted/comments/b50154/bookstack_auto_export_all/
Author
Owner

@ssddanbrown commented on GitHub (Apr 1, 2020):

Hi @Buliwif,
Thanks for the request and your compliments!

Could you confirm what exact feature you desire out of these two, just to ensure I understand:

  • Export all books in your instance to a single PDF file.
  • Export all books in your instance to individual PDF files, in a single action.
@ssddanbrown commented on GitHub (Apr 1, 2020): Hi @Buliwif, Thanks for the request and your compliments! Could you confirm what exact feature you desire out of these two, just to ensure I understand: - Export all books in your instance to a single PDF file. - Export all books in your instance to individual PDF files, in a single action.
Author
Owner

@Borbosch commented on GitHub (Apr 9, 2020):

there is a python script which can do this
https://www.reddit.com/r/selfhosted/comments/b50154/bookstack_auto_export_all/

Unfortunately that tool won't work anymore and the maintainer won't respond to any issues.
The intended function of the python-tool would be great as a native function of bookstack.

Export all books in my instance to individual PDF, html or plaintext files, in a single action. Best way would be via the rest-api so that i could trigger it on my own terms (like cronjob).

The main idea behind this:
All my documentation on my infrastructure and ways to rebuild parts of it are in bookstack. Bookstack in itself works in a Dockercontainer on this infrastructure and is not accessible during maintenance or power failure.
With this feature i could generate a offline-capebable Version of the Documentation in recuring interval without the need of a working boostack-installation. This way it could be stored on an usb-stick, SD-Card or similiar which would always work in a phone oder tablet for itself.

@Borbosch commented on GitHub (Apr 9, 2020): > there is a python script which can do this > https://www.reddit.com/r/selfhosted/comments/b50154/bookstack_auto_export_all/ Unfortunately that tool won't work anymore and the maintainer won't respond to any issues. The intended function of the python-tool would be great as a native function of bookstack. Export all books in my instance to individual PDF, html or plaintext files, in a single action. Best way would be via the rest-api so that i could trigger it on my own terms (like cronjob). The main idea behind this: All my documentation on my infrastructure and ways to rebuild parts of it are in bookstack. Bookstack in itself works in a Dockercontainer on this infrastructure and is not accessible during maintenance or power failure. With this feature i could generate a offline-capebable Version of the Documentation in recuring interval without the need of a working boostack-installation. This way it could be stored on an usb-stick, SD-Card or similiar which would always work in a phone oder tablet for itself.
Author
Owner

@nmehlei commented on GitHub (Apr 13, 2020):

Also, since bookstack doesn't really have a simple "Just backup everything" functionality (yet) this export-all functionality would be kind of a nice alternative to that. True, it would not be restorable, but at least all the content "would be there and readable" if something should happen to the Bookstack instance.

@nmehlei commented on GitHub (Apr 13, 2020): Also, since bookstack doesn't really have a simple "Just backup everything" functionality (yet) this export-all functionality would be kind of a nice alternative to that. True, it would not be restorable, but at least all the content "would be there and readable" if something should happen to the Bookstack instance.
Author
Owner

@Borbosch commented on GitHub (Apr 15, 2020):

Wow! In the newest beta there is an API-Endpoint for exporting books as PDF, html and plaintext!
Thank you so much!
The only thing missing for my usecase is the "export all books via API". But i can do a workaround by first getting all book-ids by /api/books and then exporting them one by one.

@Borbosch commented on GitHub (Apr 15, 2020): Wow! In the newest beta there is an API-Endpoint for exporting books as PDF, html and plaintext! Thank you so much! The only thing missing for my usecase is the "export all books via API". But i can do a workaround by first getting all book-ids by /api/books and then exporting them one by one.
Author
Owner

@ssddanbrown commented on GitHub (Apr 15, 2020):

@Borbosch No problem, I thought I'd sneak in that feature after seeing the messages on this thread. Just shout if you want me to put together a script for going through all books and fetching the export content.

@ssddanbrown commented on GitHub (Apr 15, 2020): @Borbosch No problem, I thought I'd sneak in that feature after seeing the messages on this thread. Just shout if you want me to put together a script for going through all books and fetching the export content.
Author
Owner

@Borbosch commented on GitHub (Apr 16, 2020):

@ssddanbrown

Just shout if you want me to put together a script for going through all books and fetching the export content.

Shout! I would be grateful if you could do that!

@Borbosch commented on GitHub (Apr 16, 2020): @ssddanbrown > Just shout if you want me to put together a script for going through all books and fetching the export content. Shout! I would be grateful if you could do that!
Author
Owner

@Dayflare commented on GitHub (Apr 16, 2020):

@ssddanbrown i would appreciate that too!

@Dayflare commented on GitHub (Apr 16, 2020): @ssddanbrown i would appreciate that too!
Author
Owner

@ssddanbrown commented on GitHub (Apr 16, 2020):

@Dayflare @Borbosch Have put together an example script here:
https://gist.github.com/ssddanbrown/45acb913a7b873240b2d89781e74a7a4

Seems to work on my dev machine. Lemme know if you have any issues or are unsure about the steps required to run it.

@ssddanbrown commented on GitHub (Apr 16, 2020): @Dayflare @Borbosch Have put together an example script here: https://gist.github.com/ssddanbrown/45acb913a7b873240b2d89781e74a7a4 Seems to work on my dev machine. Lemme know if you have any issues or are unsure about the steps required to run it.
Author
Owner

@Borbosch commented on GitHub (Apr 19, 2020):

Thank you very much. Works great in my dev-enviroment.
Since i already use node-red for most of my automation, i build a flow that does mostly the same. Nonetheless i'm very thankfull!

@Borbosch commented on GitHub (Apr 19, 2020): Thank you very much. Works great in my dev-enviroment. Since i already use node-red for most of my automation, i build a flow that does mostly the same. Nonetheless i'm very thankfull!
Author
Owner

@Dayflare commented on GitHub (May 8, 2020):

@ssddanbrown thank you very much, works wonderful. I configured a cron to export all books every week, works nice and it's a good worst case security strategy.

@Dayflare commented on GitHub (May 8, 2020): @ssddanbrown thank you very much, works wonderful. I configured a cron to export all books every week, works nice and it's a good worst case security strategy.
Author
Owner

@ssddanbrown commented on GitHub (May 12, 2020):

Awesome, glad the script helped.

I think I'll close this off with the above, and since the OP never responded to the original question put forward. Exporting all books via the UI either way is going to be technically problematic as scaling issues would quickly become realised, It's best left for API cases such as the above.

@ssddanbrown commented on GitHub (May 12, 2020): Awesome, glad the script helped. I think I'll close this off with the above, and since the OP never responded to the original question put forward. Exporting all books via the UI either way is going to be technically problematic as scaling issues would quickly become realised, It's best left for API cases such as the above.
Author
Owner

@Buliwif commented on GitHub (May 19, 2020):

Hi,
I'm sorry to reopen and to be so late on my answers.
Thank you very much to make this script.

I have no knowledge of php so it don't work for me. What I do :
Generate a token on my admin profile.
Modify the begining of the script like this :
$apiUrl = getenv('BS_URL') ?: 'https://bookstack.domain.tld';
$clientId = getenv('BS_TOKEN_ID') ?: 'My tokenID';
$clientSecret = getenv('BS_TOKEN_SECRET') ?: 'My TokenSecret';

I have this result :

PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/MYUSER/exportpdf/export-books.php on line 72
PHP Warning: file_get_contents(https://bookstack.domain.tld/api/books?count=100&offset=0): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/MYUSER/exportpdf/export-books.php on line 72
PHP Fatal error: Uncaught TypeError: Return value of apiGetJson() must be of the type array, null returned in /home/MYUSER/exportpdf/export-books.php:81
Stack trace:
#0 /home/MYUSER/exportpdf/export-books.php(48): apiGetJson('api/books?count...')
#1 /home/MYUSER/exportpdf/export-books.php(20): getAllBooks()
#2 {main}
thrown in /home/MYUSER/exportpdf/export-books.php on line 81

What I'm doing wrong please ?

@Buliwif commented on GitHub (May 19, 2020): Hi, I'm sorry to reopen and to be so late on my answers. Thank you very much to make this script. I have no knowledge of php so it don't work for me. What I do : Generate a token on my admin profile. Modify the begining of the script like this : $apiUrl = getenv('BS_URL') ?: 'https://bookstack.domain.tld'; $clientId = getenv('BS_TOKEN_ID') ?: 'My tokenID'; $clientSecret = getenv('BS_TOKEN_SECRET') ?: 'My TokenSecret'; I have this result : PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/MYUSER/exportpdf/export-books.php on line 72 PHP Warning: file_get_contents(https://bookstack.domain.tld/api/books?count=100&offset=0): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/MYUSER/exportpdf/export-books.php on line 72 PHP Fatal error: Uncaught TypeError: Return value of apiGetJson() must be of the type array, null returned in /home/MYUSER/exportpdf/export-books.php:81 Stack trace: #0 /home/MYUSER/exportpdf/export-books.php(48): apiGetJson('api/books?count...') #1 /home/MYUSER/exportpdf/export-books.php(20): getAllBooks() #2 {main} thrown in /home/MYUSER/exportpdf/export-books.php on line 81 What I'm doing wrong please ?
Author
Owner

@Dayflare commented on GitHub (May 19, 2020):

@Buliwif seems like your Bookstack URL is wrong. If you run the script from the same server where bookstack is installed try http://localhost

@Dayflare commented on GitHub (May 19, 2020): @Buliwif seems like your Bookstack URL is wrong. If you run the script from the same server where bookstack is installed try http://localhost
Author
Owner

@Buliwif commented on GitHub (May 19, 2020):

I try this and it change effectively the return but I still have error :

PHP Warning: file_get_contents(http://localhost/api/books/43/export/pdf): failed to open stream: HTTP request failed! HTTP/1.0 429 Too Many Requests
in /home/myuser/exportpdf/export-books.php on line 72

But for most of my books it seems work, but files are unreadable .
thank you very much for helping me :)

@Buliwif commented on GitHub (May 19, 2020): I try this and it change effectively the return but I still have error : PHP Warning: file_get_contents(http://localhost/api/books/43/export/pdf): failed to open stream: HTTP request failed! HTTP/1.0 429 Too Many Requests in /home/myuser/exportpdf/export-books.php on line 72 But for most of my books it seems work, but files are unreadable . thank you very much for helping me :)
Author
Owner

@Dayflare commented on GitHub (May 19, 2020):

@Buliwif this is not an error from the script anymore.

Your bookstack server is blocking the connection because of too many requests while parsing the books. Try to set the rate limit higher on your server or modify the script to pause after some books and then resume.

@Dayflare commented on GitHub (May 19, 2020): @Buliwif this is not an error from the script anymore. Your bookstack server is blocking the connection because of too many requests while parsing the books. Try to set the rate limit higher on your server or modify the script to pause after some books and then resume.
Author
Owner

@Buliwif commented on GitHub (May 25, 2020):

Thank you so much.

@Buliwif commented on GitHub (May 25, 2020): Thank you so much.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1606