Ok, I found the answer.
You ask two things: how to add images and how to add new fonts .
Adding Images
It is pretty simple. Assuming you are using Twig, you will need to do the following:
<img src="{{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset("img/MyImage.png") }}" />
Of course, you can also make it a macro so you donβt repeat yourself everywhere, for example.
{% macro image(uri) %} {{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset(uri) }} {% endmacro %}
And you use it like this
{% import '::imgurimacro.html.twig' as img %} ... <img src="{{ img.image('img/MyImage.png') }}" />
And it should work.
Add fonts
This is a little trickier. First make sure you have the latest version of Spraed PDF Generator. In composer.json:
"spraed/pdf-generator-bundle": "dev-master"
If you want to add fonts to a new PDF file, do the following:
$pdf = $pdfGenerator->generatePDF($postData , 'UTF-8', array('C:\Windows\Fonts\Font1.ttf', 'C:\Windows\Fonts\Font2.ttf'));
Then create the fonts folder (or any other name of your choice) in the web folder (or wherever you place your resources) and add the .ttf files there.
In your Twig file, add the following as a CSS style:
@font-face { font-family: "MyFontFamily"; src: {{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset('fonts/Font1.ttf') }}; }
Now when you write
<p style="font-family: MyFontFamily">Hello World!</p>
He should print "Hello World!" using registered font in pdf.
Carlos Vergara
source share