使用飞碟(ITextRenderer)解决受保护的资源 [英] Resolving protected resources with Flying Saucer (ITextRenderer)

查看:458
本文介绍了使用飞碟(ITextRenderer)解决受保护的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flying Saucer从tomcat服务器上托管的xhtml创建pdf. pdf中包含的大多数图像都是公开可用的(徽标等),但是其中一些图像在登录后受到保护(也就是说,如果用户已登录,则它们将通过servlet进行流传输).

I'm using Flying Saucer to create a pdf from xhtml, hosted on a tomcat server. Most of the images included in the pdf are publicly available (logos and so on), but some of them are protected behind a login (that is, they are streamed through a servlet if the user is logged in).

当我将URL粘贴到浏览器中时,图像当然显示得很好,因为浏览器发送带有请求的会话.但是,在飞碟呈现pdf时,它不包含受保护的图像,因为它对会话一无所知.

When I paste the url in the browser, the image is of course displayed fine, because the browser sends the session with the request. But when Flying Saucer renders the pdf, it doesn't include the protected image because it doesn't know anything about the session.

所以,我的问题是;有没有办法包括飞碟解析的字节流,就像可以添加可解析的字体一样?我尝试了类似 ,但是没有简单的方法可以在ITextRenderer上设置UAC,并且每次我尝试时都会抱怨.

So, my question is; is there any way to include the byte streams for Flying Saucer to resolve, just as it is possible to add resolvable fonts? I have tried something like this, but there is no easy way to set the UAC on the ITextRenderer, and it complained every time i tried.

推荐答案

您可以通过这种方式设置UserAgentCallback,然后飞碟将使用它来解析网址(经过测试,可与版本8一起使用):

You can set the UserAgentCallback this way, and Flying Saucer will use it to resolve the urls (tested, works with Release 8):

ITextRenderer renderer = new ITextRenderer();
renderer.getSharedContext().setUserAgentCallback(new MyUAC());

MyUAC应该扩展NaiveUserAgent,并按照另一页的建议覆盖resolveAndOpenStream方法.

MyUAC should extend the NaiveUserAgent, and override the resolveAndOpenStream method as the other page suggests.

这篇关于使用飞碟(ITextRenderer)解决受保护的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆