chatgpt-exporter icon indicating copy to clipboard operation
chatgpt-exporter copied to clipboard

Export conversation as PDF

Open mbprotheweb opened this issue 1 year ago • 12 comments

Would be great if you add the option to export a conversation as PDF And it would be a lot more user friendly for a lot of situations Thank you

mbprotheweb avatar Mar 16 '23 02:03 mbprotheweb

We are running out of space to add a button!! (just kidding 😄)

image

pionxzh avatar Mar 16 '23 02:03 pionxzh

Just suggesting You can maybe leave the basics and then have something like a hover submenu for 'More' options

mbprotheweb avatar Mar 16 '23 02:03 mbprotheweb

Something like the original export menu

image

mbprotheweb avatar Mar 16 '23 02:03 mbprotheweb

Yes we might need a sub-menu for them

pionxzh avatar Mar 16 '23 02:03 pionxzh

You can just open it in html and save as pdf, no need to implement and maintain mindless features nobody needs.

Kreijstal avatar Apr 14 '23 09:04 Kreijstal

@mbprotheweb you could do something like this:

import { promises as fs } from 'fs';
import puppeteer from 'puppeteer';

async function htmlToPdf(inputFile: string, outputFile: string) {
  try {
    const htmlContent = await fs.readFile(inputFile, 'utf-8');

    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.setContent(htmlContent);
    const pdfBuffer = await page.pdf({ format: 'A4' });

    await fs.writeFile(outputFile, pdfBuffer);
    console.log(`PDF saved to ${outputFile}`);

    await browser.close();
  } catch (error) {
    console.error('Error:', error);
  }
}

// Usage
const inputFile = 'input.html';
const outputFile = 'output.pdf';
htmlToPdf(inputFile, outputFile);

Modify it to style it as you wish

ginixsan avatar Apr 21 '23 07:04 ginixsan

Both of the above are great suggestions It would just be more convenient to be able to export it directly as a pdf

mbprotheweb avatar Apr 21 '23 18:04 mbprotheweb

Thanks for all the suggestions. I will spare some time for this recently.

pionxzh avatar Apr 21 '23 18:04 pionxzh

Both of the above are great suggestions It would just be more convenient to be able to export it directly as a pdf

ok but please don't inject a giga dependency that creates PDFs as an userscript, it would be incredibly bloated, OR, make it so, that it gets imported at runtime, that way it only is loaded when you actually want to create a PDF and not everytime you refresh

Kreijstal avatar Apr 22 '23 11:04 Kreijstal

I know this script is already huge. I will try to make it dynamic load some scripts. The userscript environment is really special, so normal code splitting will not work as intended.

pionxzh avatar Apr 22 '23 12:04 pionxzh

Any news ? Also, will the resulting PDF will keep the text formatting if you copy past from the PDF back into ChatGPT ? like all the line break and stuff like that ?

Nayko93 avatar Aug 29 '23 16:08 Nayko93

I will spare some time for it this weekend. Not sure what you mean by text formatting, but the limitation of copying from PDF won't be able to be fixed by the library.

pionxzh avatar Aug 29 '23 16:08 pionxzh