saber icon indicating copy to clipboard operation
saber copied to clipboard

Import/export PDFs losslessly

Open WasteOfO2 opened this issue 2 years ago • 7 comments

Tasks

  • [X] Lossless imports
  • [ ] Lossless exports

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

image

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

WasteOfO2 avatar Mar 01 '23 14:03 WasteOfO2

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

adil192 avatar Mar 01 '23 18:03 adil192

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

WasteOfO2 avatar Mar 02 '23 07:03 WasteOfO2

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.)

adil192 avatar Nov 10 '23 15:11 adil192

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

markwmuller avatar Jan 26 '24 18:01 markwmuller

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.

DavBfr avatar Jan 26 '24 18:01 DavBfr

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.

adil192 avatar Feb 20 '24 04:02 adil192

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.

markwmuller avatar Feb 20 '24 17:02 markwmuller