2013-10-11 79 views
4

我正在尋找易於使用且不需要wkhtmltopdf的PDF生成器套件,因爲我的共享宿主服務器不支持此功能。Symfony2 PDF生成器套件

我試過https://github.com/psliwa/PdfBundle,但如果我按照文檔,我只是在屏幕上得到一個響應(不生成PDF)。雖然有這種解決方案in this question,但該解決方案看起來過於複雜。

我也看過ioalessio/IoTcpdfBundle,這看起來很直接,但沒有安裝Composer,我的web服務器不支持供應商安裝。

我也試過stedekay/SpraedPDFGeneratorBundle,但這只是普通的錯誤,抱怨找不到Java。

雖然whiteoctober/WhiteOctoberTCPDFBundle可能能夠工作,但這只是創建一個TCPDF對象,必須進一步處理,而且文檔並不是非常全面。

任何建議(或如何得到任何提到的捆綁工作的建議)將不勝感激。

+0

您可以使用TCPDF庫,但你得給聯樣式到HTML元素 –

回答

3

我可以肯定地推薦KnpSnappyBundle與樹枝模板。

我已經在生產中多次使用過庫/包,並且沒有太多麻煩。

(與傳統應用程序中的tcpdf & dompdf相比)。

用法示例:

$this->get('knp_snappy.pdf')->generateFromHtml(
    $this->renderView(
     'MyBundle:Foo:bar.html.twig', 
     array(
      'some' => $vars 
     ) 
    ), 
    '/path/to/the/file.pdf' 
); 
+1

雖然KnpSnappyBundle是PDF生成goto語句束,它需要wkpdftohtml,我不能用,因爲在我原來的請求表示。 – Magnanimity

+0

哦抱歉,速度閱讀失敗 - 可能對其他用戶有所幫助:D – nifr

1

我是SpraedPDFGeneratorBundle的開發商。我的軟件包使用Java庫,所以您需要在您的服務器上運行JRE(6或更高版本)。

+0

stedekay是否可以使用噴塗生成畫布元素? – timhc22

+0

我從來沒有使用畫布元素,但如果我理解正確,那些元素將由Javascript繪製。所以這是不可能的。 – stedekay

4

我使用SpraedPDFGeneratorBundle,我使用Composer從https://github.com/stedekay/SpraedPDFGeneratorBundle安裝它來激活它。我在AppKernel new Spraed\PDFGeneratorBundle\SpraedPDFGeneratorBundle()中激活。

最後,我執行命令php composer.phar update,在我的控制,我把這個代碼:

$html = $this->renderView('MyappJournalBundle:Default:index1.html.twig'); 
    $pdfGenerator = $this->get('spraed.pdf.generator'); 

    return new Response($pdfGenerator->generatePDF($html), 
        200, 
        array(
         'Content-Type' => 'application/pdf', 
         'Content-Disposition' => 'inline; filename="out.pdf"' 
        ) 
    ); 

,它爲我工作!

0

您可以使用EnseparHtml2pdfBundle。 看here詳情

1

如果你想在安裝Symfony3 SpraedPDFGeneratorBundle,確保服務是:

spraed.pdf.generator: 
    class: Spraed\PDFGeneratorBundle\PDFGenerator\PDFGenerator 
    arguments: [ "@kernel" ] 

這矗立在文檔中的深跌,但其很難找到。

你可能會意識到的另一件事是發電機使用「The Flying Sauser」,它使用了一種特殊的css。所以通過閱讀這個,在http://flyingsaucerproject.github.io/flyingsaucer/r8/guide/users-guide-R8.html#xil_36,我發現我必須使用: @page {margin:0 0.5cm;尺寸:21釐米26.5釐米; } 以證明文檔中的邊距以使內容適合。

0

你可以試試這個包。 MpdfPortBundle。 https://github.com/tasmanianfox/MpdfPortBundle

+0

在這種情況下,這不是你的錯,因爲問題不在話題中,但請注意,一般來說,推薦某個工具或庫的答案必須證明它如何解決答案本身的問題。 –