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

Browser extension #60

Open
paritosh149 opened this issue Oct 22, 2018 · 12 comments
Open

Browser extension #60

paritosh149 opened this issue Oct 22, 2018 · 12 comments
Labels
Feature New feature or enhancement

Comments

@paritosh149
Copy link

I tried and found percollate a very useful tool. However, I would love to use it within html pages for on-demand creation of html page to pdf.
How can I run percollate from within browser instead of node or command-line?

@danburzo danburzo added the Feature New feature or enhancement label Oct 22, 2018
@danburzo
Copy link
Owner

I'd love it if someone could find a way to invoke percollate from the browser. It's sort of beyond the scope of this package, and I don't foresee an easy solution, but I'm keeping this open just in case someone wants a challenge :-)

@danburzo danburzo added the Available This issue is up for grabs label Oct 22, 2018
@yashha
Copy link
Contributor

yashha commented Oct 22, 2018

Here would be a draft for a web api, feel free to fork
https://github.com/yashha/percollate-api

@paritosh149
Copy link
Author

Web Api would still be a server side solution which would require web connectivity.. how can percollate be used to generate pdf within an offline web app?

@jasonslyvia
Copy link

just start the web server on localhost, and make a simple browser extension or even just a bookmarklet to send a HTTP request to localhost will do the job

@paritosh149
Copy link
Author

That surely cannot be an offline solution after all. There could be a way to run percollate within browser's javascript engine without HTTP. Let's explore.

@yashha
Copy link
Contributor

yashha commented Oct 28, 2018

You would need an alternative to puppeteer to run it fully offline on clientside.
It creates currently the pdf from the parsed html.

@yashha
Copy link
Contributor

yashha commented Dec 8, 2018

Maybe this
https://github.com/MrRio/jsPDF

@yashha
Copy link
Contributor

yashha commented Dec 15, 2018

This also supports links:
https://github.com/eKoopmans/html2pdf

I made a bookmarklet draft.
https://gist.github.com/yashha/8c3f7e34f5865bd77b326167fc281e79
I hope I have time in a week to improve it.
And push it to github.

@yashha
Copy link
Contributor

yashha commented Dec 15, 2018

At the moment it is just this:
Bundled with parcel.

// import jsPDF from 'jspdf';
// import PDFObject from 'pdfobject';
import Readability from './vendor/readability';
import html2pdf from 'html2pdf.js';

const savePage = () => {
    const article = new Readability(document).parse();
    const html = `<h1>${article.title}</h1> <br> ${article.content}`;

    // const doc = new jsPDF();
    // doc.fromHTML(html, 15, 15, {
    //     'width': 170
    // });
    //
    // if (typeof doc !== 'undefined') try {
    //     const string = doc.output('datauristring');
    //     PDFObject.embed(string, document.getElementById("preview-pane"));
    // } catch(e) {
    //     alert('Error ' + e);
    // }
    const opt = {
        margin:       0.4,
        filename:     article.title + '.pdf',
        image:        { type: 'jpeg', quality: 0.98 },
        html2canvas:  { scale: 2 },
        jsPDF:        { unit: 'in', format: 'a5', orientation: 'portrait' }
    };
    html2pdf().set(opt).from(html).save();
};
savePage();

@yashha
Copy link
Contributor

yashha commented Dec 22, 2018

The disadvantage is that
https://github.com/MrRio/jsPDF and https://github.com/eKoopmans/html2pdf
don't render it so that the text is selectable/searchable.

@danburzo danburzo changed the title How can I run percollate from within browser instead of node or command-line? Browser extension Oct 8, 2021
@danburzo
Copy link
Owner

danburzo commented Oct 8, 2021

At the moment, from what I understand, a browser extension would be able to:

  • Grab the URL of the current tab (or of all open tabs)
  • Generate HTML and EPUB files out of these URLs
  • From the HTML, on macOS/iOS/iPadOS, you can invoke the native "Print to PDF" feature.

So it sounds like it could be interesting to prototype as an universal browser extension that works on Firefox/Chrome/Safari/Edge.

@danburzo danburzo removed Available This issue is up for grabs Discussion labels Oct 8, 2021
@paritosh149
Copy link
Author

  1. Browser extension is installed and run based on user's approval and config, however, if a webapp needs to generate pdf / epub for a HTML, it must not rely on browser extension and initialize and run the utility within the webapp's scope.
  2. Also, is it possible to generate pdf / epub from a DOM element as root and/or shadow DOM root element?

@danburzo danburzo mentioned this issue May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants