2015-01-13 4 views
1

모바일 응용 프로그램 (cordova + html4)에서는 스트림에서 PDF를 표시해야합니다. 우리는 pdf 스트림을 반환하는 서비스를 가지고 있습니다. 우리는 해당 스트림을 모바일의 임시 폴더 위치에 저장하고 PDF를 표시하려고합니다. 아래 샘플 자바 샘플 자바 코드는 내가 원하는 것을 정확하게 처리합니다. 하지만 어떻게 자바 스크립트에서이 기능을 사용할 수 있습니까? 나는 자바 스크립트에서 이진 스트림을 읽는 것을 의미한다.javascript/cordova에서 pdf 작성

jsPDF 것은 당신이 PDF를 구현하려는 경우 자바 스크립트에서 PDF 및

pdf.js을 생성하려는 경우 : 당신이 좀보고 할 수 있습니다

String fileURL = "https://1/////4/xyz"; 
String saveDir = "D:/Works"; 
try { 
    URL url = new URL(fileURL); 
    HttpURLConnection httpConn = (HttpURLConnection) url 
      .openConnection(); 
    httpConn.setRequestProperty("Content-Type", 
      "application/x-www-form-urlencoded"); 
    httpConn.setRequestProperty("TOKEN", 
      "ghZtxnPfpJ63FgdT/59V+5zFTKHRdwm6rIfGJC+0B5W5CJ9pG33od7l+/L6S8R56"); 
    int responseCode = httpConn.getResponseCode(); 
    System.out.println("Reseponse Code = " + responseCode); 

    if (responseCode == HttpURLConnection.HTTP_OK) { 
     String fileName = ""; 
     String disposition = httpConn 
       .getHeaderField("Content-Disposition"); 
     String contentType = httpConn.getContentType(); 
     int contentLength = httpConn.getContentLength(); 

     if (disposition != null) { 
      // extracts file name from header field 
      int index = disposition.indexOf("filename="); 
      if (index > 0) { 
       fileName = disposition.substring(index + 10, 
         disposition.length() - 1); 
      } 
     } else { 
      // extracts file name from URL 
      fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1, 
        fileURL.length()); 
     } 

     System.out.println("Content-Type = " + contentType); 
     System.out.println("Content-Disposition = " + disposition); 
     System.out.println("Content-Length = " + contentLength); 
     System.out.println("fileName = " + fileName); 

     // opens input stream from the HTTP connection 
     InputStream inputStream = httpConn.getInputStream(); 
     String saveFilePath = saveDir + File.separator + fileName; 

     // opens an output stream to save into file 
     FileOutputStream outputStream = new FileOutputStream(
       saveFilePath); 

     int bytesRead = -1; 
     byte[] buffer = new byte[BUFFER_SIZE]; 
     while ((bytesRead = inputStream.read(buffer)) != -1) { 
      outputStream.write(buffer, 0, bytesRead); 
     } 

     outputStream.close(); 
     inputStream.close(); 

     System.out.println("File downloaded"); 
    } else { 
     System.out 
       .println("No file to download. Server replied HTTP code: " 
         + responseCode); 
    } 
    httpConn.disconnect(); 
} catch (MalformedURLException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

답변

0

THRE의 두 라이브러리 뷰어.

그 중 하나가 당신을 위해 속임수를 써야합니다.