0

I currently created a invoice in HTML. That invoice has some Blade Syntax in it, to be more precise it's one @foreach and some calling to variables, like {{$order->id}} or similar. Also I included simple CSS. Now I want to convert this HTML File to a pdf (and send it per mail, etc.)...

I know there are various threads already, but none of them seems to be about blade templates (I could (if this was the last chance for me) also change the blade things to pure php, but I don't know if this makes it better?). However none of them seems to be welcome for everybody, so with witch plugin/library could I do this? I need to do something like that (pseudoCode follows):

var InvoicePDF = generatePDFFromUrl('/incoive/6');

Of course, it will most propably be a bit harder, but thats what I need, so then I would have the pdf stored in a variable and can use it as attachment for a mail for example...

To come back to the plugins,

I know about:

http://wkhtmltopdf.org/ --> seems like I have to download it and run it, not just include something in php?

http://www.princexml.com/ --> I don't want to pay for the plugin

and there are many more, but all have something bad as I saw right....

So what's a plugin that could do all I want?

PS: I know about that thread, but none of them seems to work as I want....

Community
  • 1
  • 1
nameless
  • 1,483
  • 5
  • 32
  • 78
  • "none of them seems to work as I want". Did you try ->render()'ing the blade to retrieve the html output, then passing that result to DomPdf's render()? If so, what was the result? – Iskar Nov 14 '16 at 10:11
  • @Iskar I didn't try dompdf yet, because on the thread the one who asked said it has huge problems with tables, and as my whole invoice consists of tables, this would propably not make sense. If it changed so far, how could I render the blade and pass exactly the results into dompdf? – nameless Nov 14 '16 at 10:14
  • `$out = view('invoice', [ 'invoiceID' => '321'])->render();` to get the html output of the blade. `$dompdf->loadHtml($out); $dompdf->render();` to load that $out html into dompdf to render. Regarding tables, I am not sure about that, there is probably workarounds somewhere. Don't forget to include stylesheet. – Iskar Nov 14 '16 at 10:35
  • @Iskar I don't pass the invoice ID as get parameter, just as number after the `/` (over routes), and it gets the data from the controller, so can I only render the view? Think then it won't work as it will have no data then, will it? And stylesheets, do I have to include them manually at dompdf or is it enough to have them included in the html? – nameless Nov 14 '16 at 10:58
  • I don't know your full code/how your project is structured, but I don't see why you couldn't get the data somehow. For inserting the data into your template, your template should have some sort of delimiter and you str_replace the specific elements in it -- so @INVOICE_CUST_NAME@ in template, then str_replace it in the rendered view before dompdf loading it. For stylesheets, try it and see, most likely will need to read dompdf manual and use loadcss directive. – Iskar Nov 14 '16 at 11:25
  • @Iskar no, I'm just having the route `/invoice/invoiceID` and then in the controller called from that route i get the information and pass it in the view like `return view('invoice', ["order" => $order]);`and then in the view I access it with `{{$order->id}}` and so on – nameless Nov 14 '16 at 11:37
  • @Iskar I got this working now (kinda) with dompdf (or laravel-dompdf, the wrapper for using with laravel), but I don't get the css working.. When using a external css file, nothing works (regarding css) and using indocument css i have like 5 pages or something for a bit of html.. – nameless Nov 14 '16 at 14:37
  • DocRaptor is an affordable API that is PrinceXML-based, if that's any help. – jamespaden Nov 15 '16 at 01:47
  • Basically as I dont want to pay for it (as it's a private project) this is not possible for me unfortunately. I'm still struggling around with DomPdf, as I said I got it converted to a pdf but it seems like every table row has its own page... – nameless Nov 15 '16 at 07:59

0 Answers0