PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] All of a sudden external links not working in barryvdh/laravel-dompdf

 February 16, 2022     laravel-5     No comments   

Issue

I am using barryvdh/laravel-dompdf for quite long. Using external CSS (From local) and font (From CDN), It was working fine and suddenly the design collapsed, also the font not working so I've checked in the view and came to know the view is not loading the CSS & fonts. I am using Laravel 5.5 and barryvdh/laravel-dompdf version is 0.8.6. Tried in Laravel 8 with barryvdh/laravel-dompdf version 0.9.0 also not working.

Code:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Receipt | {{ Auth::user()->name }} - {{ $setting->name }}</title>
    <link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet" type="text/css" media="all" />
    <link href="{{ asset('css/main.css') }}" rel="stylesheet" type="text/css" media="all" />
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" media="all" />

    <style type="text/css">
        /* Another font (Chinese) loaded from local folder for particular tags */
    @font-face {
            font-family: SimHei;
            src: url('{{asset('fonts/simhei.ttf')}}') format('truetype');
        }
        body{
           font-family: Open Sans, Sans-serif; line-height: 1;
        }
        p {
            font-size: 18px;
            margin-bottom: 0 !important;
        }
    </style>
</head>

For CSS, I have tried to update

<link href="{{ asset('css/main.css') }}" rel="stylesheet" type="text/css" media="all" /> 

to

On Local:

<link href="{{ public_path('css/main.css') }}" rel="stylesheet" type="text/css" media="all" /> 
<link href="{{ base_path().'/css/maincss' }}"  rel="stylesheet" type="text/css" media="all" /> 
<link href="http://127.0.0.1:8000/css/main.css' }}"  rel="stylesheet" type="text/css" media="all" />

On server:

<link href="var/www/html/project/public/css/main.css"  rel="stylesheet" type="text/css" media="all" /> 

For the font, I have tried to have it in a local folder as a .ttf file, and importing in style still doesn't work.


Solution

I've managed to solve this issue.
Posting here incase it can help someone.
Replaced barryvdh/laravel-dompdf with barryvdh/laravel-snappy

Package Link : https://github.com/barryvdh/laravel-snappy

My external styles, images & fonts are not loaded.
For styles i have created a blade file, updated it with css codes and included it in the pdf template blade.
For images i have created an absolute path

<img src="{{ public_path('images/img1.jpg')}}" alt="No Image" />

For font i have installed the font on the server, I am using ubuntu 16.04, I have installed open sans and SimHei (Chinese font) and updated the font-family to open sans & simhei in my application.



Answered By - Sinthu San
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing