How to add PDFBox to an Android project or suggest alternative
PDFBox uses java awt and swing, even for non UI tasks, I've tried to remove references but there are a lot of files, and I was removing too much stuff
I've just tested PDFjet http://pdfjet.com/os/edition.html it's bsd licensed (plus commercial version with more features), with this sample code (ripped from Example_03.java) I was able to convert a jpeg to a pdf
FileOutputStream fos = null;
try
{
fos = new FileOutputStream("/sdcard/sample.pdf");
PDF pdf = new PDF(fos);
InputStream f = getApplicationContext().getAssets().open("img0.jpg");
Image image = new Image(pdf, f, ImageType.JPEG);
Page page = new Page(pdf, A4.PORTRAIT);
image.setPosition(0, 0);
image.drawOn(page);
pdf.flush();
fos.close();
} catch (Exception e)
{
e.printStackTrace();
}
I found the link here http://java-source.net/open-source/pdf-libraries
Android and Apache PDFBox
To create pdf using your app,
You can use PdfDocument if your app is for users who have android devices having api 19 or above.
Otherwise you can use open-sourced library named Android PDF Writer
I hope it will be helpful !!
Understanding PDFBox jar files
Summarizing the comments: you want to create a PDF from scratch and access your development over ssh
so you can't use an IDE and have to use javac
. For that you could use pdfbox-app jar file, but this would be huge. Instead, use the pdfbox, fontbox and commons-log jar files. See also here for additional dependencies if you want to do more advanced stuff (read / render (= convert to image) / decrypt / sign).
PDFBox : PDPageContentStream's append mode misbehaving
Use the constructor that has a fifth parameter, so to reset the graphic context.
public PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent,
boolean compress, boolean resetContext) throws IOException
alternatively, save and restore the graphics state in the first content stream by calling
saveGraphicsState();
// ...
restoreGraphicsState();
Related Topics
Mediaplayer.Setdatasource() and Prepare() Not Working - Android
Newer Versions of Android Studio and Only Two Drawable Directory - Drawable and Drawable-V21
How to Limit Fling in Android Gallery to Just One Item Per Fling
How to Create Multiple Pendingintents with the Same Requestcode and Different Extras
Android Audiotrack Playing .Wav File, Getting Only White Noise
Update Support Library 23.2.0 Build Bug
Android: How to Enable/Disable an Activity's Intent Filter Programmatically
Detecting Gps On/Off Switch in Android Phones
Android Decoder->Decode Returned False for Bitmap Download
How to Change Actionmode Background Color in Android
Convert Existing Project to Library Project in Android Studio
Does Retrofit Make Network Calls on Main Thread
How to Detect Wifi Tethering State
How to Access an Image from the Phone's Photo Gallery
Add an Array of Buttons to a Gridview in an Android Application