TomRoush / PdfBox-Android

The Apache PdfBox project ported to work on Android
Apache License 2.0
1.02k stars 263 forks source link

Search Fonts Slow? #38

Closed ghost closed 9 years ago

ghost commented 9 years ago

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

AedonEtLIRA commented 9 years ago

This, I believe, is related (if not exactly) my issue from #32. I think the cause is that all the fonts are loaded statically in bulk instead of on request or as singles. If you look at the source for any of the font related classes you can see what I'm talking about. When finals are over, I was hoping to hop in and see if I couldn't offer a fix to birdbrain.

ghost commented 9 years ago

@AedonEtLIRA Ah yes same exact issue! I must have missed your issue didn't see it before I posted this.

Sounds good, I will check back here and post up anything if I find a solution. Thanks.

TomRoush commented 9 years ago

Sorry for taking so long to respond to this. I'm going to close this as duplicate since this is the pretty much the same as AedonEtLIRA's speed issue. If you haven't already looked at that issue, he does a good job of explaining what's most likely closing the slowness. If you determine something else is causing it, please reopen this issue.

ghost commented 9 years ago

Fixed -> https://github.com/Birdbrain2/PdfBox-Android/issues/32