saber-notes / saber

The cross-platform open-source app built for handwriting
https://saber.adil.hanney.org
GNU General Public License v3.0
1.95k stars 119 forks source link

Import/export PDFs losslessly #432

Open WasteOfO2 opened 1 year ago

WasteOfO2 commented 1 year ago

Tasks

Original issue

Click here to see the original issue **Describe the bug** When importing PDFs, it is noted that the imported PDFs are noticeably worse quality, leading to worse legibility of the document. This issue has already been noted in the following issues and specific comments for the same: https://github.com/adil192/saber/issues/400#issuecomment-1441985933 https://github.com/adil192/saber/issues/429#issuecomment-1450090362 **To Reproduce** Steps to reproduce the behavior: 1. Create a new note 2. Import a PDF 3. Note the worse the picture quality **Expected behavior** Near-lossless quality of the imported PDF **Screenshots** Already mentioned in the above links ![image](https://user-images.githubusercontent.com/33026003/222141961-e920de77-1627-4168-94ea-e03460dc81b5.jpg) ![image](https://user-images.githubusercontent.com/45941793/220950323-ca6616ea-2990-4e8f-8292-ff4ffc5a0cc7.png) **Device (please complete the following information):** - Device: Samsung Galaxy Tab S6/S4 Lite LTE (Should probably be universal) - OS: Android 12 - Version: v0.9.5 - Browser (if applicable): - Perhaps this issue can be mitigated by allowing the imported PDF to dynamically set the page size? Or by disabling the "Maximum image size" option for such files, if not already. Willing to discuss solutions
adil192 commented 1 year ago

Perhaps this issue can be mitigated by allowing the imported PDF to dynamically set the page size?

Or by disabling the "Maximum image size" option for such files, if not already. Willing to discuss solutions

The page size is already determined by the aspect ratio of the PDF, but changing the page size won't improve the quality of the image. The max image size setting is already ignored for PDFs.

The problem is that they're rasterized to images. I'll fix this by using a regular PDF renderer in place of an image, but I'll need to find a way to invert these (efficiently)

Update: done in #520

WasteOfO2 commented 1 year ago

i think most people want to stick to non-invertible PDFs anyways, so the default can be to just leave it at the default, light theme.

i found this in flutter packages if thats helpful https://pub.dev/packages/pdf_render

the above package is noted to have issues with mac OS, read more in the above link

i also found a package that renders PDFs to Bitmaps https://pub.dev/packages/pdf_image_renderer

But considering the nature of sizes of BMPs, i think it is a better idea to not use them

also found this https://pub.dev/packages/pdfx but there doesnt seem to be support for linux

i am not very comfortable with programming related stuff, so my apologies if i am not very helpful

adil192 commented 8 months ago

Turns out that lossless exports would require the premium extension for the pdf library. Unfortunately this isn't something I can pay out of pocket, so I'll need to wait for enough sponsorship money to come in over time.

(I have also emailed @DavBfr to see how the pdf_crypto license interacts with Saber.)

markwmuller commented 5 months ago

How much $$ do you need? Have you reached out to the author to ask if there's an accommodation for FOSS projects?

DavBfr commented 5 months ago

The premium extension for the PDF library is not designed to parse a PDF document for display. It can only load the base structure to do some modifications. I don't know any FOSS Dart implementation to load PDF vector data.

adil192 commented 4 months ago

How much $$ do you need? Have you reached out to the author to ask if there's an accommodation for FOSS projects?

It's $250 currently. But I'm not certain that pdf_crypto would be right for Saber especially concerning the license.

The premium extension for the PDF library is not designed to parse a PDF document for display. It can only load the base structure to do some modifications. I don't know any FOSS Dart implementation to load PDF vector data.

I wouldn't need pdf_crypto to display a pdf. I think I can use it to export pdfs (with annotations) without having to rasterize the pages first.

markwmuller commented 4 months ago

Looks like pdf_crypto might not be the right way to go, judging by the comment from its author. Is there a way to rasterize the PDF at a higher resolution? That would certainly solve most of my personal pain point.