0

I'm using Laravel 4 with dompdf package: https://github.com/barryvdh/laravel-dompdf

When I generate a report and it converts it to PDF on my local, everything is fine and displays well, but when I do the same exact thing on my production server, it displays random letters where there is either dynamic or static content.

Screenshot of local vs production:

http://s28.postimg.org/u5zk3pc19/report_diff.png

Here is the code that creates the PDF:

/**
 * Create PDF
 *
 */
public function createPdf( $reportData )
{
    if( $this->validate() )
    {
        // Get Final Data Information
        $btu_hp = static::getBtuHp( $reportData['booth_cfm'], $reportData['cure_temp_hp'], $reportData['outside_temp'] );
        $btu_current = static::getBtuCurrent( $reportData['booth_cfm'], $reportData['bake_temp_current'], $reportData['outside_temp'] );

        $reportData['energy_percentage_per_unit'] = static::getEnergyPercentagePerUnit( $btu_hp, $btu_current );
        $reportData['energy_dollar_per_unit'] = static::getEnergyDollarPerUnit( $reportData['cost_per_therm'], $reportData['bake_time_current'], $reportData['cure_time_hp'], $btu_current, $btu_hp );
        $reportData['time_savings_per_unit'] = static::getTimeSavingsPerUnit( $reportData['bake_time_current'], $reportData['cure_time_hp'] );
        $reportData['time_savings_per_year'] = static::getTimeSavingsPerYear( $reportData['time_savings_per_unit'][0], $reportData['units_per_day'], $reportData['production_days'] );
        $reportData['labor_dollar_per_year'] = static::getLaborDollarPerYear( $reportData['labor_rate'], $reportData['time_savings_per_year'][0] );
        $reportData['energy_dollar_per_year'] = static::getEnergyDollarPerYear( $reportData['energy_dollar_per_unit'][0], $reportData['units_per_day'], $reportData['production_days'] );

        $view = View::make('pages.report.hp-report.print', array('report' => $reportData));

        if( ! $this->saveAsPdf($view, $this->generateFileName()) )
        {
            return false;
        }

        return true;
    }

    return false;
}

/**
 * Save report as PDF
 * @param html         HTML of PDF
 * @param fileName     Name of File
 *
 */
public function saveAsPdf( $html, $fileName = null )
{
    if(is_null($fileName))
        $fileName = $this->generateFileName();

    $htmlPath = $this->reportDirectory.'/'.$fileName.'.html';
    $pdfPath = $this->reportDirectory.'/'.$fileName.'.pdf';

    file_put_contents( $htmlPath, $html );

    // set recent PDF to name of PDF
    $this->recentReportFile = $fileName . '.pdf';
    return PDF::loadFile($htmlPath)->save($pdfPath);
}

/**
 * Get most recent uploaded PDF
 *
 */
public function getRecentPdf()
{
    return $this->recentReportFile;
}

/**
 * Generate file name for PDF
 *
 */
public function generateFileName()
{
    return Auth::user()->id . '_hp_' . str_random(10) . '_' . time();
}

Everything writes fine and it uses the right template and has the styling... Only the static content and dynamic content (values written out with PHP variables) display badly, although you can see some of the static content like Energy Savings and such prints fine.

Is there a reason this could be all jumbled up on the live server, but not local?

Here is the HTML for the view that is being grabbed (the HTML the php variables are injected into): http://pastebin.com/5bMR6G2s

And here is my config file for dompdf: http://pastebin.com/Ld6MQckG

Remy San
  • 525
  • 1
  • 4
  • 24
HaleyBuggs
  • 915
  • 3
  • 13
  • 29
  • Can you also post the generated HTML? I don't see anything at first glance that would indicate the problem. Maybe a corrupted font file? Have you tried different fonts? – BrianS Jul 01 '14 at 19:48

1 Answers1

2

There are two possible causes for this:

  1. Missing font(s) on the production server. Make sure you have the correct fonts installed on the production site.

  2. Character encoding issues. I'm not sure which site (dev/live) the issue is on, but it may be that one is outputting UTF-8 and the other is not. You could try to sort this out by detecting the encoding on the input file on both dev and live by using mb_detect_encoding and see if they're different. If they are, then use mb_convert_encoding before converting to PDF.

Kryten
  • 15,230
  • 6
  • 45
  • 68
  • They both output this: string(5) "ASCII" Where exactly does it grab the fonts? Like the directory? I looked at that package github page and it says it's stored in your app/storage/fonts folder and the contents in that directory are the same both on my live and prod server... The error is on the prod server. When I view it in the URL, it shows as blank and when I pull the file up on my computer, it shows that weird verbiage.. – HaleyBuggs Jun 30 '14 at 17:38