开发者

Open pdf file from the server in GWT

I want to open a pdf file from a button of my GWT application. Actually to access that file I've to query the server that returns the file enc开发者_如何转开发oded in base64 from a JSON request. It's possible to open that file then?


  1. To show a pdf "file" (it's not a file, but a byte stream in http reply) you need to rely on browsers own capability to render pdf data. To do this you must either open a URL in a new window or in in an iframe. The second is probably a better option when using GWT. Docs of the GWT Frame.

    // url of the pdf (must have application/pdf content-type)
    Frame frame = new Frame("url");  
    // add the frame wherever you want
    RootPanel.get().add(frame);
    
  2. In order for the browser to correctly display pdf page (by invoking the pdf plugin), the url that serves the pdf data must have a header that says Content-Type: application/pdf. Check that your response has this header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜