Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Android support #118

Closed
comidan opened this issue Oct 29, 2018 · 21 comments
Closed

Android support #118

comidan opened this issue Oct 29, 2018 · 21 comments

Comments

@comidan
Copy link

comidan commented Oct 29, 2018

Android support wiki article:
https://github.com/LibrePDF/OpenPDF/wiki/Android-support

So let's list the tasks required for Android support:

-Classes like awt.Color, Point, Dimensiom can be easily replaced.
-Classes like PdfGraphics2D need to be rewritten from scratch, since they use so much awt logic.
-All the rendering logic is done with awt and needs to be rewritten, retested etc.

There is also: https://github.com/witwall/appengine-awt
https://github.com/bedatadriven/appengine-export

  • Could we use this?

The original issue submission here:

Hi, thank you for your great work.

Just learnt how to use your library with a sample Java application
Then I used some classes I made thanks to your library in an Android environment but disocovered your library is using only AWT without no android.graphics packages suppport.

Any suggestion on how could I move on?

@andob
Copy link

andob commented Jan 10, 2019

hello,

I am also interested in android compatibility. I want to modify this library, to replace awt with android specific code.

  1. I can work on this repo on another branch; create openpdf-awt, openpdf-android modules, in openpdf module we would have abstract classes without graphics logic (ie AbstractImage instead of Image). In openpdf-awt module I would pull awt logic from the base module (ie Image implementation with awt). In openpdf-android module I would develop android specific graphics code (ie Image implementation based on android)

  2. (The quick way) I can fork this repo and keep only a small part of the classes / components, only those that I actually need in my project. I can make those classes android compatible. I currently only need paragraphs, images and tables. In time, I will migrate more and more components. Then I can apply option (1).

@comidan
Copy link
Author

comidan commented Jan 10, 2019

@andob Well yeah that would be great, I thought to do it myself after asking for compatibility but I later realized I have already too much work to do at college.

However I resolved this missing compatibility by bypassing it : deployed a Servlet on AWS' Elastic Beanstalk using Apache Tomcat and then getting via HTTP response the processed PDF in the Android app

Yeah that's quite a trip, so I hope there'll be android support soon

@noavarice
Copy link
Contributor

@andob @Daniele-Comi @andreasrosdal
AFAIU there's no specific need to use AWT in the library - there is just a need to specify a font color, so developers have decided to use AWT Color. So I guess it's just should be replaced with custom way to specify color to avoid pulling whole AWT JDK module which is completely redundant.

@andreasrosdal andreasrosdal pinned this issue Mar 10, 2019
@andreasrosdal andreasrosdal changed the title Question : any Android support? Android support Mar 10, 2019
@andreasrosdal andreasrosdal unpinned this issue Apr 21, 2019
@karishmapujara
Copy link

Hello @andob @Daniele-Comi @andreasrosdal
Any news on Android support?

@BobbyRuby
Copy link

BobbyRuby commented Sep 3, 2019

I don't have the skill to have this support Android, so hoping someone takes this one soon.

@andob

This comment has been minimized.

@andreasrosdal
Copy link
Contributor

So let's list the tasks required for Android support:

-Classes like awt.Color, Point, Dimensiom can be easily replaced.
-Classes like PdfGraphics2D need to be rewritten from scratch, since they use so much awt logic.
-All the rendering logic is done with awt and needs to be rewritten, retested etc.

There is also: https://github.com/witwall/appengine-awt - Could we use this?

@andreasrosdal andreasrosdal pinned this issue Sep 4, 2019
@andob
Copy link

andob commented Sep 4, 2019

@andreasrosdal @BobbyRuby
Well, we could use windwardadmin/android-awt which is based on appengine-awt.

I forked it into this repo - andob/android-awt and converted it to gradle. I tested with my old PDF generating code based on iText, I converted that code to OpenPDF and applied this dependency.

It worked! :)

This is a hack but it seems to work :D. At least with the features I used: generating PDFs with paragraphs, tables, images and normal / bold text with the default font.

@BobbyRuby can you test this on your project and post the issues you found on my repo?

@andreasrosdal
Copy link
Contributor

Can you please post a description about how to use OpenPDF with android-awt?
android-awt needs maven support also.
Thanks @andob !

@andob
Copy link

andob commented Sep 4, 2019

@andreasrosdal
Yes. My repo contains java.awt.* and javax.imageio.* classes. You just have to import both libraries (OpenPDF and the one from my repo). When OpenPDF will try to access awt classes, the JVM will find these classes on android-awt library.

On Android we use Gradle, which is fully compatible with maven.

repositories {
    maven { url "https://jitpack.io" }
}
dependencies {
	implementation 'com.github.librepdf:openpdf:1.3.8'
	implementation 'com.github.andob:android-awt:1.0.0'
}

On Maven this can be configured as

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>
    <dependency>
        <groupId>com.github.andob</groupId>
        <artifactId>android-awt</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>com.github.librepdf</groupId>
        <artifactId>openpdf</artifactId>
        <version>1.3.8</version>
    </dependency>

@andreasrosdal

This comment has been minimized.

@andob

This comment has been minimized.

@BobbyRuby
Copy link

I'll give this a shot... Hoping it will do the trick for filling forms. Won't be tonight but will try to get it tested before end of next week.

@andreasrosdal andreasrosdal unpinned this issue Sep 18, 2019
@udittmer
Copy link

udittmer commented Oct 7, 2019

What do I need to add to my ProGuard setup to make this work? While the code works fine -many thanks to all involved!- in the debug build, the release build fails at the transformClassesAndResourcesWithProguardForRelease step, with the last message being

Warning: there were 143 instances of library classes depending on program classes.
You must avoid such dependencies, since the program classes will
be processed, while the library classes will remain unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)

But I'm not sure how to avoid those?

@andob
Copy link

andob commented Oct 8, 2019

@udittmer Please update android-awt to its latest version, 1.0.1

implementation 'com.github.andob:android-awt:1.0.1'

And add these rules to your proguard-rules.pro file

-dontwarn org.bouncycastle.**
-dontwarn java.lang.invoke.**

@udittmer
Copy link

udittmer commented Oct 9, 2019

Thanks for the reply, but adding that didn't make a difference. I'm not sure why it would, anyway: suppressing warnings in ProGuard doesn't address the issue it complains about (about library classes depending on program classes), does it?

Is there a demo app (or any app that uses android-awt) available somewhere that shows how it all fits together?

@andob
Copy link

andob commented Oct 9, 2019

@udittmer well I couldn't replicate your exact error
If I import OpenPDF and android-awt:1.0.0 and then build with proguard I got the following errors:
image

There are some missing classes from java.awt.*, javax.* packages. I've added those classes in the latest version, 1.0.1.

If you want to use bouncycastle with OpenPDF, you sould import it in your build.gradle file, otherwise If you don't use bouncycastle features, you should add -dontwarn org.bouncycastle.** in proguard rules, to ignore the warning.

OpenPDF also uses java.lang.invoke.LambdaMetafactory, which is unavailable on Android. So, yes, supressing warnings don't address your exact issue, but the issues I've encountered when building with proguard.

I made a quick sample project: OpenPDFAndroidSample. Can you clone my repo and run / build for debug / release the sample? On my environment (Android Studio 3.5) works fine.

@udittmer
Copy link

Thanks very much for the help, I appreciate it. I can build the sample code fine, and after upgrading my tool chain to the latest Gradle version (I was still using 4.10.2), so does my app. Maybe something internal to Gradle changed along the way. Anyway, the problem is solved.

@BobbyRuby
Copy link

I just saw the samples and was going to share it here! Thanks andob! I will be putting this to good use I think. I'll report back any problems or issues I may find!

@VincentJoshuaET
Copy link

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn org.apache.fop.complexscripts.fonts.GlyphSubstitutionTable
-dontwarn org.apache.fop.complexscripts.util.CharScript
-dontwarn org.apache.fop.complexscripts.util.GlyphSequence
-dontwarn org.apache.fop.fonts.apps.TTFReader
-dontwarn org.apache.fop.fonts.truetype.FontFileReader
-dontwarn org.apache.fop.fonts.truetype.TTFFile
-dontwarn org.bouncycastle.jsse.BCSSLParameters
-dontwarn org.bouncycastle.jsse.BCSSLSocket
-dontwarn org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
-dontwarn org.conscrypt.Conscrypt$Version
-dontwarn org.conscrypt.Conscrypt
-dontwarn org.openjsse.javax.net.ssl.SSLParameters
-dontwarn org.openjsse.javax.net.ssl.SSLSocket
-dontwarn org.openjsse.net.ssl.OpenJSSE

@asturio
Copy link
Member

asturio commented Feb 23, 2024

There is no official android support in OpenPDF, so using android-awt is the way to go. Moving this to discussions.

@LibrePDF LibrePDF locked and limited conversation to collaborators Feb 23, 2024
@asturio asturio converted this issue into discussion #1079 Feb 23, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

9 participants