lencx / ChatGPT

🔮 ChatGPT Desktop Application (Mac, Windows and Linux)
https://nofwl.com
51.74k stars 5.81k forks source link

Export to PDF freezes #1147

Open alanosman opened 7 months ago

alanosman commented 7 months ago

Non-ChatGPT bug

Version

1.1.0

Bug description

I'm not sure if this is a feature of the desktop client or not, but when I go to export a discussion, the export freezes and never completes. I looked at chatGPT on the web, and they do not have export icons.

OS

Windows 11 pro

Environment

No response

SilenceIronMan commented 7 months ago

Yes,this is a feature of the desktop client,the export icons work via the export.js,I think it is caused by the change of gpt front-end style,try Edit Preference -> Control center ->Scripts -> export.js, remove lines 114, 143, 170 code related to 'spacer'. image

TransPete commented 7 months ago

@SilenceIronMan Your fix enabled the ExportPDF without freezing, much appreciated. With short chats the PDF correctly configures, but with long chats the text overruns max size limits and appears distorted. Cannot OCR using Adobe Acrobat Pro. Do you know of a fix to correctly format long chats? ExportPDF fix5

alanosman commented 7 months ago

Hi, @SilenceIronMan - thanks for the tip. It fixed it for me.

One thing though, it seemed like it doesn't format the text color well. image

SilenceIronMan commented 7 months ago

Hi, @SilenceIronMan - thanks for the tip. It fixed it for me.

One thing though, it seemed like it doesn't format the text color well. image

@alanosman Just add this code this.thread.style.backgroundColor = 'rgba(52,53,65,.9)'; at line 143.

SilenceIronMan commented 7 months ago

@SilenceIronMan Your fix enabled the ExportPDF without freezing, much appreciated. With short chats the PDF correctly configures, but with long chats the text overruns max size limits and appears distorted. Cannot OCR using Adobe Acrobat Pro. Do you know of a fix to correctly format long chats? ExportPDF fix5

@TransPete Maybe you can try this way, I'm not sure if this will necessarily work。 Open your PDF file, File -> Print, on the page that pops up, change the printer to "Adobe PDF" (do not do real printing), and select all pages. In the "Page Processing" section, select "Reduce to printable area" for "Page scaling method". Finally click "OK".

TransPete commented 7 months ago

@SilenceIronMan The fix did not work as it just kept processing and eventually had to be aborted due to no progress. It did however reveal that the entire download was attempting to fill a single page as illustrated below. Wonder if an instruction can be added to the ExportPDF that will have the PDF paginate correctly. image

SilenceIronMan commented 7 months ago

@SilenceIronMan The fix did not work as it just kept processing and eventually had to be aborted due to no progress. It did however reveal that the entire download was attempting to fill a single page as illustrated below. Wonder if an instruction can be added to the ExportPDF that will have the PDF paginate correctly. image

@TransPete Try this way,edit Preference -> Control center ->Scripts -> export.js. Relpace the function handlePdfwith my code: (But there will be small flaws in font segmentation.)

async function handlePdf(imgData, canvas, pixelRatio) {
    const { jsPDF } = window.jspdf;
    var contentWidth = canvas.width
    var contentHeight = canvas.height
    var pageHeight = contentWidth / 592.28 * 841.89
    var leftHeight = contentHeight
    var position = 0
    var imgWidth = 595.28
    var imgHeight = 592.28 / contentWidth * contentHeight
    var pdf = new jsPDF('', 'pt', 'a4')
    if (leftHeight < pageHeight) {
        pdf.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight, '', 'FAST');
    } else {
        while (leftHeight > 0) {
            pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight, '', 'FAST');
            leftHeight -= pageHeight
            position -= 841.89
            if (leftHeight > 0) {
                pdf.addPage()
            }
        }
    }
    const data = pdf.__private__.getArrayBuffer(pdf.__private__.buildDocument());
    const name = `ChatGPT_${formatDateTime()}.pdf`;
    await invoke('download_file', { name: name, blob: Array.from(new Uint8Array(data)) });
  }
alanosman commented 7 months ago

Hi @SilenceIronMan - I re-synced with the remote script and added this script. This seems to have fixed the issue.

TransPete commented 7 months ago

@SilenceIronMan I replaced the code but when reloaded, no longer found the "ExportPDF" button displayed in the bottom of the left sidebar. Re-synced the export.js script thinking I might have mis-pasted your code, but on restart, still cannot find the ExportPDF button. Don't know ".js" language, don't know what happened to the Export buttons! Suggestions?

SilenceIronMan commented 7 months ago

@SilenceIronMan I replaced the code but when reloaded, no longer found the "ExportPDF" button displayed in the bottom of the left sidebar. Re-synced the export.js script thinking I might have mis-pasted your code, but on restart, still cannot find the ExportPDF button. Don't know ".js" language, don't know what happened to the Export buttons! Suggestions?

@TransPete It may be that the css style has changed. I will give you a copy of my file tomorrow.

TransPete commented 7 months ago

@SilenceIronMan That will be much appreciated. Don't know when the buttons disappeared. Only thought is they might have been hidden due to problems with execution. Many thanks for your kind assistance.

alanosman commented 7 months ago

@SilenceIronMan - @TransPete is right. Now all my export buttons are gone after a restart. Whoops.

TransPete commented 7 months ago

@SilenceIronMan Thank you for the confirmation that I'm not alone @alanosman . Was beginning to think that not only ChatGPT is subject to hallucinations!

SilenceIronMan commented 7 months ago

@TransPete @alanosman Replace your content. export.txt

mjweav commented 7 months ago

Bless you, i just discovered that my favorite feature of export (the only way I have found to do this especially to .md) HAD Disappeared, then i saw everyone complaining about the accidental use and thought that it had been Erased as a feature (Please do not do that). I just updated with the export.txt in the previous post and all is well again. Thanks for that.

alanosman commented 7 months ago

@SilenceIronMan thank you. Looks like both export works and the icons are back.

Question on the username, why "Silence" with IronMan? :-)

TransPete commented 7 months ago

@SilenceIronMan Replaced the entire export.js file with the new code and most happy to see the icons re-appear. However, when I selected a chat and pressed the PDF button, the PDF that downloaded was dark and unreadable. Hope springs eternal. PDF export fail 3

TransPete commented 7 months ago

@SilenceIronMan Tried ExportPDF again and no joy. Have to Quit ChatGPT and restart to get out of the loop. PDF export fail 4

Luke717 commented 6 months ago

I tried the suggested solutions here but could not get a PDF to have anything other than the dark background. I decided to ask ChatGPT for a solution - and it provided one! I've shared the specific chat here but the solution is simple:

Change Background Color in fixLocation Method: Modify the background color set in line 168 of the fixLocation method to a lighter color or the color you desire for your PDF background. For instance, setting it to a white background can be done by changing rgba(52,53,65,.9) to rgba(255,255,255,1).

https://chat.openai.com/share/181204c5-8063-48d5-97db-84006619d9b2

Also attached is the PDF export of that chat - with a white background. ChatGPT_2023_12_25-111446.pdf