pelya / android-print-plugin-cups

CUPS print plugin for Android
GNU Lesser General Public License v3.0
93 stars 36 forks source link

New project #1

Open lbdroid opened 9 years ago

lbdroid commented 9 years ago

You have some interesting work in this project, just a bit... much... having the debian sysimage dependency. I've been working on a print framework plugin using libcups via ndk/jni.

I would welcome any contributions.

https://github.com/lbdroid/CupsClientService

pelya commented 9 years ago

The main feature of my print plugin was to print to Windows print servers (because that's what I got at the office), CUPS/ipp support is a side feature.

Another goal was to do it quickly and forget about it, which I kind of achieved by using that Debian image and not caring about installation size.

I would like to improve it, but currently have too little free time.

It would be nice to use your library instead of lp commandline interface, however that would mean rewriting half of the app code.

BTW did you take a look at the todo list in the readme? https://github.com/pelya/android-print-plugin-cups/blob/master/README.md Amdroid printing framework lacks some basic features like page margins or print preview (Google apps do print preview inside the app itself), or ability to collate pages. Also you have no real control over what font sizes each app will choose, this could be solved by reporting bigger/smaller paper size to the app, then rescaling print content.

Another feature would be to use Android as a print server itself with USB printers, that is achievable by creating an interface for Linux libusb to the Android USB framework, but that will require a lot of time and effort and will definitely need Debian image (or recompiling CUPS daemon with NDK, then having a lot of pain porting each plugin to NDK, then it won't be much smaller than Debian image). Also I would need to buy an actual USB printer for that. On May 5, 2015 11:34 PM, "lbdroid" notifications@github.com wrote:

You have some interesting work in this project, just a bit... much... having the debian sysimage dependency. I've been working on a print framework plugin using libcups via ndk/jni.

I would welcome any contributions.

https://github.com/lbdroid/CupsClientService

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1.

lbdroid commented 9 years ago

The print framework has been smoothed out a lot in android 5+, including addition of print preview. It is actually a particularly nice preview, that includes page numbering and provides page selection by checking and unchecking pages in the preview.

Shouldn't fonts and margins be determined by the application/renderer? The application is responsible for outputting a pdf, which is also what cups now prefers.

The source I started with already has the advanced print options functionality in place, and I think some or most of your todos (though some is still broken from the switch from cups4j to libcups).

FYI: printer detection is already implemented by zeroconf/bonjour and local network host scanning, though I may ultimately change over from jmdns to nsd for that when time permits (low priority, given that the functionality is already present).

pelya commented 9 years ago

Ah okay, didn't know that's a Lollipop feature.

Page margins, yes the app should define them, but I've seen no apps providing this option. And they sometimes are a big deal (in my highschool they required big left margin to staple everything and put into a binder).

I would like to also integrate zeroconf, as I don't want to add cups-browsed to the Debian image. On May 6, 2015 2:17 AM, "lbdroid" notifications@github.com wrote:

The print framework has been smoothed out a lot in android 5+, including addition of print preview. It is actually a particularly nice preview, that includes page numbering and provides page selection by checking and unchecking pages in the preview.

Shouldn't fonts and margins be determined by the application/renderer? The application is responsible for outputting a pdf, which is also what cups now prefers.

The source I started with already has the advanced print options functionality in place, and I think some or most of your todos (though some is still broken from the switch from cups4j to libcups).

FYI: printer detection is already implemented by zeroconf/bonjour and local network host scanning, though I may ultimately change over from jmdns to nsd for that when time permits (low priority, given that the functionality is already present).

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1#issuecomment-99258151 .

lbdroid commented 9 years ago

Hey, libusb already has support for Android. https://github.com/libusb/libusb/tree/master/android

Turns out that getting the USB stuff working is simply a matter of adjusting the CUPS config file to #define HAVE_LIBUSB 1 and adding libusb1.0 to the LOCAL_SHARED_LIBRARIES variable where needed (backend/usb module).

Yesterday evening, I got the majority of cupsd (including WEBIF) now building on Android. It was unexpectedly easy, although there are still some configurations that I need to change to get it to actually work.

Note that there really is no need to go through Android USB framework, since our library can just go straight to the kernel. As a long term goal for eliminating the need for root, that may be useful, but it isn't like you can run a Debian image without root anyway....

When this is all done, the size really will still be very manageable. Cups is not all that big. The total size of all the objects at this point is still under 10 MB and compress (zip, like an APK file) down to just 4.

pelya commented 9 years ago

Android disallows direct kernel calls to USB subsystem, as far as I know, so you will need root to run your code.

Debian without root is exactly what this print plugin uses, you may also take a look at this: https://play.google.com/store/apps/details?id=com.cuntubuntu On May 27, 2015 6:54 PM, "lbdroid" notifications@github.com wrote:

Hey, libusb already has support for Android. https://github.com/libusb/libusb/tree/master/android

Turns out that getting the USB stuff working is simply a matter of adjusting the CUPS config file to #define HAVE_LIBUSB 1 and adding libusb1.0 to the LOCAL_SHARED_LIBRARIES variable where needed (backend/usb module).

Yesterday evening, I got the majority of cupsd (including WEBIF) now building on Android. It was unexpectedly easy, although there are still some configurations that I need to change to get it to actually work.

Note that there really is no need to go through Android USB framework, since our library can just go straight to the kernel. As a long term goal for eliminating the need for root, that may be useful, but it isn't like you can run a Debian image without root anyway....

When this is all done, the size really will still be very manageable. Cups is not all that big. The total size of all the objects at this point is still under 10 MB and compress (zip, like an APK file) down to just 4.

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1#issuecomment-105972128 .

lbdroid commented 9 years ago

That certainly can't use any Android USB api...

pelya commented 9 years ago

But you can run GIMP and LibreOffice. On May 27, 2015 7:09 PM, "lbdroid" notifications@github.com wrote:

That certainly can't use any Android USB api...

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1#issuecomment-105980285 .

lbdroid commented 9 years ago

You can run libreoffice on Android natively with its obviously early stage UI... Plus, both are pretty much useless on a small screen with desktop UI.

Not sure how they apply to cups/USB though...

pelya commented 9 years ago

Well yes. Anyway, please keep me updated on your CUPS/libusb progress. On May 27, 2015 11:06 PM, "lbdroid" notifications@github.com wrote:

You can run libreoffice on Android natively with its obviously early stage UI... Plus, both are pretty much useless on a small screen with desktop UI.

Not sure how they apply to cups/USB though...

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1#issuecomment-106057536 .

lbdroid commented 9 years ago

Of course. ;)

darvids0n commented 8 years ago

I’m working on adding libusb support for this project right now, can you point me in the right direction for implementation? I have currently libusb.so for ARM platform, and I can see CUPS allows adding USB printers using lpadmin -p but what specifically do we need to do to make it work? Can I just make the CUPS config changes as specified here and link in the libusb.so?

pelya commented 8 years ago

Putting your libusb.so to LD_PRELOAD env var should be enough. Or you can simply replace libusb.so inside Debian installation.

Does your libusb.so hook to Android Java USB framework? Simply cross-compiling libusb for ARM will not do, as it will require root access, which a regular app cannot have. On Nov 11, 2015 5:03 AM, "David Nolan" notifications@github.com wrote:

I’m working on adding libusb support for this project right now, can you point me in the right direction for implementation? I have currently libusb.so for ARM platform, and I can see CUPS allows adding USB printers using lpadmin -p but what specifically do we need to do to make it work? Can I just make the CUPS config changes as specified here and link in the libusb.so?

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1#issuecomment-155645324 .

darvids0n commented 8 years ago

Well I could write a JNI wrapper but that would just make it usable from Java code which is not what we want. Are you saying libusb needs to be modified to call Android SDK methods before it will work? That's a fairly big job.

pelya commented 8 years ago

Yes, libusb will have to invoke Android SDK Java code, it cannot do kernel calls directly or parse USB filesystem in /sys as it does on Linux. On Nov 12, 2015 6:37 AM, "David Nolan" notifications@github.com wrote:

Well I could write a JNI wrapper but that would just make it usable from Java code which is not what we want. Are you saying libusb needs to be modified to call Android SDK methods before it will work? That's a fairly big job.

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1#issuecomment-155995302 .

darvids0n commented 8 years ago

OK now I have .so's written to call to the Android SDK, but to bundle them with CUPS I will need to recompile with --enable-libusb unless it was already done. I found the libusb.so files in /lib/archname/libusb-1.0.so, so I am assuming I just replace these in the .xz assuming CUPS has libusb support compiled in.

pelya commented 8 years ago

Run script img-cups-jessie.sh from here: https://github.com/pelya/debian-noroot/tree/master/img

It does not compile CUPS, it pulls prebuilt packages from Debian.org On Mar 4, 2016 8:24 AM, "David Nolan" notifications@github.com wrote:

OK now I have .so's written to call to the Android SDK, but to bundle them with CUPS I will need to recompile with --enable-libusb. How is the dist-cups-jessie.tar.xz created? I will need to rerun the generation process.

— Reply to this email directly or view it on GitHub https://github.com/pelya/android-print-plugin-cups/issues/1#issuecomment-192124901 .

arman-sydikov commented 7 years ago

It's been more than 1 year since the last post, have you guys managed to add USB support ? I have a rooted x86_64 android device and facing the same issue with connecting it to the printer by USB OTG cable. Mac computer can easily detect my printer with CUPS and uses its Zebra EPL2 Label Printer driver ( drv:///sample.drv/zebraep2.ppd ) for printing.

darvids0n commented 7 years ago

This project took us too long and there were still issues even getting CUPS to detect USB devices through my Android driver, so I shelved it. I also can't share as it was paid work.

csangeeta commented 6 years ago

Hi, We have our won thermal printers and we have sdk for that already. I wanted a printer service plugin that s what your project is. this will help us to show our android application in the printer option as default one when we say print from device browser. Problem : I started the service which will show our device in browser print option. but how should i add the printer and how i receive data from the browser to out app? can you please explain me.