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

[Bug] Download file (.md/.pdf) is working, but the 'open_file' command fails #242

Closed
merrickw opened this issue Jan 23, 2023 · 7 comments
Closed
Labels
bug Something isn't working

Comments

@merrickw
Copy link

Version

v0.9.2

Bug description

I think the issue here, on Windows machines, in the open_file command, the path argument contains a mix of forward and back slashes. The Open_file command then just opens an Explorer window to a default path, and not the file just downloaded.

Example, from my log file I see:
open_file: C:\Users\MXX.chatgpt\download/pdf/fq2fbm.pdf

I think this fails because of the forward slashes - this is my guess.

OS

Windows 10

Environment

No response

@merrickw merrickw added the bug Something isn't working label Jan 23, 2023
lencx added a commit that referenced this issue Jan 24, 2023
@lencx
Copy link
Owner

lencx commented Jan 25, 2023

Please try v0.10.0

@merrickw
Copy link
Author

Just tried it - the correct folder now opens, but the file does not;
Checking the logs:

[2023-01-25][02:57:17][chatgpt::utils][�[9INFO�[0m] open_file: C:\Users\xxxx\.chatgpt\download\pdf\1n4m4wy.pdf
[2023-01-25][02:58:12][chatgpt::utils][�[9mINFO�[0m] open_file: C:\Users\xxxx\.chatgpt\notes\aegck9.md

Should the open_file command open the file in a default application?
Only Explorer opens - which is fine, if that's the expected behavior.

Also, the pdf looks like it's one long image pasted into a pdf. Is that the intended behaviour?
That's also OK, since the .md file can be converted to a pdf with text.

@lencx
Copy link
Owner

lencx commented Jan 25, 2023

It will only open the directory where the file is located, not open the file (this is the expected behavior, because considering the exported file may require secondary operations by the user, so did not open the file itself).

PDF export using jsPDF, I have not yet studied in depth whether its API supports text content.

@merrickw
Copy link
Author

When you're handling the pdf it looks like you're putting a .png image in there from the code:

async function handlePdf(imgData, canvas, pixelRatio) {
  const { jsPDF } = window.jspdf;
  const orientation = canvas.width > canvas.height ? "l" : "p";
  var pdf = new jsPDF(orientation, "pt", [
    canvas.width / pixelRatio,
    canvas.height / pixelRatio,
  ]);
  var pdfWidth = pdf.internal.pageSize.getWidth();
  var pdfHeight = pdf.internal.pageSize.getHeight();
  pdf.addImage(imgData, "PNG", 0, 0, pdfWidth, pdfHeight, '', 'FAST');
  const { pathname, id, filename } = getName();
  const data = pdf.__private__.getArrayBuffer(pdf.__private__.buildDocument());
  await invoke('download', { name: `download/pdf/${id}.pdf`, blob: Array.from(new Uint8Array(data)) });
  await invoke('download_list', { pathname, filename, id, dir: 'download' });

Maybe you can inject the .md file instead of a png. I'm just guessing here.

@lencx
Copy link
Owner

lencx commented Jan 25, 2023

If you just inject markdown you will lose the style, it should be html with css.

@merrickw
Copy link
Author

Am I misreading the code above that's injecting imgData, PNG?

@lencx
Copy link
Owner

lencx commented Jan 25, 2023

The code snippet you sent is the code that generates the PDF, which is drawn via canvas, and I also found a related issues to explain how it works now. parallax/jsPDF#1580 (comment)

@lencx lencx closed this as completed Jan 27, 2023
SsomsakTH pushed a commit to SsomsakTH/ChatGPT that referenced this issue Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants