2014-09-13 7 views
0

jsPDF를 사용하여 window.print() 명령에서 제공하는 '정확하게'출력 PDF를 만드는 방법은 무엇입니까?jsPDF를 사용하여 window.print() 명령에서 제공하는 '정확히'출력 PDF를 만드는 방법은 무엇입니까?

jsPDF를 사용하여 시도한 'div'요소의 pdf를 만들어야합니다. 그러나 내가 얻는 결과물에는 여분의 총알이 많이 포함되어 번호 매기기가 엉망입니다. 하지만 화면에서 볼 수있는 것은 올바른 형식의 'div'이며 window.print()를 사용하여 그대로 인쇄 할 수 있습니다.

내 유일한 불만은 인쇄물의 옵션을 'PDF로 저장'으로 변경할 수없는 사용자를 위해이 출력을 PDF로 저장하는 다른 옵션을 원한다는 것입니다.

var pdf = new jsPDF('p', 'pt', 'letter'); 
    var source = $('#content')[0]; //content has the survey with lot of linked list elements and various formatted text 
    //I tried all kind of formatting on 'source' to make it right... but its not possible to keep the form as it is what it looks on screen 
    margins = { 
     top: 80, 
     bottom: 60, 
     left: 40, 
     width: 522 
    }; 
    pdf.fromHTML(
      source, // HTML string or DOM elem ref. 
      margins.left, // x coord 
      margins.top, {// y coord 
       'width': margins.width, // max width of content on PDF 
       //'elementHandlers': specialElementHandlers 
      }, 
    function (dispose) { 
     // dispose: object with X, Y of the last line add to the PDF 
     //   this allow the insertion of new lines after html 
     pdf.save('Disclosure' + '@DateTime.Now' + '.pdf'); 
    } 
    , margins); 

따라서 출력을 window.print()를 보면서 PDF로 저장하는 방법이 있습니까?

답변

0

이에게 시험을주십시오 : 당신은 당신이 언급 한대로 사업부로 하나의 요소를 처리하는 경우

var pdf = new jsPDF('p', 'pt', 'letter'); 
var source = $('#content')[0]; 
var options = { background: '#fff' }; 

pdf.addHTML(source, options, function() 
{ 
    pdf.save('Disclosure' + '@DateTime.Now' + '.pdf'); 
}); 

(배경 옵션이 필요

, 그렇지 않으면 당신은 투명/검정을받을 것이기 때문에 배경)

또한이 작업을 수행하려면 html2canvas이 필요합니다.

+0

이 오류가 발생합니다. pdf.addHTML은 @diegcor 함수가 아닙니다. – rezCash

관련 문제