dompdf / dompdf/dompdf

Problems to Create a PDF from Outsider HTML with tables

Open
#1,858 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug css tables
Dominant language
PHP
Stars
11.2k
Forks
1.8k
PR merge metrics
No merged PRs in 30d

Description

Hi there,

I'm trying to use DOMPDF to create a PDF from a link that is given for my ERP..
Let me try explain my issue..

I'm using Magento, and we have an ERP (TinyERP) that create a receipt to all sales made in our Magento Plataform, this receipt are made in HTML/CSS/JS and all structure are made with Tables and DIVs..
As you can see in this link: https://erp.tiny.com.br/doc.view?id=c176837d79be40ebd9da8ec5f8851c46

This HTML are good, and when the page its open, will give the option to print the page..
My problem is that I dont have access to change anything about this CSS.. and when I'm trying to use this link to create the PDF in Magento Module that I've made.. the PDF are totally wrong... Check the difference between the files;

1 - How the PDF show be created by DOMPDF:
pdf_ok_how_must_to_be

2 - How the PDF was been created by DOMPDF:
part_1_pdf
part_2_pdf
part_3_pdf

I will leave here a piece of my PHP Function that create a PDF, this a Controller from my Magento Module.. please, let me know if its possible to get this PDF done right... Ok?
I'm missing something?

Could be the margins? Keep in mind that I haven't access for this CSS that are given for the ERP..
Let me know if you need any other information..
SeeYa!

The Controller:

<?php
use Dompdf\Dompdf;
use Dompdf\Options;
require_once(Mage::getBaseDir('lib') . '/dompdf/autoload.inc.php');
class Fbxweb_TinyNFE_IndexController extends Mage_Core_Controller_Front_Action{

// USING CURL TO GET THE HTML FILE
function get_req($url) {
        $curl = curl_init($url); 
        curl_setopt($curl, CURLOPT_FAILONERROR, true); 
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   
        $result = curl_exec($curl); 
        return $result;
    }
// FUNCTION TO CREATE A PDF WITH DOMPDF    
public function DownloadNFEAction(){
  $checkFile = Fbxweb_TinyNFE_IndexController::get_req($_GET['nota_fiscal']);
  $options = new Options();
  $options->set('isRemoteEnabled', TRUE);
  $dompdf = new Dompdf($options);
  $context = stream_context_create([ 
            'ssl' => [ 
                'verify_peer' => FALSE, 
                'verify_peer_name' => FALSE,
                'allow_self_signed'=> TRUE 
            ] 
        ]);
        $dompdf->setHttpContext($context);
        $dompdf->loadHtml($checkFile);
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->render();
        $dompdf->stream();
    }
}

Its that possible to make this PDF been correctly created with DOMPDF with this outsider link given for our ERP automatically when the order are made.. I know that there is no problem about the Magento or TinyERP, the issue its about how the DOMPDF get the HTML information and generate the PDF..

How can fix this issue, anyone can help me, please?
SeeYa!
And thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the DownloadNFEAction entry point and its get_req helper, then inspect how the fetched external HTML is passed to Dompdf through loadHtml and render. Reproduce the report using the linked HTML and the supplied controller settings, comparing the source tables and CSS with the generated PDF. Done would require a minimal reproducible case and a confirmed rendering fix or documented unsupported markup.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.