mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-13 03:13:58 +03:00
[Support Request]: Failed to use Export PDF #2514
Closed
opened 2026-02-05 04:22:27 +03:00 by OVERLORD
·
19 comments
No Branch/Tag Specified
development
l10n_development
release
v25-12
llm_only
vectors
v25-11
docker_env
drawio_rendering
user_permissions
ldap_host_failover
svg_image
prosemirror
captcha_example
fix/video-export
v25.12.3
v25.12.2
v25.12.1
v25.12
v25.11.6
v25.11.5
v25.11.4
v24.11.4
v25.11.3
v25.11.2
v25.11.1
v25.11
v25.07.3
v25.07.2
v25.07.1
v25.07
v25.05.2
v25.05.1
v25.05
v25.02.5
v25.02.4
v25.02.3
v25.02.2
v25.02.1
v25.02
v24.12.1
v24.12
v24.10.3
v24.10.2
v24.10.1
v24.10
v24.05.4
v24.05.3
v24.05.2
v24.05.1
v24.05
v24.02.3
v24.02.2
v24.02.1
v24.02
v23.12.3
v23.12.2
v23.12.1
v23.12
v23.10.4
v23.10.3
v23.10.2
v23.10.1
v23.10
v23.08.3
v23.08.2
v23.08.1
v23.08
v23.06.2
v23.06.1
v23.06
v23.05.2
v23.05.1
v23.05
v23.02.3
v23.02.2
v23.02.1
v23.02
v23.01.1
v23.01
v22.11.1
v22.11
v22.10.2
v22.10.1
v22.10
v22.09.1
v22.09
v22.07.3
v22.07.2
v22.07.1
v22.07
v22.06.2
v22.06.1
v22.06
v22.04.2
v22.04.1
v22.04
v22.03.1
v22.03
v22.02.3
v22.02.2
v22.02.1
v22.02
v21.12.5
v21.12.4
v21.12.3
v21.12.2
v21.12.1
v21.12
v21.11.3
v21.11.2
v21.11.1
v21.11
v21.10.3
v21.10.2
v21.10.1
v21.10
v21.08.6
v21.08.5
v21.08.4
v21.08.3
v21.08.2
v21.08.1
v21.08
v21.05.4
v21.05.3
v21.05.2
v21.05.1
v21.05
v21.04.6
v21.04.5
v21.04.4
v21.04.3
v21.04.2
v21.04.1
v21.04
v0.31.8
v0.31.7
v0.31.6
v0.31.5
v0.31.4
v0.31.3
v0.31.2
v0.31.1
v0.31.0
v0.30.7
v0.30.6
v0.30.5
v0.30.4
v0.30.3
v0.30.2
v0.30.1
v0.30.0
v0.29.3
v0.29.2
v0.29.1
v0.29.0
v0.28.3
v0.28.2
v0.28.1
v0.28.0
v0.27.5
v0.27.4
v0.27.3
v0.27.2
v0.27.1
v0.27
v0.26.4
v0.26.3
v0.26.2
v0.26.1
v0.26.0
v0.25.5
v0.25.4
v0.25.3
v0.25.2
v0.25.1
v0.25.0
v0.24.3
v0.24.2
v0.24.1
v0.24.0
v0.23.2
v0.23.1
v0.23.0
v0.22.0
v0.21.0
v0.20.3
v0.20.2
v0.20.1
v0.20.0
v0.19.0
v0.18.5
v0.18.4
v0.18.3
v0.18.2
v0.18.1
v0.18.0
v0.17.4
v0.17.3
v0.17.2
v0.17.1
v0.17.0
v0.16.3
v0.16.2
v0.16.1
v0.16.0
v0.15.3
v0.15.2
v0.15.1
v0.15.0
v0.14.3
v0.14.2
v0.14.1
v0.14.0
v0.13.1
v0.13.0
v0.12.2
v0.12.1
v0.12.0
v0.11.2
v0.11.1
v0.11.0
v0.10.0
v0.9.3
v0.9.2
v0.9.1
v0.9.0
v0.8.2
v0.8.1
v0.8.0
v0.7.6
v0.7.5
v0.7.4
v0.7.3
0.7.2
v.0.7.1
v0.7.0
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
Labels
Clear labels
🎨 Design
📖 Docs Update
🐛 Bug
🐛 Bug
:cat2:🐈 Possible duplicate
💿 Database
☕ Open to discussion
💻 Front-End
🐕 Support
🚪 Authentication
🌍 Translations
🔌 API Task
🏭 Back-End
⛲ Upstream
🔨 Feature Request
🛠️ Enhancement
🛠️ Enhancement
🛠️ Enhancement
❤️ Happy feedback
🔒 Security
🔍 Pending Validation
💆 UX
📝 WYSIWYG Editor
🌔 Out of scope
🔩 API Request
:octocat: Admin/Meta
🖌️ View Customization
❓ Question
🚀 Priority
🛡️ Blocked
🚚 Export System
♿ A11y
🔧 Maintenance
> Markdown Editor
pull-request
Mirrored from GitHub Pull Request
No Label
🐕 Support
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/BookStack#2514
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Buliwif on GitHub (Nov 29, 2021).
Attempted Debugging
Searched GitHub Issues
Describe the Scenario
Hi,
I encounter a problem when I use export-books.php :
PHP Warning: file_get_contents(http://localhost/api/books?count=100&offset=0): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/userbookstack/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/userbookstack/export-books.php:81 Stack trace: #0 /home/userbookstack/export-books.php(48): apiGetJson('api/books?count...') #1 /home/userbookstack/export-books.php(20): getAllBooks() #2 {main} thrown in /home/userbookstack/export-books.php on line 81First I have to explain my configuration, my bookstack is configured with SSL : https://bookstack.intra.local
This is the apache conf :
<VirtualHost *:443>'ServerName bookstack.intra.localServerAdmin webmaster@localhostDocumentRoot /var/www/bookstack/public/SSLEngine onSSLCertificateFile /etc/ssl/certs/bookstack.intra.local cerSSLCertificateKeyFile /etc/ssl/private/bookstack.intra.local.keyMy API Jeton is ok and this is the export-books.php file :
$apiUrl = getenv('BS_URL') ?: 'http://localhost'; // http://bookstack.local/$clientId = getenv('BS_TOKEN_ID') ?: 'ThisIsMySecret';'$clientSecret = getenv('BS_TOKEN_SECRET') ?: 'ThisIsMySecret';Exact BookStack Version
21.08.5
Log Content
No response
PHP Version
No response
Hosting Environment
Ubuntu 18.4
@ssddanbrown commented on GitHub (Nov 29, 2021):
Hi @Buliwif,
From the first part of the error message:
The script you're running is attempting to fetch from
http://localhostwhereas you're saying you have BookStack athttps://bookstack.intra.local.You either need to configure the
export-books.phpfile to set the$apiUrlas your instance base URL, Or you need to set aBS_URLenvironment variable when running the script to point at your instance.@Buliwif commented on GitHub (Nov 29, 2021):
As always, thank you for your quick response.
I forgot to say that I tried to set https://bookstack.intra.local in the export-books.php file. The result is :
PHP Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /home/userbookstack/export-books.php on line 72 PHP Warning: file_get_contents(): Failed to enable crypto in /home/userbookstack/export-books.php on line 72 PHP Warning: file_get_contents(https://bookstack.intra.local/api/books?count=100&offset=0): failed to open stream: operation failed in /home/userbookstack/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/userbookstack/export-books.php:81 Stack trace: #0 /home/userbookstack/export-books.php(48): apiGetJson('api/books?count...') #1 /home/userbookstack/export-books.php(20): getAllBooks() #2 {main} thrown in /home/userbookstack/export-books.php on line 81@ssddanbrown commented on GitHub (Nov 29, 2021):
@Buliwif Yeah, you'll get this with a self-signed certificate since it's not trusted by the instance you're running it on.
You'd either need to:
file_get_contentsreferences to disable SSL verification, As per this stackoverflow post: https://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-failed-to-enable-crypto@Buliwif commented on GitHub (Nov 29, 2021):
Thank You Dan,
I'll try it tomorrow and will tell you the result.
@Buliwif commented on GitHub (Dec 3, 2021):
Hi,
Sorry for the delay but I was focused on other kind of problem on my job :)
The HTTPS CA is already present in /etc/ssl/certs
And for the
file_get_contentssolution, I try to modify the export-books.phpInitial :
function apiGet(string $endpoint): string {global $apiUrl, $clientId, $clientSecret;$url = rtrim($apiUrl, '/') . '/' . ltrim($endpoint, '/');$opts = ['http' => ['header' => "Authorization: Token {$clientId}:{$clientSecret}"]];$context = stream_context_create($opts);return file_get_contents($url, false, $context);But I'm not sure of what I need to modify, (sorry but php is not my cup of tea... lol)
@Buliwif commented on GitHub (Dec 6, 2021):
Hi,
So I finally tried this :
1st try
Modify the
/usr/share/php/Composer/CaBundle/CaBundle.phpAnd add under
$caBundlePaths = array(:'/etc/ssl/certs/IntraLocalCA.cer'systemctl restart php7.2-fpm.service apache2.service2nd try
Modify the
/etc/php/7.2/apache2/php.iniAnd add :
curl.cainfo= '/etc/ssl/certs/IntraLocalCA.cer'openssl.cafile= '/etc/ssl/certs/IntraLocalCA.cer'openssl.capath= '/etc/ssl/certs/IntraLocalCA.cer'systemctl restart php7.2-fpm.service apache2.service@ssddanbrown commented on GitHub (Dec 6, 2021):
@Buliwif The
.inito edit can depend on the operating system, PHP version in use and how you're actually running PHP.If you're running from the command line, those changes probably won't make a difference.
Additionally, you're editing files for php7.2, whereas BookStack requires php7.3 or greater. (Assuming you're running the script on the same system as BookStack. If not, ignore this).
If you're running the scripts via command line, you can often find the right
php.inifile by running:In regards to the option of editing the script:
For this function:
f165f615fa/php-export-all-books/export-books.php (L64-L73)Disabling SSL verification would look like this instead:
@Buliwif commented on GitHub (Dec 6, 2021):
Hi Dan,
I finally found the php.ini few minutes before you wrote you message, and it works.
Thank you for taking time with me :)
Have a nice day.
@ssddanbrown commented on GitHub (Dec 6, 2021):
Awesome! Will therefore close this off.
@Buliwif commented on GitHub (Dec 7, 2021):
Just an additional question please (or do you prefer I open a new issue ?)
Lot of pdf have a size of 0Kb ans are unreadable.
And I think it's linked, I have this error message when using export-books.php :
PHP warning: file_get_contents(https://bookstack.intra.local/api/books/19/export/pdf): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /export-books.php on line 90Do you have an idea ?
@ssddanbrown commented on GitHub (Dec 7, 2021):
You'll need to check the error log of your BookStack instance as per https://www.bookstackapp.com/docs/admin/debugging/.
My guess is potentially you're getting a timeout on exporting some books.
@Buliwif commented on GitHub (Dec 7, 2021):
I think so it's a timeout cause it affect specially the biggest books, but can I easily increase this timeout ?
@ssddanbrown commented on GitHub (Dec 7, 2021):
It's likely a task of increasing the
max_execution_timevalue in yourphp.inias per https://stackoverflow.com/questions/3829403/how-to-increase-the-execution-timeout-in-php.There may also be time limits set on the webserver level.
@Buliwif commented on GitHub (Dec 7, 2021):
Thank You, I'll try this way.
@Buliwif commented on GitHub (Dec 8, 2021):
Hi,
So, now I'm sure this is a timeout cause it happens only on the 2 biggest books.
So I modify php.ini :
max_execution_time=90upload_max_files=20MI check apache and the execution time is set by default at 300 seconds.
But it still don't work,
Is there something I miss ?
@ssddanbrown commented on GitHub (Dec 8, 2021):
@Buliwif How long does it take before it times out?
You should be able to test this quickly via the standard BookStack user interface. Just export the book to PDF in the UI. Does the same actions in the background.
@Buliwif commented on GitHub (Dec 8, 2021):
It takes about 20 seconds, from interface and from cli. Far from the 90s I set in the php.ini.
@ssddanbrown commented on GitHub (Dec 8, 2021):
@Buliwif Ah, this timeout is probably for a different php.ini than the one you edited for the certificate stuff. This'll be relevant to the php.ini used by Apache. Likely the
/etc/php/<7.3 OR 7.4 OR 8.0>/apache2/php.inifile.Remember to restart apache afterwards.
@Buliwif commented on GitHub (Dec 9, 2021):
So strange...
I try to increase the both values on all my php.ini files :
max_execution_time=300upload_max_files=20MMoreover, I try to set no limit in all my php.ini files :
max_execution_time=0Another test, I add this in the export-books.php :
set_time_limit (3000);
Same result...