This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Failed to load PDF document

cishinc1 wrote on 2013-11-27:
I am using pdfcrowd and in some situation I have the generated file displayed in my browser immediately after generation, but over the last
few days I keep getting "Failed to load PDF document" irrespective of the browser I use. I have tried Chrome, IE, FireFox, Safari same result.

Also, I have not changed the code, I have not changed browsers ( have been using the same browser for years and years ).
What do I need to check for.


Here below is the code, and I expect to hit the lines in blue & bold.

if ( file_exists( $pdfFile ))
{
$in_file = fopen($pdfFile, "rb");
$pdfcontents = fread($in_file, filesize($pdfFile));
fclose($in_file);
}
else
{

try
{
// create an API client instance
$pdfclient = new Pdfcrowd( $PDFID, $PDFKEY );

// Do PDF page setup
$pdfclient->setPageWidth("8.5in");
$pdfclient->setPageHeight("11in");
$pdfclient->setHorizontalMargin("0.7in");
$pdfclient->setVerticalMargin("0.5in");
if ( $cishID == "iprpt" || $cishID == "bprpt" || $cishID == "schbus" || $cishID == "monthlyrpt" || $cishID == "90dayrpt" ||
$cishID == "daychartingrpt" )
{
$pdfclient->setPageWidth("11in");
$pdfclient->setPageHeight("8.5in");
$pdfclient->setHorizontalMargin("0.4in");
$pdfclient->setVerticalMargin("0.5in");
}

if ( $cishID == 'clientsbyhse' )
{
if ( is_numeric($theID) )
{

}
else
{
$pdfclient->setPageWidth("11in");
$pdfclient->setPageHeight("8.5in");
$pdfclient->setHorizontalMargin("0.4in");
$pdfclient->setVerticalMargin("0.5in");
}
}

if ( $cishID == "emergency" )
{
$pdfclient->setVerticalMargin("0.4in");
}
if ( $cishID == "medreview" )
{
$pdfclient->setVerticalMargin("0.25in");
}
// Set HTML Options
$pdfclient->enableHyperlinks(False);
$pdfclient->enableBackgrounds(False);
//$pdfclient->setHtmlZoom(98);
$pdfclient->usePrintMedia(True);

// Set PDF options
//$pdfclient->setPdfScalingFactor(0.98);

// convert an html file and store the generated PDF into a $pdfcontents variable
$pdfcontents = $pdfclient->convertFile( $htmlFile );
//echo "Just passed pfdcontents<br>";
//$out_file = fopen($pdfFile, "wb");
//$pdfclient->convertFile( $htmlFile, $out_file );
//fclose($out_file);

}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}
}
// set HTTP response headers
header("Content-Type: application/pdf");
//header("Content-Type: text/html");
header("Cache-Control: no-cache");
header("Accept-Ranges: none");

// send the generated PDF
echo $pdfcontents;

Admin
CIS&H
support wrote on 2013-11-27:
Hello,

Is there any way I can reproduce the issue in my browser?
cishinc1 wrote on 2013-12-04:
Try to recreate issue using these steps

(1) Point browser to cishinc.com
(2) Sign On ( top menu ) ID/password = demo/demo
(3) Go to Reports => Resident Reports => Activity Report
(4) Do not worry selecting anything, Just click on Display Report
(5) Now scroll to the bottom of the page and click Print Report
support wrote on 2013-12-05:
Hello,

The page returns an empty response - that's why you are getting the "Failed to load PDF document" error. I checked our API logs and I don't see any hit from your application when I click the 'Print Report' button.

This indicates that the $pdfcontents variable is empty and also that your application does not call the API but uses the "if( file_exists( $pdfFile ))
{ ... }" branch.

I would recommend that you add some tracing to your code to indicate which part of your code is being executed. Also verify that if $pdfFile exists on your server, it is not empty.
cishinc1 wrote on 2013-12-05:
I found the error. It was the name of the html file. Now I remember I recently made a change in the name of the file when it was created.
and did not make the corresponding change when attempting to use the file to generate the PDF.

Thanks for your assistance.