I'm using Flying Saucer to generate PDF from HTML (so I'm using ITextRenderer, if that matters.)
I would like to simulate something like what Webkit or Gecko put in when the image cannot be found - something like an inset outline and a little broken page image.
I have determined that overriding getImageResource
in the UserAgentCallback
is a way to test for this condition (the image in the ImageResource
will be null
) but I can't figure out a nice way to render a placeholder at this point in the API.
Is there a proper way to do this? (It would be nice if this happened out of the box...)
You're on the right track here.
You want to extend UserAgentCallback with your own custom user agent functionality. It should perform almost the identical functionality of what the existing Flying Saucer implementation does, except, when an image is not found, it should return the default broken page image that you want to include.
If you're using the iTextRenderer, there is an ITextUserAgent class which you can extend for your own custom UserAgent.
To set the UserAgent, after you create the ITextRenderer, use the following code.