2013-07-29 3 views
1

jsPDF-lib를 사용하여 이미지를 PDF 파일에 추가하려고합니다. PDF로 생성되지만 이미지가 손상되어 다음과 같습니다jsPDF/HTML5로 PDF에 이미지 삽입이 작동하지 않습니다.

여기의 예처럼 내 코드에서 동일한 데이터-URL을 사용하고

enter image description here

: http://parall.ax/products/jspdf 내 전체 코드는 아래 첨부 :

<!DOCTYPE html> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one 
    or more contributor license agreements. See the NOTICE file 
    distributed with this work for additional information 
    regarding copyright ownership. The ASF licenses this file 
    to you under the Apache License, Version 2.0 (the 
    "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at 

    http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, 
    software distributed under the License is distributed on an 
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
    KIND, either express or implied. See the License for the 
    specific language governing permissions and limitations 
    under the License. 
--> 
<html> 
    <head> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> 
     <link rel="stylesheet" type="text/css" href="css/index.css" /> 
       <!-- Scripts down here --> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
     <script type="text/javascript" src="jspdf.js"></script> 
     <script type="text/javascript" src="jspdf.plugin.addimage.js"></script> 
     <title>Hello World</title> 
    </head> 
    <body> 
     <script type="text/javascript" src="cordova-2.7.0.js"></script> 
     <script type="text/javascript"> 
     var doc; 

     function clicked() { 
      doc = new jsPDF(); 
      var imgData = 'data:image/jpeg;base64, ***DATAURL_HERE***'; 
      doc.setFontSize(40); 
      doc.text(35, 25, "Test-PDF"); 
      doc.addImage(imgData, 'JPEG', 15, 40, 180, 180); 
      writeFile(); 
      alert("File was written"); 
      } 

     function writeFile() { 
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFSSuccess, onError); 
     } 

     function onFSSuccess(fs) { 
      fileSystem = fs; 
      createRoot();    
     } 

     function createRoot(e) { 
      fileSystem.root.getDirectory("Download/", {create: true}, createFile); 
     } 

     function createFile(dirEntry) { 
      var dir = "Test.pdf"; 
      dirEntry.getFile(dir, {create: true, exclusive: true}, saveFileToRoot); 
     } 

     function saveFileToRoot(f) { 
      f.createWriter(function(writerOb) { 
       writerOb.write(doc.output()); 
      }); 
     } 

     function onError(e) { 
     } 

     </script> 
    <h1>Testfile working</h1> 
    <button onclick="clicked()">Clickme</button> 
    </body> 
</html> 

아이디어가 있습니까?! 모든 도움에 감사드립니다!

+0

그래서 ... 원본 이미지에 대한 링크를 게시 할 수 있습니까? –

답변

-1

캔버스 URL 이미지에 대한 DATAURL_HERE, 당신은이 기능을 계산할 수 변화 :

VAR imgData = canvas.toDataURL ('이미지/PNG');

+0

이 질문에 게시 한 코드 샘플을 수정하십시오. 현재로 서서 형식화와 범위는 우리가 당신을 도울 수 없게합니다. 여기에 대한 정보를 얻을 수있는 [훌륭한 리소스] (http://stackoverflow.com/help/mcve)가 있습니다. -1, 잘못된 방향으로 가져 가지 마라. 아래쪽 투표는 여기에서 콘텐츠 문제를 나타내는 방법입니다. 서식 및 코드 샘플을 개선하면 기꺼이 되돌릴 수 있습니다. 코드와 함께 행운을 빌어 요! – herrbischoff

관련 문제