Jasper reports 通过Vaadin组件打开用JasperReports制作的pdf
这是我第一次尝试通过Vaadin组件打开用iReport制作的pdf。我在很多论坛上看到过,但我不明白 现在我将尝试解释我的问题:Jasper reports 通过Vaadin组件打开用JasperReports制作的pdf,jasper-reports,vaadin,Jasper Reports,Vaadin,这是我第一次尝试通过Vaadin组件打开用iReport制作的pdf。我在很多论坛上看到过,但我不明白 现在我将尝试解释我的问题: 我用iReport创建了文件(.jasper) 我想在单击Vaadin按钮时打开此文件 你有什么可以帮我的吗?更新: 生成的pdf是pdf格式还是流式格式? Firefox/Chrome: 此浏览器有自己的“应用程序/pdf”查看器 Internet Explorer: 要查看IE上的PDF,请使用Adobe Acrobat Reader。 Adobe Acroba
private void viewDocument()
{
final String retrievalName = "222.pdf";
Window window = new Window();
window.setCaption("View PDF");
window.getContent().setSizeFull();
final StreamResource resource = new StreamResource(new StreamResource.StreamSource()
{
public InputStream getStream()
{
try
{
byte[] DocContent = null;
DocContent = getFileBytes("C:\\Temp\\222.pdf");
return new ByteArrayInputStream(DocContent);
}
catch (Exception e1)
{
e1.printStackTrace();
return null;
}
}
}, retrievalName, getMainWindow().getApplication());
Embedded c = new Embedded("", resource);
c.setSizeFull();
resource.setMIMEType("application/pdf");
c.setType(Embedded.TYPE_BROWSER);
window.addComponent(c);
window.setModal(true);
window.setWidth("90%");
window.setHeight("90%");
getMainWindow().addWindow(window);
}
/**
* getFileBytes
*
* @author NBochkarev
*
* @param fileOut
* @return
* @throws IOException
*/
public static byte[] getFileBytes(String fileName) throws IOException
{
ByteArrayOutputStream ous = null;
InputStream ios = null;
try
{
byte[] buffer = new byte[4096];
ous = new ByteArrayOutputStream();
ios = new FileInputStream(new java.io.File(fileName));
int read = 0;
while ((read = ios.read(buffer)) != -1)
ous.write(buffer, 0, read);
}
finally
{
try
{
if (ous != null)
ous.close();
}
catch (IOException e)
{
// swallow, since not that important
}
try
{
if (ios != null)
ios.close();
}
catch (IOException e)
{
// swallow, since not that important
}
}
return ous.toByteArray();
}
更新:
生成的pdf是pdf格式还是流式格式?
Firefox/Chrome:
此浏览器有自己的“应用程序/pdf”查看器
Internet Explorer:
要查看IE上的PDF,请使用Adobe Acrobat Reader。
Adobe Acrobat Reader浏览器安装插件。
此插件检测应用程序/pdf内容,并在Internet Explorer中显示自己的查看器
这是在瓦丁制作的样品:
private void viewDocument()
{
final String retrievalName = "222.pdf";
Window window = new Window();
window.setCaption("View PDF");
window.getContent().setSizeFull();
final StreamResource resource = new StreamResource(new StreamResource.StreamSource()
{
public InputStream getStream()
{
try
{
byte[] DocContent = null;
DocContent = getFileBytes("C:\\Temp\\222.pdf");
return new ByteArrayInputStream(DocContent);
}
catch (Exception e1)
{
e1.printStackTrace();
return null;
}
}
}, retrievalName, getMainWindow().getApplication());
Embedded c = new Embedded("", resource);
c.setSizeFull();
resource.setMIMEType("application/pdf");
c.setType(Embedded.TYPE_BROWSER);
window.addComponent(c);
window.setModal(true);
window.setWidth("90%");
window.setHeight("90%");
getMainWindow().addWindow(window);
}
/**
* getFileBytes
*
* @author NBochkarev
*
* @param fileOut
* @return
* @throws IOException
*/
public static byte[] getFileBytes(String fileName) throws IOException
{
ByteArrayOutputStream ous = null;
InputStream ios = null;
try
{
byte[] buffer = new byte[4096];
ous = new ByteArrayOutputStream();
ios = new FileInputStream(new java.io.File(fileName));
int read = 0;
while ((read = ios.read(buffer)) != -1)
ous.write(buffer, 0, read);
}
finally
{
try
{
if (ous != null)
ous.close();
}
catch (IOException e)
{
// swallow, since not that important
}
try
{
if (ios != null)
ios.close();
}
catch (IOException e)
{
// swallow, since not that important
}
}
return ous.toByteArray();
}