Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AbdulBazith's avatar

How to generate charts using barryvdh/laravel-dompdf and make it report

guys iam working with a project online examination

iam using barryvdh/laravel-dompdf for generating pdf.

these much days i just use tables for getting the pdf.

my client expecting student mark in chart view

how to get it in chart view??

i used

 <link rel="stylesheet" href="{{ ltrim(public_path('css/font-for-print.css'), '/') }}" />
    
    <link rel="stylesheet" href="{{ ltrim(public_path('css/bootstrap.min.css'), '/') }}" />
    
    <link rel="stylesheet" src="{{ ltrim(public_path('js/jquery.min.js'), '/') }}" />
    
    <link rel="stylesheet" src="{{ ltrim(public_path('js/bootstrap.min.js'), '/') }}" />
 

this not worked. the js charts not displayed in the pdf

i alos tried like this


<link rel="stylesheet" href="{{ URL::asset('https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css') }}" />

    <link rel="stylesheet" src="{{ URL::asset('https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js') }}" />

    <link rel="stylesheet" src="{{ URL::asset('https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js') }}" />

even i use css progress bar but that too didnt worked for me..

but this too not worked. kindly some one help to generate charts.

its better to generate charts in javascript or laravel??

Kindly some one help

0 likes
12 replies
AbdulBazith's avatar

after few reference i started installing barryvdh/laravel-snappy

everthing done

but still css files are not loading properly. images are loaded correctly. whats the reason guys

how i added is

  <link href="{{ public_path('newprint/css/font-for-print.css') }}" rel="stylesheet" type="text/css" />

    <link href="{{ public_path('newprint/css/chek.css') }}" rel="stylesheet" type="text/css" />

    <link href="{{ public_path('newprint/js/pi-chart.css') }}" rel="stylesheet" type="text/css" />

(or)
    <link rel="stylesheet" href="{{ URL::asset('newprint/css/font-for-print.css') }}" />
    <link rel="stylesheet" href="{{ URL::asset('newprint/css/chek.css') }}" />
       <link rel="stylesheet" href="{{ URL::asset('newprint/js/pi-chart.css') }}" />


both the links not working. the chart is displayed but it changed. the progress bar are not in correct order.

kinldy some one help please

bobbybouwmann's avatar

Wait... You have questions about snappy and DOMPDF... What are you using right now? This is a mess.

The reason the sharts do not display is that DOMPDF only renders your HTML and CSS, not your javascript.

At this point, it might be better for you to use a tool like Puppeteer to render your view in the browser and export that to an image or PDF.

This package can do that for you: https://github.com/spatie/browsershot

Note: You need to install some stuff for this as well, shared hosting probably doesn't support this.

AbdulBazith's avatar

@bobbybouwmann thank you soo much for your response.

actually these much days i used barryvdh/laravel-dompdf only because just my client expected only tables so.

But now my client is a school. so they need charts, graphs, progress bar for student reports.

barryvdh/laravel-dompdf not supporting external css, javascript charts etc. so when i referred in google most of them said it is impossible to use barryvdh/laravel-dompdf for javascript charts,

so i planned to use barryvdh/laravel-snappy package.

in local pdf working fine. but as you said in live how i should do the change?? whether it is possible in shared hosting??

and one more thing i face error when working taking print out in images in barryvdh/laravel-snappy

the error is


The exit status code '1' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files [===========================> ] 45% Warning: Failed to load file:///C:/Users/Azasoft/AppData/Local/Temp/css/font-for-print.css (ignore) Warning: Failed to load file:///C:/Users/Azasoft/AppData/Local/Temp/css/question.css (ignore) Warning: Failed to load file:///C:/Users/Azasoft/AppData/Local/Temp/css/progress-bar.css (ignore) [============================> ] 48% Error: Failed to load c:/xampp/htdocs/Laravel/OnlineExam-18-05-2020-staff/public/storage/, with network status code 202 and http status code 0 - Cannot open c:/xampp/htdocs/Laravel/OnlineExam-18-05-2020-staff/public/storage/: Path is a directory 

what may be the problem???

bobbybouwmann's avatar

Well, you're already pointing to the incorrect CSS file so it seems.

1 like
AbdulBazith's avatar

@bobbybouwmann then you are saying that barryvdh/laravel-dompdf will support css and js if path is correct??

kindly suggest any solution for local images loading and in live server also?

AbdulBazith's avatar

@bobbybouwmann

kindly please suggest any package. that need to support external css and js files.

still now i cant get any idea please..

you suggested Browsrshot but i need to fetch few data from db. i will list all the names in the screen and then i will check few students and then will take pdf. i think this is not possible in BrowserShot.

Kindly please suggest any package

bobbybouwmann's avatar

Browsershot just creates a screenshot or PDF form a certain view. You can just create a view and pass the data to the view like you normally would it would work just fine.

Note that browsershot might not work on shared hosting.

AbdulBazith's avatar

@bobbybouwmann but i need a package that must work in shared hosting with using css and js.

when i referred in google most of them said barryvdh/laravel-dompdf will support css. but not all the css tags only a few tags.

but iam having progress bar, etc. do u have any idea ?? any package that must run in local system and live server with css and js???

my client expecting charts, student mark in progress bar?? all these how can i do?? i was so confused, past one week iam suffering to get this pdf issue.

till these days what i did is i used snapey pdf in my local and daily i will take printout and mail them. but how long i can do this, i need to give print permission to them

i will show my expectation also.

image: https://imgur.com/01e3bjQ

please check this image and please suggest me a best package.. plz

bobbybouwmann's avatar

You can tell me all you need, but you need a certain server dependencies to run this kind of software. Nobody said it would be easy!

I really can't help you, because there is no such package that supports all your needs for shared hosting.

Please or to participate in this conversation.