docusaurus-pdf icon indicating copy to clipboard operation
docusaurus-pdf copied to clipboard

Generate PDF fail for `2.0.0-beta0`

Open ywjr opened this issue 3 years ago • 20 comments

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)

ywjr avatar May 08 '21 00:05 ywjr

Probably needs updating for Docusaurus 2.0.0-beta0?

antonygibbs avatar May 18 '21 13:05 antonygibbs

Sorry, I can't link to GitHub now. I can't reply  you directly  

Sorry, I can't link to GitHub now. I can't answer you directly

I have tested 2.0.0-beta.0 and 2.0.0-alpha.73, and the test results are as follows

  1. PDF file can be generated on 2.0.0-alpha.73,

2。 However, it failed to run on 2.0.0-beta.0. It can't generate PDF. The failure information is like the above post.

------------------ 原始邮件 ------------------ 发件人: "kohheepeace/docusaurus-pdf" @.>; 发送时间: 2021年5月18日(星期二) 晚上9:58 @.>; @.@.>; 主题: Re: [kohheepeace/docusaurus-pdf] generate PDF fail (#29)

Probably needs updating for Docusaurus 2.0.0-beta0?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

ywjr avatar May 18 '21 14:05 ywjr

Sorry, I can only reply by mail now。

I suggest another function:

Multiple MD files are merged and generated into a PDF file

------------------ 原始邮件 ------------------ 发件人: "kohheepeace/docusaurus-pdf" @.>; 发送时间: 2021年5月18日(星期二) 晚上9:58 @.>; @.@.>; 主题: Re: [kohheepeace/docusaurus-pdf] generate PDF fail (#29)

Probably needs updating for Docusaurus 2.0.0-beta0?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

ywjr avatar May 18 '21 14:05 ywjr

------------------ 原始邮件 ------------------ 发件人: "kohheepeace/docusaurus-pdf" @.>; 发送时间: 2021年5月18日(星期二) 晚上9:58 @.>; @.@.>; 主题: Re: [kohheepeace/docusaurus-pdf] generate PDF fail (#29)

Probably needs updating for Docusaurus 2.0.0-beta0?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

ywjr avatar May 18 '21 15:05 ywjr

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

idontknowjs avatar May 18 '21 23:05 idontknowjs

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

@antonygibbs Thanks 👍

kohheepeace avatar May 19 '21 09:05 kohheepeace

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

image

idontknowjs avatar May 19 '21 10:05 idontknowjs

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 avatar May 19 '21 10:05 kohheepeace

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

kohheepeace avatar May 19 '21 10:05 kohheepeace

    the test results are as follows

  1. PDF file can be generated on v2.0.0-alpha.73,

2。 However, it failed to run on v2.0.0-beta.0. It can't generate PDF. 

The failure information is like the above post.

------------------ 原始邮件 ------------------ 发件人: "kohheepeace/docusaurus-pdf" @.>; 发送时间: 2021年5月19日(星期三) 下午5:56 @.>; @.@.>; 主题: Re: [kohheepeace/docusaurus-pdf] generate PDF fail (#29)

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

@antonygibbs Thanks 👍

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

ywjr avatar May 19 '21 10:05 ywjr

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

kohheepeace avatar May 19 '21 10:05 kohheepeace

@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

idontknowjs avatar May 19 '21 10:05 idontknowjs

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

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

Is this working ?

kohheepeace avatar May 19 '21 10:05 kohheepeace

@kohheepeace thanks it worked! 🎉

idontknowjs avatar May 19 '21 11:05 idontknowjs

@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 😃)

antonygibbs avatar May 19 '21 14:05 antonygibbs

@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.

kohheepeace avatar May 19 '21 14:05 kohheepeace

@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 avatar May 19 '21 14:05 antonygibbs

... . 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 avatar Sep 21 '22 12:09 ACavdar

@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.

ACavdar avatar Sep 21 '22 12:09 ACavdar

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

RiNaPa avatar Nov 01 '22 14:11 RiNaPa