-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
PDF Download #969
Comments
Could we use something like |
Sorry I may have explained poorly. I believe react-pdf will render pdf's on the webpage. What I'm thinking would be a way to export your documents to a pdf as an additional format. Like sphinx has PDF generation via LaTeX |
We could also achieve this with html2canvas module I think. There are a few ways to do that. However I am not sure which one would be the optimal way. If there is interest in it I assume I could take a look. |
It might be possible to generate PDFs during the build using something like pandoc and then serve them with the document. |
Concatenate markdowns, parse with pandocs to pdf? |
We could use something like markdown-pdf to create pdf documents for markdown files during the build process and serve them. The URL for each pdf would be the same as the document one but with an extension ".pdf". For translated documents too. We could also make this feature as optional and turned off as a default based on some siteConfig key. I can take a look into it if it's still a requested feature. |
Please may you go into some more detail as to how I could implement this? |
Apologies for replying late. If you want to understand my approach, start by learning about Travis and see how to convert markdown to pdf using pandoc. What I am essentially doing is whenever I make a commit to my docusaurus site, my Travis script converts those markdown files (which are listed in sidebars.json) to pdf then simply merge them and push it to my other repository. |
Would love to see this feature! |
Actually React-pdf can do the job. We need to work on it |
Lack of this feature, or single-page output, is why my company has to move away from Docusaurus. |
@braco thanks for the feedback. What will you be moving to? |
@yangshun Hi I implemented node script to generate pdf file through docs. This is generated PDF: https://drive.google.com/file/d/19P3qSwLLUHYigrxH3QXIMXmRpTFi4pKB/view Asking
ApproachI immitated mdx-deck approach. Author needs to manually generate and serve pdf at local by this approach.
*Discussion about this approach: jxnblk/mdx-deck#141 Demo
|
@kohheepeace could you explain what oss stands for in this context? I´m new to docusaurus and looking for a way to export docs as PDF so I tried your demo code-snippet. Unfortunately, the structure of my project initialized with Thank you for sharing and working on this project! |
Hi, @maxarndt, sorry for my bad explanation "oss site" stands for https://github.com/facebook/docusaurus. If you just made site by runnning You need to specify initial url to start scraping. Then, Puppeteer automatically paginates and generates PDF. I hope it will work in your environment! |
@maxarndt I made npm package for generating PDF. |
Hi Kohhee. I was trying to install your npm package and it was failing during the following install process. I am also rather new on Docusaurus and pdf translations, so thanks in advanced: make: *** [Release/obj.target/hummus/src/PDFDictionaryDriver.o] Error 1 |
@jonsanjuan Thanks for your report! I think it is better to talk about this in my repo. Could you post issue in my repo? |
will do |
guys...I am not able to convert static pages created through Docusaurus to pdf...can you please help |
I really like @kohheepeace solution and especially has the opportunity to load mdx components too in a way pure pandoc+md can not. I managed to get it running very quickly which is great. I think pandoc, if it is your solution, might also be a good option too, but is a bit harder to setup If you simply run like
This looks reasonably good, has a classic "academic paper" style latex font, but it lacks the ordering. I wanted to get some nice ordering and make it use sort of the "sidebar.json" ordering from the docusaurus I made this small command/bash script
Note the title.md at the bottom, I put it there since I don't want the title's header stripped off It adds, in addition to everything that docusaurus docs have, a special title.md which just contains these contents The title.md file:
Read_sidebar.js looks like
This just reads a sidebar.json and outputs the list of files to read, in the order that they are specified in the sidebar.json If you have substructure in your sidebar like different sections I recommend making something like this
This produces a nice table of contents where each section that corresponds to a section of the sidebars.json also gets a section in the pdf table of contents Example from our docs https://jbrowse.org/jb2/jbrowse2.pdf (from https://jbrowse.org/jb2/docs/) |
Hi @kohheepeace very cool tool! Do you have plans to turn that into a Docusaurus plugin? I believe you just need to hook into |
@Josh-Cena thanks for your proposal. I'm currently busy on another project, so I can't implement this as soon as possible. docusaurus-pdf and mr-pdf are MIT license so please feel free to fork or create completely as another project 👍 |
Here is an interesting solutions built into the CI process. I did not try but it depend on Prince which is almost like $4k a pop to license! Also found https://www.npmjs.com/package/docusaurus-plugin-papersaurus?activeTab=readme which I did test and it looked promising up until no pdfs were generated as I described in my issue to that project here. Pdf generation is pretty important to have in a documentation project like this. A bit surprised its not among the first features. First time testing docusaurus and part of the requirements I have is to generate a PDF so I guess I'll have to try a method outside of docusaurus. If I can get something working I'll try to create a plugin. |
Someone recently submitted this package to our community resources: https://github.com/jean-humann/docs-to-pdf |
For anyone desperate for documentation tools with advanced PDF export, I found |
Is this feature fully stalled or is anyone planning to work on it? |
@intergalacticmammoth this worked for me; minor update to @kohheepeace's comment above. Requires const puppeteer = require('puppeteer');
const { PDFRStreamForBuffer, createWriterToModify, PDFStreamForResponse } = require('muhammara');
const { WritableStream } = require('memory-streams');
const fs = require('fs');
const mergePdfBlobs = (pdfBlobs) => {
const outStream = new WritableStream();
const [firstPdfRStream, ...restPdfRStreams] = pdfBlobs.map(pdfBlob => new PDFRStreamForBuffer(pdfBlob));
const pdfWriter = createWriterToModify(firstPdfRStream, new PDFStreamForResponse(outStream));
restPdfRStreams.forEach(pdfRStream => pdfWriter.appendPDFPagesFromPDF(pdfRStream));
pdfWriter.end();
outStream.end();
return outStream.toBuffer();
};
let generatedPdfBlobs = [];
(async () => {
const browser = await puppeteer.launch({ headless: true });
let page = await browser.newPage();
let nextPageUrl = 'http://localhost:3000/docs/introduction';
const outputFileName = 'output.pdf';
while (nextPageUrl) {
console.log('Processing page:', nextPageUrl);
await page.goto(nextPageUrl, { waitUntil: 'networkidle2' });
try {
nextPageUrl = await page.$eval('a.pagination-nav__link--next', (element) => element.href);
} catch (e) {
console.log(`No next page found. Saving to ${outputFileName}...`);
nextPageUrl = null;
}
try {
await page.waitForSelector('article');
let html = await page.$eval('article', (element) => element.outerHTML);
await page.setContent(html);
} catch (e) {
console.warn('Article not found on this page, skipping.');
continue;
}
await page.addStyleTag({ url: 'http://localhost:3000/styles.css' });
await page.addScriptTag({ url: 'http://localhost:3000/main.js' });
const pdfBlob = await page.pdf({
path: "",
format: 'A4',
printBackground: true,
margin: { top: 20, right: 15, left: 15, bottom: 20 },
});
generatedPdfBlobs.push(pdfBlob);
}
await browser.close();
const mergedPdfBlob = mergePdfBlobs(generatedPdfBlobs);
fs.writeFileSync(outputFileName, mergedPdfBlob);
console.log(`Saved merged PDF to ${outputFileName}`);
})(); |
🚀 Feature
The ability for users to download an offline version of the document.
This would be ideal as a PDF with title page and table of contents.
Have you read the Contributing Guidelines on issues?
Yes
Motivation
Interested in using this as a documentation solution for client producs but PDF for print is required by some.
Pitch
A download button could be added to the top of the side nav which when clicked on could would download the file.
The text was updated successfully, but these errors were encountered: