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

Add attachment rendering in PDF and HTML #716

Merged

Conversation

Komediruzecki
Copy link
Contributor

Add attachment rendering in PDF and HTML

  • Add attachment getter in PDF export (exports.ts)
  • Add parsing note md content to replace <img src='id'> with valid note image id
    • id blob is replaced with object url link in PDF export
    • id blob is replaced with base64 encoding of the image
  • Update downloadBlob to have cleanup callback (for revoking objectURLs in PDF export)

How it works:
Users can export the PDF and HTML and any image link attached to document which renders well in markdown preview should be exported inside downloaded PDF and HTML (see more details in commit description).

How it looks:
- md:

- result: PDF & HTML

Test:

  • In electron Linux App (dev)
    • Test exporting PDF & HTML in local file system storage
  • In electron Linux App production version (appImage)
    • Test exporting PDF & HTML from local file system storage
    • Test exporting PDF & HTML from cloud storage

Test invalid attachements exporting, error message, see below:
NoSuchImagePushMessage

Error Handling:
If attachment cannot be found, it is skipped and error message is shown to the user. The exporting continues with all valid attachments.

Add attachment getter in PDF export (exports.ts)
Add parsing note md content to replace <img src='id'> with valid note id
  - id blob is replaced with object url link in PDF export
  - id blob is replaced with base64 encoding of the image
Update downloadBlob to have cleanup callback (for revoking objectURLs in PDF export)
@Komediruzecki Komediruzecki self-assigned this Dec 11, 2020
@Komediruzecki Komediruzecki added the awaiting review ❇️ Pull request is awaiting a review. label Dec 11, 2020
@@ -22,6 +30,9 @@ export function downloadBlob(blob: Blob, fileName: string) {
anchor.click()
window.URL.revokeObjectURL(anchor.href)
document.body.removeChild(anchor)
if (callback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary. There are no deferred statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, fixed!

@@ -22,6 +30,9 @@ export function downloadBlob(blob: Blob, fileName: string) {
anchor.click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use writeFile method from electronOnly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really write this method, but will need more time to investigate this downloads API, is this something we could use from electron API? Yes I see, for blob it don't matter since we could just write it to disk? Will update it later today.

Copy link
Contributor Author

@Komediruzecki Komediruzecki Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I investigated this further. For download APIs - that's extensions? In this case electron supports some, but it seems a bit complicated setting that up, do you have any examples of this? did you try it?

As for writeFile, I could call something like this:

await writeFile(fileName, Buffer.from(await blob.arrayBuffer()))

similar thing is done for attachment writing. But this involves promises and a drawback that we are saving it with filename only - location should then be fetched from user somehow (folder where to save the item, as we have for storage location selection boxes).

This is currently done with ".click()" when user selects the location, in that location/filename the blob is saved/downloaded.

So can you inspect this one more time, and give me the specification, which method would be best, so we can change it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can merge this now. I'll investigate more later!

@@ -189,10 +204,108 @@ const generatePrintToPdfHTML = (
`
}

const blobToBase64 = async (blob: Blob) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertBlobToBase64

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use conventional functions rather than arrow functions

function convertBlobToBase64(blob: Blob) {...}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, didn't know that. Updated

})
}

const updateNoteLinks = async (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

src/lib/exports.ts Outdated Show resolved Hide resolved
@Rokt33r Rokt33r added awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. and removed awaiting review ❇️ Pull request is awaiting a review. labels Dec 14, 2020
Update download blob to not have callback
Use normal functions instead of arrow in exports.ts
@Komediruzecki Komediruzecki added awaiting review ❇️ Pull request is awaiting a review. and removed awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. labels Dec 15, 2020
@Rokt33r Rokt33r added this to the v0.12.0 milestone Dec 17, 2020
@Rokt33r Rokt33r removed the awaiting review ❇️ Pull request is awaiting a review. label Dec 17, 2020
@Rokt33r Rokt33r merged commit 70b8d75 into BoostIO:master Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants