-
Notifications
You must be signed in to change notification settings - Fork 356
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
NullPointerException returning PdfImageElement in custom ReplacedElementFactory class. #111
Comments
Hi @syedkaleem29 Thanks for using the library and let us know how you go. |
Hi @danfickle, I got the image to work thanks a lot for that. I am using this library for RTL support and The text in pdf and browser are completely different styling though I know the alphabets are the same. I am using font from a file using I saw the source code for Even your online sand box shows disjointed Arabic text. Please guide me on this one. Also, is it possible to associate a hyperlink with an image? Thanks a lot for your awesome library and support. |
It should be possible to use an image as a hyperlink. Are you having a specific difficulty? In regards to the Arabic shaping issue, it's a bit of hit and miss with fonts. Specifically, the project just converts Arabic text characters into their presentational format equivalents (beginning, middle or end). Therefore, this will only work if the font supports those characters. Browsers, on the other hand, use a text shaping engine (harfbuzz) and don't need the presentational characters in the font. I can tell you the setup of the showcase document if that is any help. Firstly, this is the settings: PdfRendererBuilder builder = new PdfRendererBuilder();
builder.useUnicodeBidiSplitter(new ICUBidiSplitter.ICUBidiSplitterFactory());
builder.useUnicodeBidiReorderer(new ICUBidiReorderer());
builder.defaultTextDirection(TextDirection.LTR);
builder.useUnicodeLineBreaker(new ICUBreakers.ICULineBreaker(Locale.US));
builder.useUnicodeCharacterBreaker(new ICUBreakers.ICUCharacterBreaker(Locale.US));
builder.useUnicodeToLowerTransformer(new ICUTransformers.ICUToLowerTransformer(Locale.US));
builder.useUnicodeToUpperTransformer(new ICUTransformers.ICUToUpperTransformer(Locale.US));
builder.useUnicodeToTitleTransformer(new ICUTransformers.ICUToTitleTransformer(Locale.US)); Then the
Finally the font used is:
You may also with to read PDF-BOX 3550 - Text shaping for an insight into text shaping with PDFs. |
Hey, @danfickle thank you so much the font works now. You are right only Noto Naskh Arabic works. I have only two more issues. The image I replaced using the custom Replaced factory has an attribute which is an external link and that needs to be annotated to the image. The image is of type PdfBoxImage. Should I use a PdfBoxLinkManager? Also, it would be great to have no HTML changes. Because I do not have the liberty for that in my project. It was done in flying saucer using Image.setAnnotation. The print dialogue of the browser needs to open based on a boolean value. I just want to know how to add the open print dialogue box action to the PdfCreationListener class. Pardon for this silly question. Is it possible for me to use ITextRenderer at all? Edit: Even if having around my image is my only option I am getting a blue line below the image. |
I have a few doubts. I believe Flying saucer uses IText to convert PDF from XHTML. Am I right? and this project uses PDFBox to do the same even though being a clone of the flying saucer. May I know the reason behind this? |
I have defined my own image replacement factory which based on the value of the src attribute get the location of the image file. Converts file into a byte array and then renders the image for the PDF.
To achieve this I used the following code in createReplacedElement method of my class.
Which in all sense should work because a PdfBoxImage was created and it was returned as ReplacedElementFactory. Just like in the source code of PdfBoxReplacedElementFactory.
The real catch here is PdfBoxImage has another member field PDImageXObject which is set to null in my case and the PdfBoxOutputDevice uses this object. Hence, the NPE.
So does this mean the constructor PdfBoxImage(byte[], String) is useless?
Logs for reference
Finally, this was possible in flying-saucer.
So is this an issue? or am I doing something terribly wrong?
Waiting for your response.
The text was updated successfully, but these errors were encountered: