2013-06-02 2 views
2

나는 flot으로 만든 차트를 가져 와서 wkhtmltopdf를 사용하여 PDF로 렌더링하려고합니다.wkhtmltopdf는 flot 차트 축만 렌더링합니까?

차트를 포함하는 div 내에서 HTML을 가져 와서 서버로 다시 전달합니다.

PDF에서 실제 차트가 아니라 축 만 표시된다는 것을 알았습니다.

enter image description here

을하지만 wkhtmltopdf 렌더링 같은 이미지는 다음과 같습니다 : 브라우저에서 볼

차트는 다음과 같습니다 enter image description here

내가 포함 한 FLOT/예 두 템플릿의 /examples.css. wkhtmltopdf에 전달

html로는 다음과 같습니다

<body> 
    <h2>Incidents per 100 Workers</h2> 
    <p>This is the test output</p> 
     <div id="content"> 
       <div class="demo-container"> 
         <div id="placeholder" class="demo-placeholder"> 
      <canvas height="450" width="850" style="direction: ltr; position: absolute; left: 0px; top: 0px; width: 850px; height: 450px;" class="flot-base"></canvas><div style="position: absolute; top: 0px; left: 0px; bottom: 0px; right: 0px; font-size: smaller; color: rgb(84, 84, 84);" class="flot-text"><div style="position: absolute; top: 0px; left: 0px; bottom: 0px; right: 0px; display: block;" class="flot-x-axis flot-x1-axis xAxis x1Axis"><div class="flot-tick-label tickLabel" style="position: absolute; max-width: 106px; top: 431px; left: 23px; text-align: center;">0</div><div class="flot-tick-label tickLabel" style="position: absolute; max-width: 106px; top: 431px; left: 144px; text-align: center;">2</div><div class="flot-tick-label tickLabel" style="position: absolute; max-width: 106px; top: 431px; left: 265px; text-align: center;">4</div><div class="flot-tick-label tickLabel" style="position: absolute; max-width: 106px; top: 431px; left: 386px; text-align: center;">6</div><div class="flot-tick-label tickLabel" style="position: absolute; max-width: 106px; top: 431px; left: 507px; text-align: center;">8</div><div class="flot-tick-label tickLabel" style="position: absolute; max-width: 106px; top: 431px; left: 624px; text-align: center;">10</div><div class="flot-tick-label tickLabel" style="position: absolute; max-width: 106px; top: 431px; left: 745px; text-align: center;">12</div></div><div style="position: absolute; top: 0px; left: 0px; bottom: 0px; right: 0px; display: block;" class="flot-y-axis flot-y1-axis yAxis y1Axis"><div class="flot-tick-label tickLabel" style="position: absolute; top: 418px; left: 2px; text-align: right;">-1.5</div><div class="flot-tick-label tickLabel" style="position: absolute; top: 348px; left: 2px; text-align: right;">-1.0</div><div class="flot-tick-label tickLabel" style="position: absolute; top: 279px; left: 2px; text-align: right;">-0.5</div><div class="flot-tick-label tickLabel" style="position: absolute; top: 209px; left: 6px; text-align: right;">0.0</div><div class="flot-tick-label tickLabel" style="position: absolute; top: 140px; left: 6px; text-align: right;">0.5</div><div class="flot-tick-label tickLabel" style="position: absolute; top: 70px; left: 6px; text-align: right;">1.0</div><div class="flot-tick-label tickLabel" style="position: absolute; top: 1px; left: 6px; text-align: right;">1.5</div></div></div><canvas height="450" width="850" style="direction: ltr; position: absolute; left: 0px; top: 0px; width: 850px; height: 450px;" class="flot-overlay"></canvas> 
      </div> 
       </div> 
     </div> 
</body> 
</html> 

사람이 발생할 수 있습니다 어떤 아이디어를 가지고?

감사


답변!

아래의 Ryley에서 언급했듯이 대부분의 차트가 '작성된'캔버스가 사라지면 HTML을 서버로 다시 보낼 수 없습니다.

대신 나는이 한 :

//fplotChart is the value returned by calling 
//the fPlot .plot() function 
var fplotChartCanvas = fplotChart.getCanvas(); 
valueToSubmitToServer = fplotChartCanvas.toDataURL(); 

을 그리고 값이 되돌려 IMG 요소의 'SRC'로 그때 'valueToSubmitToServer'에 사용되는 서버

<img id="chart1" src="{{ pdf_inject_canvas_url }}"> 

이었다 일단 이것은 단지 일 괜찮 았던 점을 제외하고는 원래 배경색을 잃어버린 것입니다.

답변

2

Flot은 canvas 요소를 사용하여 그래프 자체를 렌더링하고 html div를 배치하여 레이블을 표시합니다. 사용중인 wkhtmltopdf 버전이 canvas 요소를 지원하지 않는다고 생각합니다. 나는 wfhtmltopdf 0.10.0 rc2의 정적으로 링크 된 버전을 사용하여 pdf로 플롯 그래프를 성공적으로 캡쳐 했으므로 확실히 가능합니다. 플랫폼에 맞는 버전을 추적해야합니다.

+0

감사 느린 응답을 매우 귀하의 답변을 많이하고 죄송합니다. 캔버스 구성 요소로 인해 HTML을 서버로 다시 보내면 도움이되지 않습니다.원래의 질문을 편집하여 내가이 작업을하기 위해 수행 한 작업에 대해 자세히 설명했습니다. 답변 해 주셔서 다시 한 번 감사드립니다. – shearichard

1

나는이 동일한 문제를 여러 번 보았습니다. wkhtmltopdf가 캔버스 공간을 렌더링하는 데 사용하는 일부 누락 된 종속성으로 인해 발생합니다 (그래픽 가속화 컨텐츠이기 때문에 상상합니다). 누락 된 것이 무엇인지 정확히 기억할 수는 없지만 wkhtmltopdf는 stdout에 유용한 디버그 정보를 쓰거나 로그를 호출하는 로그에 유용합니다. 그것은 X 서버 환경이나 QT 의존성과 관련이 있을지 모르지만, 가장 좋은 것은 로그를 확인하는 것입니다. dataURL 밖으로 캔버스를 구문 분석

, 괜찮 것을 제외하면 기존의 IE 버전을 지원해야하는 경우 (< = IE8)

관련 문제