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

Generate PDF fail for 2.0.0-beta0 #29

Open
ywjr opened this issue May 8, 2021 · 20 comments
Open

Generate PDF fail for 2.0.0-beta0 #29

ywjr opened this issue May 8, 2021 · 20 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ywjr
Copy link

ywjr commented May 8, 2021

npx docusaurus-pdf http://localhost:3000/platformintro/intro intro.pdf

Error: The src attribute of the 'styles*.js' file could not be found!
at getScriptPathFromHTML (C:\Users\lenovo\AppData\Roaming\npm-cache_npx\5804\node_modules\docusaurus-pdf\lib\index.js:100:15)
at C:\Users\lenovo\AppData\Roaming\npm-cache_npx\5804\node_modules\docusaurus-pdf\lib\index.js:164:42
at processTicksAndRejections (internal/process/task_queues.js:93:5)

@antonygibbs
Copy link

Probably needs updating for Docusaurus 2.0.0-beta0?

@ywjr
Copy link
Author

ywjr commented May 18, 2021 via email

@ywjr
Copy link
Author

ywjr commented May 18, 2021 via email

@ywjr
Copy link
Author

ywjr commented May 18, 2021 via email

@idontknowjs
Copy link

I've been facing the same issue - is there any soultion to it?

@kohheepeace
Copy link
Owner

@CovalentBond, @ywjr Are you using docusaurus v1? This npm will create a PDF file for v1.

@antonygibbs Thanks 👍

@idontknowjs
Copy link

idontknowjs commented May 19, 2021

Thanks @kohheepeace - But I've been using the latest version 2.0.0-beta.0 only.

image

@kohheepeace
Copy link
Owner

kohheepeace commented May 19, 2021

I've noticed @ywjr have written it already.

@CovalentBond I've confirmed that https://github.com/kohheepeace/mr-pdf works correctly for v2 beta. Could you also check if mr-pdf works ? I will merge the code of mr-pdf to docusaurus-pdf.

Just run the below command.

 npx mr-pdf --initialDocsURL="https://docusaurus.io/docs" --paginationSelector=".pagination-nav__item--next > a"

📌 [Issue Fix Outlook]

  • docusaurus-pdf is whitelisting specific style files by Regex. => I think Regex is not working correctly for 2.0.0-beta.0 .
  • mr-pdf is blacklisting specific selector manually.

@kohheepeace
Copy link
Owner

@CovalentBond And docusaurus-pdf cannot generate PDF for homepage. https://zowe-docs.netlify.app/ is homepage not docs page.

@ywjr
Copy link
Author

ywjr commented May 19, 2021 via email

@kohheepeace kohheepeace added bug Something isn't working help wanted Extra attention is needed labels May 19, 2021
@kohheepeace
Copy link
Owner

kohheepeace commented May 19, 2021

@ywjr Hey, please write the issue properly as possible as you can. It distracts me from reading and dealing with issues. 😠

@idontknowjs
Copy link

idontknowjs commented May 19, 2021

@kohheepeace mr-pdf worked for v2.0.0-beta.0 site. Thank you! 🙌

My concern is I've swizzled the DocItem component as you may find here. While generating the PDF these components are also being printed:

  1. image
  2. image

Is there any way - we can prevent it

@kohheepeace
Copy link
Owner

@CovalentBond yes!😀 You can exclude unnecessary HTML elements by using --excludeSelectors

npx mr-pdf ... --excludeSelectors=".docsRating"

Is this working ?

@kohheepeace kohheepeace changed the title generate PDF fail Generate PDF fail for 2.0.0-beta0 May 19, 2021
@idontknowjs
Copy link

@kohheepeace thanks it worked! 🎉

@antonygibbs
Copy link

@kohheepeace Thanks so much for pointing out mr-pdf. I was able to get great PDF documentation from the command line npx mr-pdf --initialDocsURL="http://localhost:3000/docs/{starting-page}" --paginationSelector=".pagination-nav__item--next > a", but found that this included the 'Edit this page' icon and link. I was unable to determine how to exclude this in the parameter --excludeSelectors. Are you able to help on that detail? (I found that all other exclusions I needed happened by default 😃)

@kohheepeace
Copy link
Owner

kohheepeace commented May 19, 2021

@antonygibbs
You can use chrome devtools to detect the CSS class for 'Edit this page' icon and link.

But... there is no specific Class for this element...
image

Is this one working ?

--excludeSelectors=".margin-vert--xl a"

(I found that all other exclusions I needed happened by default 😃)

=> Yes, I've also noticed this. Maybe docusaurus added CSS for print PDF by default.
=> Or, Maybe Chrome Api has changed.

@antonygibbs
Copy link

@kohheepeace That totally worked! Thank you so much for responding to this thread today to offer assistance to us all, and the alternative of mr-pdf is great for some other teams here too, I am spreading the word!

antonygibbs added a commit to antonygibbs/docusaurus that referenced this issue May 19, 2021
Added new option for PDF generation seeing as docusaurus-pdf doesn't work beyond 2.0.0.-alpha73, as establised in [bug facebook#29](kohheepeace/docusaurus-pdf#29).
lex111 added a commit to facebook/docusaurus that referenced this issue May 25, 2021
* Update 2-resources.md

Added new option for PDF generation seeing as docusaurus-pdf doesn't work beyond 2.0.0.-alpha73, as establised in [bug #29](kohheepeace/docusaurus-pdf#29).

* Update 2-resources.md

Co-authored-by: Alexey Pyltsyn <[email protected]>
@ACavdar
Copy link

ACavdar commented Sep 21, 2022

... . I was able to get great PDF documentation from the command line npx mr-pdf --initialDocsURL="http://localhost:3000/docs/{starting-page}" --paginationSelector=".pagination-nav__item--next > a", but ....

@antonygibbs How can this command work? The command you passed above has parameter --initialDocsURL, but documentation of mr-pdf gives; --initialDocURLs (note the location of letter s) . I am really confused, help me out here. @kohheepeace @antonygibbs . The command works with parameter described in the documentation; --initialDocURLs .

I use Docusaurus 2.1.0 (tried with 2.0 beta versions first) and need to generate PDF from the documentation but, below is my adventure with no luck.

npx mr-pdf --initialDocsURL="http://localhost:3000/docs/intro" --paginationSelector=".pagination-nav__item--next > a" --excludeSelectors=".margin-vert--xl a"

error: unknown option '--initialDocsURL'

------------------------------

npx mr-pdf --initialDocURLs="http://localhost:3000/docs/intro" --paginationSelector=".pagination-nav__item--next > a" --excludeSelectors=".margin-vert--xl a"

error: required option '--contentSelector <selector>' not specified

-------------------------------

npx mr-pdf --initialDocURLs="http://localhost:3000/docs/intro" --paginationSelector=".pagination-nav__item--next > a" --excludeSelectors=".margin-vert--xl a" --contentSelector="article"

-- result: PDF generated. Only first page (intro) 

The CSS selector for next page link has also changed in 2.0 versions. It was .pagination-nav__item--next but now it is .pagination-nav__link--next .

I would appreciate your help to generate PDF with all pages in my Docusaurus documentation project.

@ACavdar
Copy link

ACavdar commented Sep 21, 2022

@idontknowjs :

Thanks @kohheepeace - But I've been using the latest version 2.0.0-beta.0 only.

image

I, too get the same error, and also with href instead of src sometimes. Did you manage to find a solution for that?
I used Docusaurus versions 2.0.0-beta.14 and 2.1.0.

@RiNaPa
Copy link

RiNaPa commented Nov 1, 2022

Is there any way I can generate pdf of site on button click instead of command line?

Repository owner deleted a comment Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants