How to Add PDFbox to an Android Project or Suggest Alternative

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



Leave a reply



Submit