1

Vaadinコンポーネントを介してiReportで作成された pdf を開こうとするのはこれが初めてです。多くのフォーラムで見ましたが、理解できません。

今私は私の問題を説明しようとします:

  1. iReportでファイル (.jasper) を作成しました
  2. Vaadinボタンをクリックしたときにこのファイルを開きたい

何かお手伝いできることはありませんか?

4

1 に答える 1

1

アップデート:

生成された pdf は pdf またはストリームですか? Firefox/Chrome: このブラウザには独自の「application/pdf」ビューアがあります

Internet Explorer: IE で PDF を表示するには、Adobe Acrobat Reader を使用しています。ブラウザ用のAdobe Acrobat Readerインストールプラグイン。このプラグインは、アプリケーション/PDF コンテンツを検出し、Internet Explorer で独自のビューアーを表示します。

これは、Vaadin でこれを作成するためのサンプルです。

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();
}
于 2013-07-10T10:28:20.553 に答える