PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label dompdf. Show all posts
Showing posts with label dompdf. Show all posts

Friday, May 20, 2022

[FIXED] how to add php gd with composer (laravel 8)

 May 20, 2022     composer-php, dompdf, gd, php, require     No comments   

Issue

I trying to add php gd to the composer.json. I want to install php gd because of the following error :

The PHP GD extension is required, but is not installed.

The error was caused by dompdf as dompdf requires php gd to process images. I tried the following command :

composer require "ext-gd:*" --ignore-platform-reqs

Without any result even tough ext-gd was added to the composer.json. Does anyone know a solution to my problem? Thank in advance.


Solution

You can't install GD with Composer. Composer manages other PHP source that your project relies on, but GD is not PHP source -- it's a native PHP extension module like ext-curl or ext-mysqli. Adding ext-gd:* to your composer.json simply means, "This project requires the GD extension to be installed." In order to actually install that extension, you'll need to drop to your OS-level tools. If you're on a Debian-based system, that'll likely be something like:

sudo apt install php-gd

Or, for a RedHat-based system, something like:

sudo dnf install php-gd

Once done, run your composer install again and you should be good.



Answered By - Alex Howansky
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, May 5, 2022

[FIXED] How to manage image paths in DOMpdf in laravel 9

 May 05, 2022     dompdf, image, laravel-9, laravel-blade, laravel-dompdf     No comments   

Issue

Since I updated to Laravel 9 the images in PDFs doesn't get found anymore. Is there any trick with the image source path in Laravel 9? Till now it worked with storage_path() in the pdf's blades.

I use the package Barryvdh\DomPDF

Do anybody know, how to solve that issue?

Thank you very much


Solution

I found a way to solve this problem independently from the package: For the image source I defined a route outside of any middleware and defined a ResourceController which is returning the path. When you have several tables with image data, you have to define a route for each single table!

I could combine it easely with an authority check inside the Controller...

Blade:

<img src="{{ route('routename', [var1, var2]) }}">

web.php

Route::get('pathtoimages/{var1}/{var2}', 'ResourceController@getAuthorizedImage')->name('routename');

Controller:

public function getAuthorizedImage($var1, $var2, Request $request) 
{
    // any checks...
    $resource = ObjectImage::find($var2);

    return response()->file(Storage::path($resource->path));
    //image path saved in table column "path"
}

That's the way it works.

Stay healthy and peaceful

CruiseLee



Answered By - CruiseLee
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, March 14, 2022

[FIXED] Dompdf 0.8.3 not fetching remote CSS in PHP 7.2 and CodeIgniter 3

 March 14, 2022     codeigniter, dompdf, php     No comments   

Issue

I'm upgrading my environment to PHP7.3 (from PHP5.5) and my DomPDF new installation (from 0.6 to 0.8.3) does not fetch any external CSS files. All server-related configuration seems ok, but only relative CSS files are loaded.

What may I be missing?

I'm using the following lines to generate the PDF:

require_once("dompdf_0-8-3/autoload.inc.php");

$options = new Dompdf\Options();
$options->set(array('isPhpEnabled'          => true, 
                    'isRemoteEnabled'       => true, 
                    'isJavascriptEnabled'   => false, 
                    'isHtml5ParserEnabled'  => true, 
                    'tempDir'               => sys_get_temp_dir())
        );

$dompdf = new Dompdf\Dompdf();
$dompdf->setOptions($options);    
$dompdf->loadHtml($html);    
$dompdf->setPaper($size, $orientation);            
$dompdf->render();
$dompdf->stream($filename.".pdf");

Note: I'm using base_url() in link href's tag, inside the HTML view.

Anyone has the same problem or any suggestion on how to solve?


Solution

The problem was due to a port redirection issue in the server. Solved :) Thank you all!



Answered By - Pedro Conrad Junior
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, March 8, 2022

[FIXED] Dompdf UT8 with database records with accents

 March 08, 2022     dompdf, laravel     No comments   

Issue

I have a problem with utf8 with my stored data with dompdf for laravel: https://github.com/barryvdh/laravel-dompdf

My column collation is set to

utf8mb4_unicode_ci

In my html file I use:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

So when I write in my html file : éééé and I generate the PDF it's file but when I display my stored data the accents are displayed by : ?

enter image description here

In my config/dompdf.php

I have set :

  "DOMPDF_UNICODE_ENABLED" => true,
  "DOMPDF_PDF_BACKEND" => "CPDF",

What am I doing wrong? The problem only come from my stored data.. Hope someone could help thanks a lot in advance.

When I display my blade page without dompdf on firefox it's also really strange I get spaces between the accents :

enter image description here

But with Chrome all is fine ..

enter image description here

Also when i trie to pass a variable with a accent to my dompdf view the content of the variable is not display when there is an accent

$fede = 'fé'; // not display 
$fede = 'fe'; // is displayed as well.. 

Solution

I had same issue before , and i changed many things but i couldn't make it to work , then i switched to niklasravnsborg/laravel-pdf and it worked like sharm , give it a try and see



Answered By - BM2ilabs
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, February 4, 2022

[FIXED] Cakepdf not showing image for DomPdf

 February 04, 2022     cakephp, cakephp-4.x, dompdf     No comments   

Issue

I am using cakepdf plugin to generate pdf in cakephp application. I am using below configuration for dompdf

Configure::write('CakePdf', [
            // 'engine' => 'CakePdf.WkHtmlToPdf',
            'engine' => 'CakePdf.DomPdf',
            'margin' => [
                'bottom' => 15,
                'left' => 50,
                'right' => 30,
                'top' => 45
            ],
            'orientation' => 'landscape',
            'download' => false,
            'isRemoteEnabled'=> true
            // 'enable-local-file-access' => true
]);

I have added 'isRemoteEnabled'=> true

For display image I have used

<img src="<?= WWW_ROOT ?>img/4dx/01/00.png" />

I have also tried by

<?php echo $this->Html->image('4dx/01/00.png', ['fullBase' => true]); ?>

Same result no any change found. $this->Html->image this way also not working for WkHtmlToPdf. I am using PHP version 7.4.x

This image perfectly showing if I use WkHtmlToPdf engine, but for dompdf I am not getting image, it's showing not found. Like below image

enter image description here


Solution

Engine options must be passed via the engine option, eg:

'engine' => [
    'className' => 'CakePdf.DomPdf',
    'options' => [
        'isRemoteEnabled' => true,
    ]
],

Also note that the WWW_ROOT constant holds is a filesystem path! In order to be able to access the filesystem you must configure the chroot option in recent versions of Dompdf!

'engine' => [
    'className' => 'CakePdf.DomPdf',
    'options' => [
        // allow local file access to webroot and Dompdf files
        'chroot' => [
            WWW_ROOT,
            ROOT . DS . 'vendor' . DS . 'dompdf' . DS . 'dompdf' . DS,
        ],
    ]
],

See also

  • https://github.com/FriendsOfCake/CakePdf/tree/4.1.1#configuration
  • https://github.com/dompdf/dompdf/wiki/Usage#options
  • https://github.com/dompdf/dompdf/wiki/Usage#security-restrictions-for-local-files
  • https://github.com/dompdf/dompdf/issues/2229


Answered By - ndm
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, January 28, 2022

[FIXED] justify content space between not working in dompdf

 January 28, 2022     dompdf, html, laravel, php     No comments   

Issue

I have such a report that generated by DOMPDF and created with Laravel. I want to display text, one in text-align: left, and another one in text-align: right (both in a same line). But it's not working in my code.

<div class="container m-0">
    <div class="row">
        <div class="col-12 p-0">
            <table>
                <tr>
                    <td>
                        <p class="m-0" style="font-size:.8rem;">
                            <span class="font-weight-bold">Hari, tanggal:</span> 
                            Kamis, 14 Oktober 2021
                        </p>
                    </td>
                    <td align="right">
                        <p class="m-0" style="font-size:.8rem;">Pagi / Siang / Malam</p>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>

enter image description here

Anybody would to help me with this issue please? I've been looking for this but still couldn't find the solution. Thank u in advance


Solution

It's because of your table width.

You can do like:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container m-0">
    <div class="row">
        <div class="col-12 p-0">
            <table class="w-100">
                <tr>
                    <td>
                        <span class="font-weight-bold">Hari, tanggal:</span> 
                            Kamis, 14 Oktober 2021
                    </td>
                    <td align="right">
                        Pagi / Siang / Malam
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>



Answered By - Abolfazl Mohajeri
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, January 22, 2022

[FIXED] Create an Html with OpenTBS

 January 22, 2022     docx, dompdf, opentbs, pdf, php     No comments   

Issue

I'm using tbs '3.8.0' with OpenTBS Plugin version 1.7.6 to create a docx. In the same project I have dompdf.cls.php 468

I know that I can't convert directly a docx to a pdf, so I'm trying to use OpenTBS to create a valid input for Dompdf.

Is there a way to create an html with OpenTBS, or something that I can pass as a valid input to Dompdf ?

As now my docx is created in this way:

    $TBS = new \clsTinyButStrong;
    $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
    $TBS->LoadTemplate('path'.$fileName, OPENTBS_ALREADY_UTF8);
    $TBS->Show(OPENTBS_STRING, $fileName.docx");

Solution

TinyButStrong is a Template Engine that works with any text template. So it fits well to merge HTML pages, and it has some facilities for that. TBS can also merge XML files for example.

Meanwhile, OpenTBS is a plug-in for TinyButStrong that makes it merge Ms Office and LibreOffice documents. Ms Office and LibreOffice documents are technically Zip archives containing XML subfiles. Without OpenTBS, the TinyButStrong template engine cannot merge such documents.

So if you ant to merge HTML pages in order to convert them into PDF using Dompdf, then TinyButStrong (without the OpenTBS plug-in) can do that without problem.

See examples https://www.tinybutstrong.com/examples.php



Answered By - Skrol29
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, January 16, 2022

[FIXED] How to load html file inside cakephp using dompdf

 January 16, 2022     cakephp, cakephp-3.0, dompdf, pdf-generation, php     No comments   

Issue

I am using dompdf with cakephp 3.6 to generate prints from HTML to PDF

I have a function name test inside drivercontroller and i want to load a ctp file which is created inside src\Template\DriverDetails and filename is testpdf.ctp

Can u plz help me to suggest how to pass complete file.

Below is my code

public function test()  {
            $html = file_get_contents("testpdf.ctp");            
            $dompdf = new Dompdf();
            $dompdf->loadHtml($html);
            $dompdf->setPaper('A4', 'portrait');
            $dompdf->render();
            $dompdf->stream("invoice.pdf", array("Attachment" =>0));
            exit(0);
        }

src\Template\DriverDetails\testpdf.ctp

<html>
    <body>
        <table>
            <tr><td align="center"><?php echo $id; ?></td></tr>
            <tr><td align="center">Demo Data</td></tr>
        </table>
    </body>
</html>

Solution

You can try like that way.

public function test()
{
    $data = "This can be accessible in view file";
    $builder = $this->viewBuilder();
    $builder->autoLayout(false);

    // set your template path [don't use .ctp]
    $builder->template('Users/add');

    //Pass data into view file
    $view = $builder->build(['data' => $data]);

    //Render view file content and store into variable
    $viewContent = $view->render();
    var_dump($viewContent);
}


Answered By - Sohel Rana
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

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
All Comments
Atom
All Comments

Copyright © PHPFixing