java - How to view PDF data bytes using SWT Browser -


i have function returns byte array of pdf data, , want view in java swt application. not want use jars such icepdf, jpedal, etc. swt , java.

one obvious solution write bytes file "c:/temp/file.pdf" , call browser.seturl("file://c:/temp/file.pdf"). want avoid using temp file if possible.

i tried following, not work, because "settext" assumes mime type text/html. if swt provided settext(bytes,headers) method!

any advice how this?

public class mybrowser {     static byte[] getpdfdata()     {         // details omitted     }      public static void main(string[] args)     {          shell shell = new shell();         shell.setlayout(new rowlayout(swt.vertical));          browser browser = new browser(shell, swt.border);         browser.setlayoutdata(new rowdata(600, 300));          byte[] pdfdata = getpdfdata();          stringbuffer buffer = new stringbuffer();         buffer.append("content-type: application/pdf\n\n");         (int = 0; < pdfdata.length; ++i)             buffer.append((char) pdfdata[i]);         browser.settext(new string(buffer));         shell.pack();         shell.open();          while (shell != null && !shell.isdisposed())         {             if (!shell.getdisplay().readanddispatch())             {                 shell.getdisplay().sleep();             }         }     }  } 

oh, well. give up. not ideal, guess must use temp file. following works,

        byte[] pdfdata = getpdfdata();          file tempfile = file.createtempfile("twiqd", ".pdf");         fileoutputstream tempout = new fileoutputstream(tempfile);         tempout.write(pdfdata);         tempout.close();          browser.seturl(tempfile.touri().tourl().toexternalform());         shell.pack();         etc. 

i have remember delete temp file.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -