Coder Social home page Coder Social logo

pdfbox-android's People

Contributors

312937 avatar 4brunu avatar anyongjin avatar camdenfullmer avatar cwiep avatar dependabot[bot] avatar hjgode avatar hxlich avatar jitpack-io avatar juliendn avatar mdamt avatar ngochai84 avatar rzimmer avatar sbassomp avatar thekevinbrown avatar tiper avatar tomroush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdfbox-android's Issues

Unmappable character for encoding UTF-8 on building APK

I'm getting an 'Unmappable character for encoding UTF-8' when I try to build my App.

Any idea about how to fix that?

Error:error: unmappable character for encoding UTF-8
     * Gets the summary of the table�s purpose and structure.
                                    ^
Error:error: unmappable character for encoding UTF-8
     * Sets the summary of the table�s purpose and structure.
                                    ^
Error:error: unmappable character for encoding UTF-8
     * Placement: Before: Placed so that the before edge of the element�s
                                                                       ^
Error:error: unmappable character for encoding UTF-8
     * element�s allocation rectangle.
              ^
Error:error: unmappable character for encoding UTF-8
     * Placement: Start: Placed so that the start edge of the element�s
                                                                     ^
Error:error: unmappable character for encoding UTF-8
     * specified placement. Other content that would intrude into the element�s
                                                                             ^
Error:error: unmappable character for encoding UTF-8
     * Placement: End: Placed so that the end edge of the element�s allocation
                                                                 ^
Error:error: unmappable character for encoding UTF-8
     * Other content that would intrude into the element�s allocation rectangle
                                                        ^
Error:error: unmappable character for encoding UTF-8
     * BlockAlign: Before: Before edge of the first child�s allocation rectangle
                                                         ^
Error:error: unmappable character for encoding UTF-8
     * aligned with that of the table cell�s content rectangle.
                                          ^
Error:error: unmappable character for encoding UTF-8
     * between the before edge of the first child�s allocation rectangle and
                                                 ^
Error:error: unmappable character for encoding UTF-8
     * that of the table cell�s content rectangle shall be the same as the
                             ^
Error:error: unmappable character for encoding UTF-8
     * distance between the after edge of the last child�s allocation rectangle
                                                        ^
Error:error: unmappable character for encoding UTF-8
     * and that of the table cell�s content rectangle.
                                 ^
Error:error: unmappable character for encoding UTF-8
     * BlockAlign: After: After edge of the last child�s allocation rectangle
                                                      ^
Error:error: unmappable character for encoding UTF-8
     * aligned with that of the table cell�s content rectangle.
                                          ^
Error:error: unmappable character for encoding UTF-8
     * edges of the table cell�s content rectangle. The first child shall be
                              ^
Error:error: unmappable character for encoding UTF-8
     * InlineAlign: Start: Start edge of each child�s allocation rectangle
                                                   ^
Error:error: unmappable character for encoding UTF-8
     * aligned with that of the table cell�s content rectangle.
                                          ^
Error:error: unmappable character for encoding UTF-8
     * distance between the start edges of the child�s allocation rectangle and
                                                    ^
Error:error: unmappable character for encoding UTF-8
     * the table cell�s content rectangle shall be the same as the distance
                     ^
Error:error: unmappable character for encoding UTF-8
     * InlineAlign: End: End edge of each child�s allocation rectangle aligned
                                               ^
Error:error: unmappable character for encoding UTF-8
     * with that of the table cell�s content rectangle.
                                  ^
Error:error: unmappable character for encoding UTF-8
     * GlyphOrientationVertical: -180�
                                     ^
Error:error: unmappable character for encoding UTF-8
     * GlyphOrientationVertical: -90�
                                    ^
Error:error: unmappable character for encoding UTF-8
     * GlyphOrientationVertical: 0�
                                  ^
Error:error: unmappable character for encoding UTF-8
     * GlyphOrientationVertical: 90�
                                   ^
Error:error: unmappable character for encoding UTF-8
     * GlyphOrientationVertical: 180�
                                    ^
Error:error: unmappable character for encoding UTF-8
     * GlyphOrientationVertical: 270�
                                    ^
Error:error: unmappable character for encoding UTF-8
     * GlyphOrientationVertical: 360�
                                    ^
Error:error: unmappable character for encoding UTF-8
     * Gets the width of the element�s content rectangle in the
                                    ^
Error:error: unmappable character for encoding UTF-8
     * Sets the width of the element�s content rectangle in the
                                    ^
Error:error: unmappable character for encoding UTF-8
     * Sets the width of the element�s content rectangle in the
                                    ^
Error:error: unmappable character for encoding UTF-8
     * Sets the width of the element�s content rectangle in the
                                    ^
Error:error: unmappable character for encoding UTF-8
     * Gets the height of the element�s content rectangle in the
                                     ^
Error:error: unmappable character for encoding UTF-8
     * Sets the height of the element�s content rectangle in the
                                     ^
Error:error: unmappable character for encoding UTF-8
     * Sets the height of the element�s content rectangle in the
                                     ^
Error:error: unmappable character for encoding UTF-8
     * Sets the height of the element�s content rectangle in the
                                     ^
Error:error: unmappable character for encoding UTF-8
     * Gets the offset to account for the separation between the table cell�s
                                                                           ^
Error:error: unmappable character for encoding UTF-8
     * Gets the distance by which the element�s baseline shall be shifted
                                             ^
Error:error: unmappable character for encoding UTF-8
     * Sets the distance by which the element�s baseline shall be shifted
                                             ^
Error:error: unmappable character for encoding UTF-8
     * Sets the distance by which the element�s baseline shall be shifted
                                             ^
Error:error: unmappable character for encoding UTF-8
     * Gets the element�s preferred height in the block-progression direction
                       ^
Error:error: unmappable character for encoding UTF-8
     * Sets the element�s preferred height in the block-progression direction
                       ^
Error:error: unmappable character for encoding UTF-8
     * Sets the element�s preferred height in the block-progression direction
                       ^
Error:error: unmappable character for encoding UTF-8
     * Sets the element�s preferred height in the block-progression direction
                       ^
Error:error: unmappable character for encoding UTF-8
     * Sets the element�s preferred height in the block-progression direction
                       ^
Error:error: unmappable character for encoding UTF-8
 * @author Timo B�hme (timo.boehme at ontochem.com)
                 ^ 

Google play supported device 0

Have a problem with an already-published application on Google Play.
The application is in the store, but no one can download, because of an error Supported devices 0.
I did refactor the project, removed all unnecessary with the manifest. Compiled a new apk, and again "Supported devices 0".
I use pdfbox-android-1.8.9.jar.
If I remove the pdfbox from project, then are "Supported devices 7700".
I build project with Eclipse.

What does this mean?

Add image to pdf

How can this library be used to add a image(bitmap) in to a page? The class PDXObjectImage seems not work for me.

Contributing

I want to contribute to this project, how can I do so?
There isn't any good pdf library available for android, it would be fun to make this library a good one :)
👍 for the effort.

VerifyError when creating PDImageXObject

I get this error:

java.lang.VerifyError: org/apache/pdfbox/pdmodel/graphics/image/PDImageXObject
        at org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory.createFromStream(JPEGFactory.java:46)

when I am trying to create PDIMageXObject

PDImageXObject pdImage = JPEGFactory.createFromStream(document, new FileInputStream(new File(path)));

I get this error on device and emulator but only when running on API 15

I am using latest version of PdfBox-Android 1.8.9.0

Just checked: I dont get an Exception when using JAR version 1.8.7 of PdfBox-Android, but this version have a problem with loading resources #32

RESOLVED:
I cloned repository and compiled library to AAR and it works fine on API15 now. I compiled using latest build-tools 23.0.1, perhaps that was the reason.

Missing Font in FileSystemFontProvider

At first thank you for the android version :)

I want to create a new PDF on my android device. But I always get this errors:
12-30 10:44:40.219 7632-7632/de.doubleslash.logbook W/FileSystemFontProvider﹕ Missing 'name' entry for PostScript name in font /system/fonts/AndroidEmoji.ttf 12-30 10:44:43.852 7632-7632/de.doubleslash.logbook W/FileSystemFontProvider﹕ Missing 'name' entry for PostScript name in font /system/fonts/NotoSansSymbols-Regular.ttf

My code is for example:


        PDFont font = PDType1Font.HELVETICA_BOLD;
        // Start a new content stream which will "hold" the to be created content
        PDPageContentStream contentStream = new PDPageContentStream(document,page);


        // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
        contentStream.beginText();
        contentStream.setFont( font, 12 );
        contentStream.moveTextPositionByAmount( 100, 700 );

        contentStream.drawString( "Hello World" );
        contentStream.endText();

Is there an font which I can use?

INSTALL_FAILED_CPU_ABI_INCOMPATIBLE for 1.8.9 on Genymotion

Hi,

Not sure whether it's bug or just lack of my knowledge but when I add 1.8.9 library version to my project I cannot run my app in Genymotion emulator. My IDE (IntelliJ Idea) gives me message INSTALL_FAILED_CPU_ABI_INCOMPATIBLE. When I replace lib with version 1.8.7 everything runs ok and I can use library features in my project.

Add a jpg file into a pdf

Hi, I need to add a jpg file into a pdf file for my project. It was possible in the main pdfBox library but how to do it with pdfBox-android library since the PDJpeg class isn't here anymore?

Thank you

Error when loading PDF

When I try to execute the following:

PDDocument document = PDDocument.load(new File("/sdcard/Download/file.pdf"));

I get the following error:

01-14 11:56:16.064    4778-4778/? W/System.err﹕ java.io.IOException: offset < 0: -4096
01-14 11:56:16.064    4778-4778/? W/System.err﹕ at java.io.RandomAccessFile.seek(RandomAccessFile.java:597)
01-14 11:56:16.064    4778-4778/? W/System.err﹕ at org.apache.pdfbox.io.RandomAccessBufferedFileInputStream.seek(RandomAccessBufferedFileInputStream.java:102)
01-14 11:56:16.064    4778-4778/? W/System.err﹕ at org.apache.pdfbox.io.PushBackInputStream.seek(PushBackInputStream.java:218)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at org.apache.pdfbox.pdfparser.NonSequentialPDFParser.initialParse(NonSequentialPDFParser.java:476)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at org.apache.pdfbox.pdfparser.NonSequentialPDFParser.parse(NonSequentialPDFParser.java:940)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1030)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:944)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at com.mobilejazz.coltrane.example.FileDetailActivity.onCreate(FileDetailActivity.java:53)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5933)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
01-14 11:56:16.065    4778-4778/? W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
01-14 11:56:16.066    4778-4778/? W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Any ideas??

PDFTextStripperByArea failed extracting text (font problems?)

Hello,

I have tried the library with a lot of documents. It works fine but with some of them I got always a similar message:

11-06 14:59:34.737: E/PDResources(23440):   at java.lang.Thread.run(Thread.java:841)
11-06 14:59:34.737: W/PDTrueTypeFont(23440): Using fallback font for ArialMT
11-06 14:59:34.737: E/ExternalFonts(23440): No TTF fallback font for 'Helvetica'
11-06 14:59:34.737: W/PDTrueTypeFont(23440): Using fallback font for Tahoma
11-06 14:59:34.747: E/ExternalFonts(23440): No TTF fallback font for 'Helvetica'
11-06 14:59:34.747: W/PDTrueTypeFont(23440): Using fallback font for ArialNarrow
11-06 14:59:34.747: E/ExternalFonts(23440): No TTF fallback font for 'Helvetica'
11-06 14:59:34.747: W/PDTrueTypeFont(23440): Using fallback font for ArialNarrow-BoldItalic
11-06 14:59:34.747: E/ExternalFonts(23440): No TTF fallback font for 'Helvetica-BoldOblique'
11-06 14:59:34.747: W/System.err(23440): java.io.IOException: Error: Could not find referenced cmap stream Identity-H
11-06 14:59:34.747: W/System.err(23440):    at org.apache.fontbox.cmap.CMapParser.getExternalCMap(CMapParser.java:383)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.fontbox.cmap.CMapParser.parsePredefined(CMapParser.java:84)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.pdmodel.font.CMapManager.getPredefinedCMap(CmapManager.java:34)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.pdmodel.font.PDType0Font.readEncoding(PDType0Font.java:71)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.pdmodel.font.PDType0Font.<init>(PDType0Font.java:48)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:73)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.pdmodel.PDResources.getFonts(PDResources.java:172)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.contentstream.PDFStreamEngine.getFonts(PDFStreamEngine.java:503)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:32)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:466)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.contentstream.PDFStreamEngine.processSubStream(PDFStreamEngine.java:220)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.contentstream.PDFStreamEngine.processSubStream(PDFStreamEngine.java:185)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:139)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.contentstream.PDFTextStreamEngine.processStream(PDFTextStreamEngine.java:105)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.util.PDFTextStripper.processPage(PDFTextStripper.java:353)
11-06 14:59:34.747: W/System.err(23440):    at org.apache.pdfbox.util.PDFTextStripperByArea.extractRegions(PDFTextStripperByArea.java:102)

Sometimes is this message, and sometimes is "No fallback font for 'Helvetica'" or another font type

Is this a problem with this library, or maybe with PDFBox?

The code I have used is this:

PDFTextStripperByArea stripper = new PDFTextStripperByArea();

[...]
stripper.addRegion(k, regions_hash.get(k));
[...]

regions=stripper.getRegions();  
for(String region: regions) {
    String textForRegion = stripper.getTextForRegion(region);
    textForRegion=textForRegion.trim();

    if (!textForRegion.isEmpty()) {
        outStream.write((textForRegion+' ').getBytes());
    }
}

possible : PdfBox not generating a valid edited pdf

Im developing an app that is used to preview pdf files and add hand signature to them.
Im using two 3rd party libs: PdfBox (for editing) and MuPdf port for Android (for preview).

What i basically do is take a pdf file (not edited) from assets, show it to the user (using MuPdf), and then the user can (on button click) add a hand signature (inside different activity). I capture the signature bitmap and save the image on the SDCARD. After that i have a method insertImage (this is the ONLY piece of code in my app related to this library) like this

public static void insertImage(Context context) {
String pdfPath = context.getFilesDir() + File.separator + "/myPdf.pdf";
int marginFromEdge = 40;

PDDocument doc;
try {
  doc = PDDocument.load(new File(pdfPath));
  PDPage page = doc.getPage(0);

  File imageFile = new File(Environment.getExternalStorageDirectory() + "/PdfDir/image.jpg");
  File pdfFile = new File(Environment.getExternalStorageDirectory() + "/PdfDir/myPdfEdited.pdf");

  PDImageXObject pdImage = JPEGFactory.createFromStream(doc,
    new FileInputStream(imageFile));

  PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true);
  contentStream.drawImage(pdImage,
    page.getCropBox().getWidth() - pdImage.getWidth() - marginFromEdge, marginFromEdge);
  contentStream.close();

  doc.save(pdfFile);
  doc.close();
} catch (IOException e) {
  e.printStackTrace();
}

}

Now everything is working GREAT! Except when i go back from the signature activity i can't see the image that was inserted in the pdf, i see the pdf as it was before the signature.

When i open myPdfEdited.pdf with android adobe native viewer (or ANY other pdf viewer) i can see the signature but not with MuPdf, so i thought this was a MuPdf issue. But then i tried to add the same image in the pdf using a PC pdf editor and preview that image using my app and i can see the signature which tells me that MuPdf is working as it should. Maybe im not setting some parameter on the PDDocument...

So i thought maybe this is PdfBox issue because i can open every edited pdf file and preview it with MuPdf except the one that is saved in insertImage method by PdfBox doc.save(pdfFile).

I hope you understand my problem and i hope you can help.

Thanks.

Need Image Insertion in pdf`

Hi,

First of all very big thank to your pdfbox for android.it is very easy use jar ,who ever looking for pdf creation and merging.
From my side i have small request,can you please provide the image insertion any where in the document.and also need to set hyperlink for images.I have checked the pdfbox java version.this features are available in java,but that is completely based on awt.please update the jar.

Is there any possible to play videos within pdf document.

Thanks in advance

GlyphLoading fails

It appears glyph loading from a file fails when there is a blank line at the end of the file. Around like 116 in GlyphList.java, the function ready() is used to determine if there are any more characters left in the stream. This function returns 'true' at the end of the file, even when garbage will be parsed and returned as null.

Research shows that ready() checks if parsing will cause a block of the main thread, instead of actually seeing if the stream is still valid. Therefore, its use here is problematic.

Is PDFRenderer working now?

I saw couple of commits related to PDFRenderer, is it working now? I tried following code but didn't give any output

        InputStream inputStream = assetManager.open("Test.pdf");
        PDDocument pdDocument = PDDocument.load(inputStream);;
        PDFRenderer pdfRenderer = new PDFRenderer(pdDocument);
        Bitmap pageBitmap = pdfRenderer.renderImage(0);
        ImageView imageView = (ImageView)findViewById(R.id.imageView);
        imageView.setImageBitmap(pageBitmap);

If it is working now please provide a sample code for how to use it

Load external TTF fonts?

Hello, I notice that there are a lot of "No TTF fallback font for xxxx" errors showing up and I was wondering if I could load a TTF file into PDFBox so that it could use that instead of throwing an error. Is this possible or is there any way around this?

No glyph for U+000A in font Helvetica

I am trying to generate a PDF but I always have this issue:

java.lang.IllegalArgumentException: No glyph for U+000A in font Helvetica
        at org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:290)
        at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:249)
        at org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:292)

Another thing, always take aprox 30 segs to generate a pdf.
I think is because the look for al ttf in the system. It is possible to do more fast?

All the best

bug in below pdfStripper?

Thanks for your cool work!!

I found that is bug if i called below function:

static String pdftoText(String fileName, int ps, int pe) {
PDFParser parser;
String parsedText = null;;
PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File(fileName);
if (!file.isFile()) {
System.err.println("File " + fileName + " does not exist.");
return null;
}
try {
parser = new PDFParser(new FileInputStream(file));
} catch (IOException e) {
System.err.println("Unable to open PDF Parser. " + e.getMessage());
return null;
}
try {
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(ps);
pdfStripper.setEndPage(pe);
parsedText = pdfStripper.getText(pdDoc);
} catch (Exception e) {
System.err
.println("An exception occured in parsing the PDF Document."
+ e.getMessage());
} finally {
try {
if (cosDoc != null)
cosDoc.close();
if (pdDoc != null)
pdDoc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return parsedText;
}
pdftoText("D:\abc.pdf",1, 2);

09-23 22:29:23.680: W/System.err(25976): An exception occured in parsing the PDF Document.Error: could not find resource 'org/apache/pdfbox/resources/PDFTextStripper.properties' on classpath.

PDDocument.save(file) is very slow

Using PDFBox-Android, I'm currently loading my PDF into a PDDocument like so:

PDDocument pdDoc = PDDocument.load(file);
PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog();
PDAcroForm acroForm = pdCatalog.getAcroForm();

Then I am timing the save() function like this:

long substart = System.currentTimeMillis();
pdDoc.save(file);
Log.d("formData", "save took " + (System.currentTimeMillis() - substart) / 1000);

The save method is taking up to 10 seconds on a Nextbook NXA8QC116R (~6-7 seconds on my HTC One M8 And Lenovo Tab 2 A8) to save a PDF file that is only 93kb in size. I've also tried using a BufferedOutputStream to save the file, but that didn't seem to help.

Is this a flaw in the library, or is there something that I can do to help speed up the saving method for small files?

`PDXObjectImage` and `PDJpeg` equivalent ?

What are the android equivalent classes for the above mentioned classes ?

Or simply put , how can I add images while creating a pdf file . Have you been able to achieve this ?

How to generate jar file for the eclipse project

Hi,

I am trying to build the android project using the ./gradlew command in the android studio and it is generating jar files but this jar file contains java files instead of class files so when I am adding this jar files into eclipse its not working.

Please guide me to resolve this problem.

Thanks

PDF Form filling invisible text

When giving values to an acorform pdf and then saving said pdf and transferring to PC. Clicking a form field in adobe reader shows the text in the field , but it will not show if it is not clicked. Upon research of this, it seems as PDFBox is corrupting/damaging the pdf file. Ironically using Adobe Reader on Android, displays the PDF correctly.

Drawing transparent images

Does the library at the moment support drawing transparent images? I have a png with transparent background I need to draw.

At the moment I draw my pngs and jpgs by first loading them up into Bitmap objects and then using the following function to transform them into PDImageXObjects:

private PDImageXObject getImageXObjectFromBitmap(PDDocument doc, Bitmap bitmap) throws IOException {
    PDImageXObject image = null;

    if (image != null)
        return image;

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, 100, baos);
    byte[] bytes = baos.toByteArray();
    InputStream imageStream = new ByteArrayInputStream(bytes);

    image = JPEGFactory.createFromStream(doc, imageStream);

    baos.close();
    imageStream.close();

    return image;

}

not able to write text containing characters like € in PDF

I was trying to write string 500 €/year** as follows,

pageContentStream.drawString("500 " + Html.fromHtml(getString(R.string.euro)).toString() + "/hour");

where euro is defined in strings.xml as

<string name="euro">(&#8364;)</string>
<string name="pound">(&#163;)</string>

With above code it is writing some gibberish characters.

I found one solution here to write , which is working perfectly.

I want to write whole text in one go, is it possible?

Or do I need to write first, then move text next to it and then write remaining text?

I don't feel that would be a correct solution.

Long class load times

When I first boot up the library to generate a PDF, I'm getting really long (30 seconds) just to load the library to the point where I can start generating PDFs. I went through the source and I think the problem is that class such as ExternalFonts and GlyphList are loading resources from disk when the class is loaded. Is there a way that we can shift this into a static initialization method or document that the static loading is occurring?

PDType1Font should use encoding field instead of MacOSRomanEncoding.INSTANCE

In PDType1Font#getInvertedEncoding(), the MacOSRomanEncoding is inverted and used to look up non-ASCII-characters but the field "encoding" should be used here.
You can test it with when you write a german string with umlauts to a PDF.

Class PDTrueTypeFont also uses a hard coded reference to MacOSRomanEncoding but here I can't judge if it's also incorrect. It would be worth an examination.

PdfViewer porting

Any plan to port PdfViewer? I'm desperately looking for that.....

Draw fill rectangle

Hello,

Can I draw a fill rectangle with this lib? In the Apache's PdfBox, there is a method fillRect() able to draw a fill rectangle, but I don't see it in this lib.

Render PDF pages to images

How can this library be used to render PDF pages to images similar to PDFImageWriter in Apache PDFBox

Search Fonts Slow?

So to use showText it appears you have to define a PDFont. When I put the code in for PDFont it seems to hang and take quite a few seconds to process the fonts. Is this normal? Below is the code and output when it is hanging. It doesn't crash, but takes awhile, about 5 seconds. Thanks

Running: pdfbox-android-1.8.9.jar

Code:

PDPageContentStream contentStream = new PDPageContentStream(document, document.getPage(0), true, true);
PDFont font = PDType1Font.HELVETICA_BOLD;
contentStream.drawImage(ximage, 325, 300, 275, 390);
contentStream.beginText();
contentStream.newLineAtOffset(50, 190);
contentStream.setFont(font, 12);
contentStream.setStrokingColor(0.0f, 0.0f, 0.0f, 1.0f);
contentStream.showText("Some text to insert into a table.");
contentStream.endText();
contentStream.close();
document.save(Environment.getExternalStorageDirectory().getPath() + "/newPdfWithImage.pdf");
document.close();

Log:
--------- beginning of system
04-27 10:55:25.268 27536-27536/myapp V/PdfBoxAndroid﹕ Will search the local system for fonts
04-27 10:55:25.285 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'AndroidClock-Regular' / 'AndroidClock' / 'Regular'
04-27 10:55:25.292 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'AndroidClock-Large-Regular' / 'AndroidClock-Large' / 'Regular'
04-27 10:55:25.299 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'AndroidClock-Large-Regular' / 'AndroidClock-Large' / 'Regular'
04-27 10:55:25.310 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'CarroisGothicSC-Regular' / 'Carrois Gothic SC' / 'Regular'
04-27 10:55:25.318 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Clockopia' / 'Clockopia' / 'Regular'
04-27 10:55:25.329 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'ComingSoon' / 'Coming Soon' / 'Regular'
04-27 10:55:25.339 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'CutiveMono-Regular' / 'Cutive Mono' / 'Regular'
04-27 10:55:25.350 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'DancingScript-Bold' / 'Dancing Script' / 'Bold'
04-27 10:55:25.361 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'DancingScript' / 'Dancing Script' / 'Regular'
04-27 10:55:25.370 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Bold' / 'Roboto Bold' / 'Bold'
04-27 10:55:25.379 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Regular' / 'Roboto' / 'Regular'
04-27 10:55:25.387 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'DroidSansFallback' / 'Droid Sans Fallback' / 'Regular'
04-27 10:55:25.395 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'DroidSansMono' / 'Droid Sans Mono' / 'Regular'
04-27 10:55:25.403 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'MotoyaLMaru-W3-90ms-RKSJ-H' / 'MotoyaLMaru' / 'W3 mono'
04-27 10:55:25.414 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NanumGothic' / 'NanumGothic' / 'Regular'
04-27 10:55:25.420 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoColorEmoji' / 'Noto Color Emoji' / 'Regular'
04-27 10:55:25.427 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoNaskhArabic-Bold' / 'Noto Naskh Arabic' / 'Bold'
04-27 10:55:25.434 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoNaskhArabic' / 'Noto Naskh Arabic' / 'Regular'
04-27 10:55:25.442 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoNaskhArabicUI-Bold' / 'Noto Naskh Arabic UI' / 'Bold'
04-27 10:55:25.449 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoNaskhArabicUI' / 'Noto Naskh Arabic UI' / 'Regular'
04-27 10:55:25.456 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansArmenian-Bold' / 'Noto Sans Armenian' / 'Bold'
04-27 10:55:25.463 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansArmenian' / 'Noto Sans Armenian' / 'Regular'
04-27 10:55:25.470 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansBengali-Bold' / 'Noto Sans Bengali' / 'Bold'
04-27 10:55:25.477 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansBengali' / 'Noto Sans Bengali' / 'Regular'
04-27 10:55:25.484 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansBengaliUI-Bold' / 'Noto Sans Bengali UI' / 'Bold'
04-27 10:55:25.491 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansBengaliUI' / 'Noto Sans Bengali UI' / 'Regular'
04-27 10:55:25.499 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansDevanagari-Bold' / 'Noto Sans Devanagari' / 'Bold'
04-27 10:55:25.506 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansDevanagari' / 'Noto Sans Devanagari' / 'Regular'
04-27 10:55:25.513 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansDevanagariUI-Bold' / 'Noto Sans Devanagari UI' / 'Bold'
04-27 10:55:25.519 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansDevanagariUI' / 'Noto Sans Devanagari UI' / 'Regular'
04-27 10:55:25.525 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansEthiopic-Bold' / 'Noto Sans Ethiopic' / 'Bold'
04-27 10:55:25.531 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansEthiopic' / 'Noto Sans Ethiopic' / 'Regular'
04-27 10:55:25.538 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansGeorgian-Bold' / 'Noto Sans Georgian' / 'Bold'
04-27 10:55:25.545 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansGeorgian' / 'Noto Sans Georgian' / 'Regular'
04-27 10:55:25.550 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansHebrew-Bold' / 'Noto Sans Hebrew' / 'Bold'
04-27 10:55:25.555 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansHebrew' / 'Noto Sans Hebrew' / 'Regular'
04-27 10:55:25.563 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKannada-Bold' / 'Noto Sans Kannada' / 'Bold'
04-27 10:55:25.570 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKannada' / 'Noto Sans Kannada' / 'Regular'
04-27 10:55:25.576 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKannadaUI-Bold' / 'Noto Sans Kannada UI' / 'Bold'
04-27 10:55:25.584 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKannadaUI' / 'Noto Sans Kannada UI' / 'Regular'
04-27 10:55:25.591 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKhmer-Bold' / 'Noto Sans Khmer' / 'Bold'
04-27 10:55:25.598 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKhmer' / 'Noto Sans Khmer' / 'Regular'
04-27 10:55:25.606 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKhmerUI-Bold' / 'Noto Sans Khmer UI' / 'Bold'
04-27 10:55:25.614 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansKhmerUI' / 'Noto Sans Khmer UI' / 'Regular'
04-27 10:55:25.620 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansLao-Bold' / 'Noto Sans Lao' / 'Bold'
04-27 10:55:25.627 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansLao' / 'Noto Sans Lao' / 'Regular'
04-27 10:55:25.633 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansLaoUI-Bold' / 'Noto Sans Lao UI' / 'Bold'
04-27 10:55:25.639 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansLaoUI' / 'Noto Sans Lao UI' / 'Regular'
04-27 10:55:25.646 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMalayalam-Bold' / 'Noto Sans Malayalam' / 'Bold'
04-27 10:55:25.653 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMalayalam' / 'Noto Sans Malayalam' / 'Regular'
04-27 10:55:25.660 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMalayalamUI-Bold' / 'Noto Sans Malayalam UI' / 'Bold'
04-27 10:55:25.667 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMalayalamUI' / 'Noto Sans Malayalam UI' / 'Regular'
04-27 10:55:25.673 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMyanmar-Bold' / 'Noto Sans Myanmar' / 'Bold'
04-27 10:55:25.680 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMyanmar' / 'Noto Sans Myanmar' / 'Regular'
04-27 10:55:25.688 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMyanmarUI-Bold' / 'Noto Sans Myanmar UI' / 'Bold'
04-27 10:55:25.695 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansMyanmarUI' / 'Noto Sans Myanmar UI' / 'Regular'
04-27 10:55:25.703 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansSymbols' / 'Noto Sans Symbols' / 'Regular'
04-27 10:55:25.709 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTamil-Bold' / 'Noto Sans Tamil' / 'Bold'
04-27 10:55:25.718 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTamil' / 'Noto Sans Tamil' / 'Regular'
04-27 10:55:25.725 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTamilUI-Bold' / 'Noto Sans Tamil UI' / 'Bold'
04-27 10:55:25.732 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTamilUI' / 'Noto Sans Tamil UI' / 'Regular'
04-27 10:55:25.739 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTelugu-Bold' / 'Noto Sans Telugu' / 'Bold'
04-27 10:55:25.747 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTelugu' / 'Noto Sans Telugu' / 'Regular'
04-27 10:55:25.772 27536-27544/myapp W/art﹕ Suspending all threads took: 18.371ms
04-27 10:55:25.784 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTeluguUI-Bold' / 'Noto Sans Telugu UI' / 'Bold'
04-27 10:55:25.802 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansTeluguUI' / 'Noto Sans Telugu UI' / 'Regular'
04-27 10:55:25.810 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansThai-Bold' / 'Noto Sans Thai' / 'Bold'
04-27 10:55:25.818 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansThai' / 'Noto Sans Thai' / 'Regular'
04-27 10:55:25.825 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansThaiUI-Bold' / 'Noto Sans Thai UI' / 'Bold'
04-27 10:55:25.834 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSansThaiUI' / 'Noto Sans Thai UI' / 'Regular'
04-27 10:55:25.841 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSerif-Bold' / 'Noto Serif' / 'Bold'
04-27 10:55:25.848 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSerif-BoldItalic' / 'Noto Serif' / 'Bold Italic'
04-27 10:55:25.855 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSerif-Italic' / 'Noto Serif' / 'Italic'
04-27 10:55:25.868 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'NotoSerif' / 'Noto Serif' / 'Regular'
04-27 10:55:25.877 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Black' / 'Roboto Black' / 'Black'
04-27 10:55:25.887 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-BlackItalic' / 'Roboto Black' / 'Black Italic'
04-27 10:55:25.895 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Bold' / 'Roboto Bold' / 'Bold'
04-27 10:55:25.905 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-BoldItalic' / 'Roboto Bold' / 'Bold Italic'
04-27 10:55:25.913 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Italic' / 'Roboto' / 'Italic'
04-27 10:55:25.923 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Light' / 'Roboto Light' / 'Light'
04-27 10:55:25.931 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-LightItalic' / 'Roboto Light' / 'Light Italic'
04-27 10:55:25.941 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Medium' / 'Roboto Medium' / 'Medium'
04-27 10:55:25.950 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-MediumItalic' / 'Roboto Medium' / 'Medium Italic'
04-27 10:55:25.957 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Regular' / 'Roboto' / 'Regular'
04-27 10:55:25.966 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-Thin' / 'Roboto Thin' / 'Thin'
04-27 10:55:25.976 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'Roboto-ThinItalic' / 'Roboto Thin' / 'Thin Italic'
04-27 10:55:25.985 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'RobotoCondensed-Bold' / 'Roboto Condensed Bold' / 'Bold'
04-27 10:55:25.994 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'RobotoCondensed-BoldItalic' / 'Roboto Condensed Bold' / 'Bold Italic'
04-27 10:55:26.002 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'RobotoCondensed-Italic' / 'Roboto Condensed' / 'Italic'
04-27 10:55:26.011 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'RobotoCondensed-Light' / 'Roboto Condensed Light' / 'Light'
04-27 10:55:26.021 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'RobotoCondensed-LightItalic' / 'Roboto Condensed Light' / 'Light Italic'
04-27 10:55:26.029 27536-27536/myapp V/PdfBoxAndroid﹕ TTF: 'RobotoCondensed-Regular' / 'Roboto Condensed' / 'Regular'
04-27 10:55:26.029 27536-27536/myapp V/PdfBoxAndroid﹕ Found 91 fonts on the local system
04-27 10:55:26.047 27536-27536/myapp D/PdfBoxAndroid﹕ Loaded Roboto-Regular from /system/fonts/Roboto-Regular.ttf
04-27 10:55:26.058 27536-27536/myapp D/PdfBoxAndroid﹕ Loaded Roboto-Bold from /system/fonts/Roboto-Bold.ttf
04-27 10:55:26.068 27536-27536/myapp D/PdfBoxAndroid﹕ Loaded Roboto-Italic from /system/fonts/Roboto-Italic.ttf
04-27 10:55:26.079 27536-27536/myapp D/PdfBoxAndroid﹕ Loaded Roboto-BoldItalic from /system/fonts/Roboto-BoldItalic.ttf
04-27 10:55:26.091 27536-27536/myapp D/PdfBoxAndroid﹕ Loaded DroidSansMono from /system/fonts/DroidSansMono.ttf

Build configuration

How do I build the source? Is there maven or any other configuration available?
Thanks,

License

This library helps me a lot. I would like to put a reference to your work in my license file.

What do you want me to put in?

I can put something like:

Apache PDFBox
    Copyright 2014 The Apache Software Foundation

    This product includes software developed at
    The Apache Software Foundation (http://www.apache.org/).

    Based on source code originally developed in the PDFBox and 
    FontBox projects.

    Copyright (c) 2002-2007, www.pdfbox.org

    Based on source code originally developed in the PaDaF project.
    Copyright (c) 2010 Atos Worldline SAS

    Includes the Adobe Glyph List
    Copyright 1997, 1998, 2002, 2007, 2010 Adobe Systems Incorporated.

    Includes the Zapf Dingbats Glyph List
    Copyright 2002, 2010 Adobe Systems Incorporated."

But with your data.

PDF Form with comb text field

When trying to set the value of a textfield that has comb within a form PDF the following error occurs.

02-27 10:09:09.299  24004-24004/com.dixieind.dixieapplication E/﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'float org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(java.lang.String)' on a null object reference
            at org.apache.pdfbox.service.interactive.form.PDAppearanceString.calculateFontSize(PDAppearanceString.java:475)
            at org.apache.pdfbox.service.interactive.form.PDAppearanceString.setAppearanceValue(PDAppearanceString.java:234)
            at org.apache.pdfbox.service.interactive.form.AppearanceGenerator.generateFieldAppearances(AppearanceGenerator.java:66)
            at org.apache.pdfbox.pdmodel.interactive.form.PDField.updateFieldAppearances(PDField.java:103)
            at org.apache.pdfbox.pdmodel.interactive.form.PDTextField.setValue(PDTextField.java:264)
            at com.dixieind.dixieapplication.PdfWriter2.viewToPdf(PdfWriter2.java:317)
            at com.dixieind.dixieapplication.GovernmentForm1.OpenAdobeReader(GovernmentForm1.java:60)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4002)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Output pdf file invalid

I am a beginner for this project. I created the hello world pdf. But it can not opened on the phone or on the PC. Please help to check about it. Thanks!

I add this code in the button onClick() function:

PDDocument document = new PDDocument();
            PDPage page = new PDPage();
            document.addPage( page );

            // Create a new font object selecting one of the PDF base fonts
            PDFont font = PDType1Font.HELVETICA_BOLD;

            // Start a new content stream which will "hold" the to be created content
            PDPageContentStream contentStream;
            try {
                contentStream = new PDPageContentStream(document, page);
                // Define a text content stream using the selected font, moving the cursor and drawing the text "Hello World"
                contentStream.beginText();
                contentStream.setFont( font, 12 );
                contentStream.moveTextPositionByAmount( 100, 700 );
                contentStream.drawString( "Hello World" );
                contentStream.endText();

                // Make sure that the content stream is closed:
                contentStream.close();

                // Save the results and ensure that the document is properly closed:
                document.save(Environment.getExternalStorageDirectory().getPath()
                        + "/Hello World.pdf");
                document.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

using the newest pdfbox-android-1.8.8 jar library file in android sdk 19
UPDATE: pdfbox-android-1.8.7 work!!

Remove Apache Commons Logging library

Suggestion to replace Apache Commons Logging library with Android's Log.

Probably isn't a big issue to do the first time, but when merging in changes from PDFBox it might turn into a problem.

Unable to parse file

Hi ,I have used this jar and i am unable to parse pdf file.I am getting following error message.

Could not find method java.io.IOException., referenced from method org.apache.pdfbox.pdfparser.BaseParser.readLong

Could not find method java.io.IOException., referenced from method org.apache.pdfbox.pdfparser.BaseParser.parseCOSString

Can you tell me what would be the reason for this

Bug in PDFMergerUtility (with FIX)

If i merge to pdf files with sublings, i the exception "A single node with no siblings is required".

To fix this bug, replace the lines 210 until 214 in the PDFMergerUtility.java

PDOutlineItem var43 = srcOutline.getFirstChild();
                        if(var43 != null) {
                            PDOutlineItem srcPageMode = new PDOutlineItem((COSDictionary)cloner.cloneForNewDocument(var43));
                            destOutline.addLast(srcPageMode);
                        }

with the following code:

for (PDOutlineItem item : srcOutline.children()) {
                            // get each child, clone its dictionary, remove siblings info,
                            // append outline item created from there
                            COSDictionary clonedDict = (COSDictionary) cloner.cloneForNewDocument(item);
                            clonedDict.removeItem(COSName.PREV);
                            clonedDict.removeItem(COSName.NEXT);
                            PDOutlineItem clonedItem = new PDOutlineItem(clonedDict);
                            destOutline.addLast(clonedItem);
}

This code is from the official pdfbox trunk and works fine. I have tested it.

GlyphList.loadList Error in 1.8.8

Hi Birdbrain2,
I am using pdfbox-android for few month now in my android app.
I am facing a problem with the extraction of text on Korean files. I tried to upgrade to 1.8.8 to see if there is any improvements. But when using 1.8.8 I always crash with this error :

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.startsWith(java.lang.String)' on a null object reference
at org.apache.pdfbox.pdmodel.font.encoding.GlyphList.loadList(GlyphList.java:104)

I am probably doing something wrong but I've got no problem with 1.8.7 and 1.8.6.

PDPageContentStream's append mode misbehaving.

I am drawing an image on one of the PDF page.. when I use PDPageContentStream stream = new PDPageContentStream(doc, page); to draw image, everything works fine.. see below image.

image

but when I use constructor PDPageContentStream stream = new PDPageContentStream(doc, page, true, true); to create PDPageContentStream to draw image the newly added image gets inverted upside down..

image

Not sure whether it's an issue or it should work like this only.. if it's not the bug then can you suggest any workaround?

Can't get showText() to work (font exceptions)

(Working on Android 4.3, Android Studio 1.4, please ask if you need more info)

I can't get writing text to work, which seems to be related to font problems. Using a version of the library from earlier this year (a co-worker included a copy of the .jar file in the project at that time), I used to get errors of the following kind when calling PDPageContentStream.showText():

 "java.lang.IllegalArgumentException: No glyph for U+0053 in font Times-Bold"

The font I used here was PDType1Font.TIMES_BOLD.

I've given up on that version and added the recommended build.gradle dependency instead:

 compile 'org.apache:pdfbox-android:1.8.9.0'

But now the showText() call crashes with a null pointer exception (I'm using TIMES_ROMAN now if it makes a difference - I guess that it doesn't):

10-15 01:07:52.213 13986-13986/com.ems.test W/System.err: java.lang.NullPointerException
10-15 01:07:52.221 13986-13986/com.ems.test W/System.err:     at org.apache.pdfbox.pdmodel.font.PDType1Font.getNameInFont(PDType1Font.java:422)
10-15 01:07:52.221 13986-13986/com.ems.test W/System.err:     at org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:285)
10-15 01:07:52.221 13986-13986/com.ems.test W/System.err:     at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:249)
10-15 01:07:52.221 13986-13986/com.ems.test W/System.err:     at org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:292)

For your reference, here is an excerpt from my code:

    PDDocument document = new PDDocument();
    PDPageContentStream contentStream;
    PDPage titlePage = new PDPage(PDRectangle.A4);
    document.addPage(titlePage);
    PDPage page = new PDPage(PDRectangle.A4);
    document.addPage(page);
    contentStream = new PDPageContentStream(document, page);
    PDRectangle rect = page.getMediaBox();
    PDFont fontPlain = PDType1Font.TIMES_ROMAN; 

    contentStream.beginText();
    contentStream.setFont(fontPlain, 12);
    contentStream.newLineAtOffset(rect.getWidth() / 2, 20);
    contentStream.showText("S");    <---------- this crashes
    contentStream.endText();

Is there any other information I need to get the library to work? Or does it work in principle but I have to limit myself to certain fonts, and if so, which ones and how do I select them? Perhaps you could just point me to an example that works? I couldn't find any, and the documentation seems to be rather sparse.

Thanks a lot for your time

fail to load non-english pdf

Hi,

I found that if I try to extract txt from non-english pdf, for example, a Chinese one, it gives some "wrong" text. e.g.

https://www.spj.org/pdf/ethicscode-chinese.pdf

    long startTime = System.currentTimeMillis();        
    String data = null;
    try {
           File tempFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "scratchfile");
           File pdfFile = new File(filename);
           tempFile.createNewFile();
           RandomAccess scratchFile;            
           scratchFile = new RandomAccessFile(tempFile, "rw");
           PDFTextStripper textStripper = new PDFTextStripper();
           PDDocument doc = PDDocument.loadNonSeq(pdfFile, scratchFile);
           if (pe==-1) pe= doc.getNumberOfPages();
           textStripper.setStartPage(ps);
           textStripper.setEndPage(pe);            
           data = textStripper.getText(doc);            
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

java.lang.ArrayIndexOutOfBoundsException in android.graphics.Matrix.setValues

PDPageContentStream

The Android Matrix class needs 9 Values otherwise the ArrayIndexOutOfBoundsException is throw.
To create a correct AffineTransform with the Android Matrix class the following lines needs to be changed.

Line: 483

transform.setValues(new float[] {width, 0, 0, height, x, y});  

must be replaced with

transform.setValues(new float[] {width, 0, x, 0, height, y, 0, 0, 1 });

Line: 618:

transform.setValues(new float[] {width, 0, 0, height, x, y}); 

must be replaced with

transform.setValues(new float[] {width, 0, x, 0, height, y, 0, 0, 1 });

How to get all positions of specific term in PDF

I'd like to get all the TextPosition of a term. Is this possible ?
This will be used to implement a "search term" functionnality in a project.
Then with these positions, I'll highlight the text with the coordinnates.
Thaks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.