CatimaLoyalty / Android

Catima, a Loyalty Card & Ticket Manager for Android
https://catima.app
GNU General Public License v3.0
807 stars 146 forks source link

Import from PDF files #496

Closed rklett closed 5 months ago

rklett commented 2 years ago

I'd like to be able to use Catima to store and display e-tickets which have been provided in PDF format with embedded QR codes. I suppose the workaround for this is to either take a screenshot of the PDF on my phone and import that or to scan the QR code off my computer screen. Both of these are a bit of a hassle that I'd like to avoid if Catima supported importing a PDF.

Maybe something to consider is that usually these PDFs come with one page per ticket with each page/ticket having a separate QR code. I expect this complicates things more than just adding a PDF reading library but we can set the aside for now.

TheLastProject commented 2 years ago

So it seems to me this is actually multiple features working together and it would be best to implement all of these, although only #3 is really necessary for this feature.

1: Let Catima handle share intents for images (so that sharing an image to Catima works).

  1. Extend the image reading to look for multiple codes (so, start with the "Select image from gallery" button in adding a barcode) and offer the user to add one or more of the found codes (right now, I think the code stops as soon as it found a single code)
  2. Support PDF files (is there a small library that can convert those to images perhaps to keep the code simple?). Maybe only support this in the share intent so we still just open the gallery on the "Scan Card Barcode" screen
rklett commented 2 years ago

I can't really help with the first two but the third one, I've seen similar features in https://github.com/michaeltroger/greenpass-android. Unfortunately, that app keeps crashing for me on my new phone after I imported a PDF but I had it sort of working on an older phone.

Poking around, I think it uses https://github.com/TomRoush/PdfBox-Android for the PDF handling. I'm not a developer though so my contributions probably end here. I'll keep an eye out in case anything comes up that I might be able to help with.

famo commented 2 years ago

@rklett you might want to check out https://github.com/ligi/PassAndroid, which is actually made for tickets and also supports import of PDF tickets. HTH

atharen commented 2 years ago

Quoting from #977, noting only PDF import related mentions:

Treating PDF files as images and letting them go through the cropper, making sure that multi-page PDF files will stay multi-page (probably by just putting all pages below or next to each other). (Side note: Supporting PDFs as image input also has the benefit of being able to support them in "Scan Barcode -> Select image from gallery" for new barcodes to be added, such as for https://github.com/CatimaLoyalty/Android/issues/907)

Either 1 picture per PDF (collate all pages into 1 image), or an image for each page - the first suggestion works best if you have multiple PDFs, but the latter works best when you only have 1 PDF, so you can swipe over each individual image/page. It's an implementation detail so I'll leave it to be discussed in the appropriate task.

One or two pages are easy enough, but if you get 5 or more pages it'll look awful.

Potential Libraries for the implementation:

I was trying to convert my PDF on device (though ended up using my PC, as it was easier), and found 2 open-source apps which advertise this functionality:

Let's put those libraries in the new task as links and see if they're the best of if there are other options. Archived for 5 years sounds like it's asking for trouble though.

TheLastProject commented 2 years ago

Oh yeah, that reminds me, I found https://developer.android.com/reference/android/graphics/pdf/PdfRenderer.html yesterday. PDF reading right in Android core libraries. That would definitely be the best option if possible.

But first it needs checking if Google's new Android 13 restrictions on opening files hasn't broken the ability to open non-media-files: #979

ChildishGiant commented 1 year ago

this would be a massive step forward for this app's actual use as a ticket manager as well as membership cards.

brennoflavio commented 1 year ago

I don't know if its an use case that this app is whiling to support, but currently in my country I can use PDF's with QR codes as valid documents (IDs, vaccination cards, car license etc).

So Catima has being a great way to concentrate all my documents, except that I can't attach the original PDF's to the document if some official asks for it. Currently I converted the PDFs to images and attached to Catima, but sometimes they ask for the PDF itself. So I'm saving that in my phone also, but would be great to have some sort of "Attachments" session that allows the user to upload stuff related to that card.

andrearicci commented 1 year ago

maybe we can just use an "attach" option, for any kind of document, wich opens a new app.