Display PDF in different window by reading Binary file in MIME folder.

Hi all,
I've kept binary file in MIME folder and I'm trying to read the contents of it. and I'm trying to display contents in pdf format in separate window.
For this I was able to read the file by using FileInputStream
byte[] bytes = new byte[1000];
     try
              //File file = new File(WDURLGenerator.getResourcePath(wdComponentAPI.getDeployableObjectPart(),"data.bin"));
               File file = new File(WDURLGenerator.getResourcePath("test.bin"));
               FileInputStream is = new FileInputStream(file);
              long length = file.length();
               //Create the byte array to hold the data
               byte[] bytesA = new byte[(int)length];
               //Read in the bytes
                int offset = 0;
                int numRead = 0;
                while (offset < bytesA.length&& (numRead=is.read(bytesA, offset, bytesA.length-offset)) >= 0)
                     offset += numRead;
                    is.close();
               bytes = bytesA;
               wdContext.currentContextElement().setPdfSource(bytes);
             catch(Exception e)
               wdComponentAPI.getMessageManager().reportException("Error Reading File:"+e.getCause(),true);
               wdComponentAPI.getMessageManager().reportException("Error Reading File To String:"+e.toString(),true);
I've to show this in external window. I created attribute "pdfResource" of type binary
and declared in the source
private ISimpleType myPdfDoc;
After that I added this bit of code in Init Method
myPdfDoc = wdContext.getNodeInfo().getAttribute("pdfResource").getModifiableSimpleType();
((IWDModifiableBinaryType)myPdfDoc).setMimeType(WDWebResourceType.PDF);
((IWDModifiableBinaryType)myPdfDoc).setFileName("PDF");
After this I made an action handler which has following code.
final byte[] documentContent = bytes
final String docUrl = myPdfDoc.format( bytes );
String docUrl = myPdfDoc.format(bytes);
IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(docURL,"Resource", true);
window.open();
But it is throwing Null Pointer exception for Init Method and also while displaying.
Where is that I'm faltering. Any Pointers will be help ful
Thanks
Srikant

First of all why do you need those three lines of code in your wdDoInit() ?
Simply, you may use this:
IWDCachedWebResource cachedResource = null;
String url = null;
byte[] pdf = wdContext.currentContextElement().getPdfSource();
if (pdf != null) {
   cachedResource = WDWebResource.getWebResource(pdf, WDWebResourceType.PDF);
   url = cachedResource.getURL();
Refer <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/4a/fb8342a7d30d53e10000000a155106/content.htm">Utilizing the IWDCachedWebResource-API</a> for further assistance.
/* Changed the code */
Message was edited by: Bala Krishnan

Similar Messages

  • How to disable 'Enable JavaScript' and 'Display PDF in browser' in Adobe Reader 9.1 msi?

    I'd like to how to disable 'Enable JavaScript' and 'Display PDF in browser' in Adobe Reader 9.1 msi.
    Any help would be appreciated.

    NeoChang:
    You can modify the installation package using the Adobe Customization Wizard to toggle the "Display PDF in Browser" but I have not found a setting to disable JavaScript from the Wizard. I have created a script which makes the changes, but it has to be run for every user since that info is stored in the User hive of the Windows registry.
    Disable JavaScript:
    REG ADD "HKCU\SOFTWARE\Adobe\Acrobat Reader\9.0\JSPrefs" /v bEnableJS /d 0 /t REG_DWORD /f
    Disable Browser Integration:
    REG ADD "HKCU\Software\Adobe\Acrobat Reader\9.0\Originals" /v bBrowserIntegration /d 0 /t REG_DWORD /f
    Michael
    ~Simplicity of Character is a Natural Result of Profound Thought~

  • How to open and read binary files?

    How do I open and read Binary files?

    Did you  look on The Unarchiver's web site where it has a link to older versions? http://theunarchiver.googlecode.com/files/TheUnarchiver3.2_legacy.zip
    The best thing to do is ask your friends what programs they used to produce these files, or at least what format files they are producing.  Otherwise it's like being shown a car and given a bundle of 200 keys with no idea to which one to use, or even if any of them work with that car.
    Using The Unarchiver will likely not do anything because it too will not know what format files are involved, and they may not even been in an archived format.  If they sent you a Word file without telling you (a favorite of Windows users to do  -- it drives me crazy when they could have just sent them in plain text), The Unarchiver won't open them.  If it's a picture file then using Hexedit will just show you a bunch of unintelligible stuff as shown in an earlier post, though you may see a line of text providing a hint.
    As I said earlier, often .bin may be an executable program which needs another program to actually interpret it.  That's what Java is trying to do.  Still, it may think it can execute the file, but it is highly unlikely somebody would send you an executable program (and if they did I would not trust it).  For all you know it may be a Windows virus.

  • Read binary file in LabVIEW 2012

    Hi,
    Have anyoune experienced problems reading binary files in 2012 previously saved in 2010.
    As shown on attached image, the same VI is opened in 2010 and 2012 reading the same binary file containing the data structure "ProcessList IN".
    I suspect it has something to do with the variants ?
    The error message does help a lot (-;
    Any ideas ?
    Kind regards
    Kahr
    Regards Kahr
    Certified LabVIEW Architect
    CIM A/S
    Attachments:
    Read_Binary_File_Error_LV2012.png ‏426 KB

    Hi Kahr,
    "error 1" tells one of the input parameters is wrong: it's either the path or the cluster datatype! The error message only mentions a file path AS AN EXAMPLE!
    You're using BinaryRead similar to those old Datalog file functions to read a cluster of several data. It has been know that datalog files get tricky when one is using a different LabVIEW version to read them due to changes of internal data representation. Maybe that's the point that hits you now?
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Read binary file 10 bytes at a time

    I want to read binary file in a specific format. There is a number at the starting of the file. That tells us where the data is starting. Suppose it says 3975, then it mean data starts at 3975. Then once I read that location I want to read data at 10bytes at a time and then convert it to numeric and display it on graph. I am attaching the file format and the current vi which I am using. please help.
    Solved!
    Go to Solution.
    Attachments:
    topo.zip ‏89 KB

    Ah, the first 10 characters are a string!
    After opening the file, use the Read From Text File with count set to 10.  Then use the Decimal String to Number to convert this string into your "record size".
    NOTE:  The text indicator was just for debug purposes.  You don't really need it.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Read record size.png ‏12 KB

  • I want to make a schedular which read xml files from a folder ,import in Indesign template then export as a pdf....

    i want to make a schedular probably in Coldfusion or using javascript ,  which read xml files from a folder ,import in Indesign template then export as a pdf....

    I don't think you understand: I want to open Dreamweaver and build a brand new site, then when I am done I want to host the dreamweaver site on the Business Catalyst platform. I dont want to use anything in BC to build the site, I just want to use the hosting platform. I do not want to import a BC site into dreamweaver or anything like that. I just want to use BC the same way I would use godaddy, or uhost or any other hosting provider. Based on your response you said that "of course its possible to build a BC site in Dreamweaver" I dont want to build a BC site, I want to build a Dreamweaver site and host it on the BC platform. Like I said before it doesnt seem like this is possible. As of now we can only build a new site in MUSE and integrate it into BC without using a BC template. Can you understand what I am saying. I DONT WANT TO USE A BC TEMPLATE, I WANT NOTHING TO DO WITH BC WHILE I AM BUILDING THE SITE WITH DREAMWEAVER, JUST LIKE MUSE DOES.

  • Labview 8.2 Read Binary File, no pos offset option anymore?!

    I have a VI that worked perfectly well in 7.1 and now I've opened it in 8.2 it doesn't work and I can't revert back to 7.1 because I accidently pressed save.
    In 7.1 I used the combination of open, read and close file functions to read parts of a large binary data file - I cannot read the whole file into Labview 8.2 as it fills the memory. There isn't a terminal in the 'read binary file' function in 8.2 for 'pos offset' which is what I used to use in 7.1. How am I supposed to open the file now? Surely they have not removed such a useful facility entirely - is there another way to do it that I am not aware of?
    Many thanks in advance for help,
    Sarah

    smercurio_fc wrote:
    André, at first I could not understand your response, ...
    Must be my Dutch way of writing English
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • Reading binary files

    Hi
    I need some help in reading binary files. This is the code I have so far.
    import java.io.InputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    public class patternmatch {
         public static void main (String[] args) {   
              final byte[] bytes = new byte[1];
              try {     
                   final InputStream  instream = new FileInputStream  (args[0]);
                   while (true) {
                        final int count = instream.read (bytes);
                        if (count==-1) break;
                        System.out.println(bytes);
                   instream.close();       
              } catch (IOException e) {
                   System.err.println(e);         
    }Instead of a list of hexadecimal numbers that I want I get a long line of
    [B@eee36c
    [B@eee36c
    [B@eee36c
    [B@eee36c
    Which represents some address I think.
    Does anyone know how to extract the hexidecimal numbers?
    Thanks
    Charles

    double post http://forum.java.sun.com/thread.jsp?forum=31&thread=558802

  • How to Read all files inside resource Folder inside Jar?

    I have a Jar file,,,, The program reads for resource files in the resource folder inside the Jar. I want my program to read all files inside this folder without knowing the names or the number of files in the folder.
    I am using this to make an Applet easy to be updated with spicific files. I just want to add a file inside the resource folder and Jar the program and automatically the program reads what ever is in there!!
    I used the File class to get all file names inside the resource folder. it works fine before Jarring the program. After I jar I recieve a URI not Herarichy Exception!!
    File fold=new java.io.File(getClass().getResource(folder).toURI());
    String[] files=fold.list();
    I hope the question is clear!!

    How to get the directory and jar file that you class resides in:
    // returns path and jarfile (ex: /home/mydir/my.jar)
    public String getJarfileName()
            // Get the location of the jar file and the jar file name
            java.net.URL outputURL = YourClass.class.getProtectionDomain().getCodeSource().getLocation();
            String outputString = outputURL.toString();
            String[] parseString;
            int index1 = outputString.indexOf(":");
            int index2 = outputString.lastIndexOf(":");
            if (index1!=index2) // Windows/DOS uses C: naming convention
               parseString = outputString.split("file:/");
            else
               parseString = outputString.split("file:");
            String jarFilename = parseString[1];
           return jarFilename;
    }If your my.jar was in /home/mydir, it will store "/home/mydir/my.jar" in jarFilename.
    note: getLocation returns "file:/C:/home/mydir/my.jar" for Windows/DOS and "file:/home/mydir/my.jar" for windows, thus why I look for the first and last index of the colon so I can correctly split the string.
    If you want to grab a file in the jar file and get an InputStream, do the following:
    import java.io.*;
    import java.util.Enumeration;
    // jar stuff
    import java.util.jar.*;
    import java.util.zip.ZipEntry;
    public class Jaris
       private JarFile jf;
       public Jaris(String jarFilename) throws Exception
           try
                           jf = new JarFile(jarFilename);
           catch (Exception e)
                jf=null;
                throw(e);
       public InputStream getInputStream(String matchString) throws Exception
           ZipEntry ze=null;
           try
              Enumeration resources = jf.entries();
              while ( resources.hasMoreElements() )
                 JarEntry je = (JarEntry) resources.nextElement();
                 // find a file that matches this string from anywhere in my jar file
                 if ( je.getName().matches(".*\\"+matchString) )
                    String filename=je.getName();
                    ze=jf.getEntry(filename);
          catch (Exception e)
             throw(e);
          InputStream is = jf.getInputStream(ze);
          return is;
       // for testing the Jaris methods
       public static void main(String[] args)
          try
               String jarFilename=getJarfileName();
               Jaris jis = new Jaris(jarFilename); // this is the string we got from the other method listed above
               InputStream is=jis.getInputStream("myfile.txt"); // can be used for xml, xsl, etc
          catch (Exception e)
             // this is just a test, so we'll ignore the exception
    }Happy coding! :)
    Doc

  • How to read the file from a folder.

    Hi All,
    How to read the file from a folder or directory from the non sap server / remote server.
    Regards
    Sathis

    open dataset filename for input in text mode
                         encoding default.
    filename is character type variable with the destination filename.
    Edited by: Jino Augustine on Apr 19, 2010 1:31 PM

  • Read all Files from a Folder on Server

    Hi,
    Can anyone help me in finding if there's any way to read all files in a folder on the server?Any Function module or anything.
    Thanks

    On App server?  Try this sample program.
    report zrich_0001 .
    data: begin of itab occurs 0,
          rec(1000) type c,
          end of itab.
    data: wa(1000) type c.
    data: p_file type localfile.
    data: ifile type table of  salfldir with header line.
    parameters: p_path type salfile-longname
                        default '/usr/sap/TST/DVEBMGS01/data/'.
    call function 'RZL_READ_DIR_LOCAL'
         exporting
              name           = p_path
         tables
              file_tbl       = ifile
         exceptions
              argument_error = 1
              not_found      = 2
              others         = 3.
    loop at ifile.
      format hotspot on.
      write:/ ifile-name.
      hide ifile-name.
      format hotspot off.
    endloop.
    at line-selection.
      concatenate p_path ifile-name into p_file.
      clear itab.  refresh itab.
      open dataset p_file for input in text mode.
      if sy-subrc = 0.
        do.
          read dataset p_file into wa.
          if sy-subrc <> 0.
            exit.
          endif.
          itab-rec = wa.
          append itab.
        enddo.
      endif.
      close dataset p_file.
      loop at itab.
        write:/ itab.
      endloop.
    Regards,
    Rich Heilman

  • How to disable Display PDF in Browser in Adobe Reader XI?

    I am having troubles with opening a report in PDF form from a web browser, and I'm trying to figure out how to disable opening a PDF in a browser in Reader XI.  I tried disabling "Open in Read Mode" and "Allow Fast Web View" both individually and seperately, and none of those combinations did the trick.
    Any suggestions/help are appreciated.  Thanks.

    Hello Lloyd6770
    Try these steps.  ( I'm using Windows 7 x64 Ultimate, Internet Explorer 9,  and Adobe XI )
    1. Open Adobe XI
    2. Click Edit
    3. Click Accessibility
    4. Click Setup Assistant
    5. Click top radio button 'Set Options for Screen Readers'
    6. Click Next
    7. Do not change options on Screen 2 of 4, Click Next
    8. Do not change options on Screen 3 of 4, Click Next
    9. On screen 4 of 4, remove the check mark on ' Display PDF documents in the web browser '
    NOTE: I checked Internet Explorer 9 / Tools / Manage add-ons and Adobe PDF Link Helper is still enabled in Internet Explorer 9.
    PDF's will open in Adobe XI as you preferred and not in your brower.
    Cheers!

  • Display PDFs in Java window?

    Hi,
    I was wondering if Acrobat is the right product to buy in order to dispaly PDFs in my custom Java application. That is: does it come with a Java API (Java 1.4.2). I only need to display PDFs, nothing else. And I do not want to display the PDFs in a browser or Reader window, but inside my application (alongside with other information)
    Will Acrobat Standard edition do, or will I need Acrobat Pro?
    Thanks in advance.
    /Henrik

    Acrobat does not come with a Java API, as Java is not a standard desktop development environment.  Instead, it offers platform-native APIs in C/C++, COM/OLE and JavaScript.
    On the server side, of course, our Livecycle products are all Java-based.

  • Read binary file (DOC, PDF, TIF,...) into SAP with JCO-Server

    Hallo,
    I want to read a binary file (DOC, PRD, TIF,...) within a JCO-Server and transfer this file to SAP.
    In SAP we want to store the file in DMS.
    Next step is to read a file from DMS and store the file external using the JCO-Server.
    My questions are:
    1. How can I upload/download any binary in JAVA
    2. How have I to define the communication tabel between SAP and JCO to transfer the data (string,char, raw) and how long must be a row.
    Maybe any code exsamples ?
    Thanks

    We found the way how to define the tables so we can transfer the data between SAP an Java.

  • Problem rendering certain bytes when reading binary file

    I have a two part problem. I am trying to read files of any type from a client and transfer them over a pipe to a UNIX host running a C API. I have this process working for text data just fine however when I try and submit binary data there appears to be some data loss. Most of the file appears to end up on the host but it just isn't as long as the source, nor will it render correctly.
    In investigating this problem I tried to simply output a temporary copy of the transferred file on the client as I was reading the file just to see if my "thinking/process" was correct. The copy of the file ends up the same length but some bytes seem to have been misread. Upon doing a windiff on the source and copy it appears that several characters that are rendered as blocks in the original show up as '?' in the destination file.
    I believe this is an entirely different problem than why I am losing data on the host side but I want to first figure out why this problem is occuring. The below code is how I am reading and writing the binary file. I realize it has some problems with it, it is more of a POC at this point.
               final int BUF_SIZE = 1000;  // 1K
               char[] cBuffer = new char[BUF_SIZE];
               byte[] bBuffer = new byte[BUF_SIZE];
               int read = BUF_SIZE;
               long length = fLocalFile.length();
               FileInputStream fis = new FileInputStream(fLocalFile);
               DataInputStream dis = new DataInputStream(fis);
               FileOutputStream fos = new FileOutputStream("C:\\temp.file", false);
               DataOutputStream dos = new DataOutputStream(fos);
               for (int start = 0; start < length && reply.getSuccess(); start += read)
                   System.out.println("length: " + length + " start: " + start);
                   read = dis.read(bBuffer, 0, BUF_SIZE);
                   // Send the file data
                   String sTemp = sDestName + ":" + new String(bBuffer,0,read);
                   dos.write(bBuffer,0,read);
                   reply = axBridge.execute (Commands.CMD_FILE_TRANSFER_SEND, sTemp);
                dos.close();
            }It seems as if when reading or writing on the data streams some of the characters aren't getting converted correctly. Can anyone help? I've been testing with a PDF if that sheds any light.

    Yes but you ARE converting to a String first which you then send to the axBridge (sTemp!). Try just sending the bytes. You can easily pre-pend the "<filename>:" by sending those first.
    I know that some conversions occur when converting to a String, what they are exactly and what the exact effects are escapes me. Past experience though has taught me to ALWAYS send bytes, with no conversions, what you read is what you send.
    You may need to modify the send/receive protocol so that you send the command first with the filename then the bytes are sent after...
    As for why the file is not being written correctly to: c:\\temp.file, don't know... try the following code, it tends to be one of the "standard" ways of "streaming" data...
         byte buf[] = new byte[bufSize];
         int bRead = -1;
         while ((bRead = in.read (buf)) != -1)
             out.write (buf,
                     0,
                     bRead);
         }     And try just using a FileOutputStream or wrapping in a BufferedOutputStream.

Maybe you are looking for