[英]Open Dynamically generated pdf as html page
I am working on web development project IDE used:Eclipse Language:JAVA(framework used:hibernate,struts2) 我正在使用以下Web开发项目IDE:Eclipse语言:JAVA(使用的框架:休眠,struts2)
I have created a pdf file using java and I want to view that dynamically created pdf as a html page. 我已经使用Java创建了一个pdf文件,我想将动态创建的pdf查看为html页面。
Here is my code 这是我的代码
public String SOSViewFile()
{
try {
HttpServletResponse response = ServletActionContext.getResponse();
PDFGenerator pdf = new PDFGenerator();
PDFGenerator generator=new PDFGenerator();
/* byte[] bytes = null;
bytes = (generator.generatepdf(sosValues.getCmaId(), null)).toByteArray();
//bytes = buffer.toByteArray();
response.setContentLength(bytes.length);
if (bytes != null) {
bis = new ByteArrayInputStream(bytes);
}*/
baos=generator.generatepdf(sosValues.getCmaId(), null);
bis = new ByteArrayInputStream(baos.toByteArray());
PdfReader pdfReader=new PdfReader(bis);
PdfStamper pdfStamper=new PdfStamper(pdfReader, baos);
pdfStamper.setEncryption(null, null, PdfWriter.HideToolbar, PdfWriter.STRENGTH40BITS);
pdfStamper.close();
bis = new ByteArrayInputStream(baos.toByteArray());
///baos.close();
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
bis and baos are 之二和宝
private InputStream bis;
private ByteArrayOutputStream baos;
Please help me in converting this generated pdf file to a html. 请帮助我将生成的pdf文件转换为html。
Write the generated bytes to the servlet response's OutputStream
and set the mime-type to application/pdf. 将生成的字节写入servlet响应的
OutputStream
,并将mime-type设置为application / pdf。
It won't convert it to HTML (of course), but many browsers will open it directly (YMMV). 它不会将其转换为HTML(当然),但是许多浏览器会直接将其打开(YMMV)。
The tool that might help you is CSSBox/pdf2dom . 可能会帮助您的工具是CSSBox / pdf2dom 。 It converts pdf to html page.
它将pdf转换为html页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.