Possibility to export shelves #920

Open
opened 2026-02-04 22:55:04 +03:00 by OVERLORD · 4 comments
Owner

Originally created by @schuepp on GitHub (Nov 21, 2018).

First, the export feature for books is great!
But I've been asking myself if it would be possible to download not only single books, but whole shelves. So basically what I imagine is the same export function as in the book level in the shelf level.

Furthermore, a possibility to download the PDF via script would be really helpful (I'm a beginner in bash/powershell though, maybe someone could point me to the right direction here). Or is there any other way then the web UI to export a book to pdf?

Describe the benefits this feature would bring to BookStack users

  • Having a complete export of the wiki
  • Automation of exports

Additional context

declare -a arr=("book1" "book2")

for i in "${arr[@]}"
do
  wget -O /home/brute/backup/export/$i.pdf 127.0.0.1:8080/books/$i/export/pdf
done

Unfortunatly this doesnt work as intended. Maybe I'm lacking the skills though.
I'm sorry if this is not the right place for a question, feel free to close the issue if that is the case.

best regards

Originally created by @schuepp on GitHub (Nov 21, 2018). First, the export feature for books is great! But I've been asking myself if it would be possible to download not only single books, but whole shelves. So basically what I imagine is the same export function as in the book level in the shelf level. Furthermore, a possibility to download the PDF via script would be really helpful (I'm a beginner in bash/powershell though, maybe someone could point me to the right direction here). Or is there any other way then the web UI to export a book to pdf? **Describe the benefits this feature would bring to BookStack users** - Having a complete export of the wiki - Automation of exports **Additional context** ``` declare -a arr=("book1" "book2") for i in "${arr[@]}" do wget -O /home/brute/backup/export/$i.pdf 127.0.0.1:8080/books/$i/export/pdf done ``` Unfortunatly this doesnt work as intended. Maybe I'm lacking the skills though. I'm sorry if this is not the right place for a question, feel free to close the issue if that is the case. best regards
OVERLORD added the 🔨 Feature Request🏭 Back-End labels 2026-02-04 22:55:04 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Nov 22, 2018):

Thanks for the suggestion.

In regards to scripting this, I get really confused with bash syntax to be honest. I've put together a PHP script to perform the same thing:

#!/usr/bin/env php
<?php

// Base URL for your BookStack instance with no trailing slash
$bookstackBaseURL = 'https://demo.bookstackapp.com';

// Folder to store fetched exported files, Defaulted to current cmd line working directory
$exportFolder = getcwd() . '/';

// Format to export files. 'html', 'plaintext' or 'pdf'.
$exportFormat = 'pdf';

// List of book 'url-slugs' to export
$booksToExport = [
	'bookstack-user-guide',
	'dummy-content-book',
	'lorem-ipsum-dolor',
	'the-book-of-books',
];

$bookCount = count($booksToExport);
foreach($booksToExport as $i => $bookSlug) {
	echo 'Exporting book ' . ($i+1) . '/' . ($bookCount) . "\n";
	$exportUrl = trim($bookstackBaseURL, '/ ') . '/books/' . $bookSlug . '/export/' . $exportFormat;
	$exportContent = file_get_contents($exportUrl);
	$exportPath = $exportFolder . $bookSlug . '.' . $exportFormat;
	file_put_contents($exportPath, $exportContent);
}

echo "Export complete\n";

Just need to save the above in a file, Make it executable (chmod a+x ./script_name.php) then run it (php script_name.php). Will need php installed and available on cmd line. All bits you may want to configure are at the top of the file.

One issue you may face is if your instance is not public, then the export URL's won't be accessible externally.

@ssddanbrown commented on GitHub (Nov 22, 2018): Thanks for the suggestion. In regards to scripting this, I get really confused with bash syntax to be honest. I've put together a PHP script to perform the same thing: ```php #!/usr/bin/env php <?php // Base URL for your BookStack instance with no trailing slash $bookstackBaseURL = 'https://demo.bookstackapp.com'; // Folder to store fetched exported files, Defaulted to current cmd line working directory $exportFolder = getcwd() . '/'; // Format to export files. 'html', 'plaintext' or 'pdf'. $exportFormat = 'pdf'; // List of book 'url-slugs' to export $booksToExport = [ 'bookstack-user-guide', 'dummy-content-book', 'lorem-ipsum-dolor', 'the-book-of-books', ]; $bookCount = count($booksToExport); foreach($booksToExport as $i => $bookSlug) { echo 'Exporting book ' . ($i+1) . '/' . ($bookCount) . "\n"; $exportUrl = trim($bookstackBaseURL, '/ ') . '/books/' . $bookSlug . '/export/' . $exportFormat; $exportContent = file_get_contents($exportUrl); $exportPath = $exportFolder . $bookSlug . '.' . $exportFormat; file_put_contents($exportPath, $exportContent); } echo "Export complete\n"; ``` Just need to save the above in a file, Make it executable (`chmod a+x ./script_name.php`) then run it (`php script_name.php`). Will need php installed and available on cmd line. All bits you may want to configure are at the top of the file. One issue you may face is if your instance is not public, then the export URL's won't be accessible externally.
Author
Owner

@numinance commented on GitHub (Jul 31, 2020):

I wrote a little script in Python to manage a bulk download of all books. Currently I am downloading the JSON file manually as I couldn't get it to work with any authentication. I had to turn my Bookstack instance to Public as I was having issues through my VPN as well. Hopefully this helps someone:

#!/usr/bin/env python

import requests
import json
import os

#create folder to place books in
path = "./bookdump"
try:
    os.mkdir(path)
except OSError:
    print ("Creation of the directory %s failed" % path)
else:
    print ("Successfully created the directory %s " % path)
 
#define location of bookstack instance
url = 'http://demo.bookstackapp.com'

#example url for book location http://demo.bookstackapp.com/books/SAMPLEBOOKNAME/export/pdf
#JSON list of books can be obtained from http://demo.bookstackapp.com/api/books

#saved the json file in same directory as python script
jsonfile = 'books.json'
with open(jsonfile) as jsondata:
    jdata = json.load(jsondata)

#Change to the folder where the books are intended to be dumped
os.chdir(path)

#Get the book and write to file
for i in jdata["data"]:
    exporturlname= url +'/books/'+ i["slug"] +'/export/'+'pdf'
    r = requests.get(exporturlname, allow_redirects=True)
    open(i["name"]+'.pdf', 'wb').write(r.content)
    print("Exported PDF file: "+i["name"])
@numinance commented on GitHub (Jul 31, 2020): I wrote a little script in Python to manage a bulk download of all books. Currently I am downloading the JSON file manually as I couldn't get it to work with any authentication. I had to turn my Bookstack instance to Public as I was having issues through my VPN as well. Hopefully this helps someone: ``` #!/usr/bin/env python import requests import json import os #create folder to place books in path = "./bookdump" try: os.mkdir(path) except OSError: print ("Creation of the directory %s failed" % path) else: print ("Successfully created the directory %s " % path) #define location of bookstack instance url = 'http://demo.bookstackapp.com' #example url for book location http://demo.bookstackapp.com/books/SAMPLEBOOKNAME/export/pdf #JSON list of books can be obtained from http://demo.bookstackapp.com/api/books #saved the json file in same directory as python script jsonfile = 'books.json' with open(jsonfile) as jsondata: jdata = json.load(jsondata) #Change to the folder where the books are intended to be dumped os.chdir(path) #Get the book and write to file for i in jdata["data"]: exporturlname= url +'/books/'+ i["slug"] +'/export/'+'pdf' r = requests.get(exporturlname, allow_redirects=True) open(i["name"]+'.pdf', 'wb').write(r.content) print("Exported PDF file: "+i["name"]) ```
Author
Owner

@magicman32 commented on GitHub (Feb 21, 2021):

Any update on this?

@magicman32 commented on GitHub (Feb 21, 2021): Any update on this?
Author
Owner

@manicmarvin commented on GitHub (Oct 27, 2022):

I would very much like the ability to offer downloads/exports of entire shelves from the web interface to users. Same as books. Do you think you will implement this?

@manicmarvin commented on GitHub (Oct 27, 2022): I would very much like the ability to offer downloads/exports of entire shelves from the web interface to _users_. Same as books. Do you think you will implement this?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#920