createPDF v. 1.10 failing on new install

9 posts by 3 authors in: Forums > CMS Builder
Last Post: July 24   (RSS)

I have migrated a previously existing website to a new server. Our use of the createPDF plugin on the old site worked well.

When it failed on the new server, I installed the latest version of the plugin, downloaded the available binaries and then specified the best one at the top of createPDF.php

$GLOBALS['CREATEPDF_BINARY_FILE'] = 'wkhtmltopdf-0.12.6-1.debian9_stretch_amd64';

After this, running the test within the plugin comes up green everywhere, suggesting that all should be well.

However, all my calls to the plugin in my application fail with the error:

"Exit with code 1 due to network error: ContentNotFoundErrorError executing wkhtmltopdf! (Exit code: 1)<br>"

My web host is uninterested in helping with software issues, so I was wondering if anyone has any insight into this problem?

Sorry. Realized I should have posted this in the plugins forum!

I have read about this error and have removed relative p[aths from my html but this has not solved anything.

Has anyone else encountered this issue?

Hello pgplast,

It seems you are on the right track and this error seems to be involving one of many scenarios...

  1. It is a relative URL that it is having trouble with
  2. It is running across a link which is broken or the resource is not available (like missing a linked file or something like a font file)
  3. If a link is returning something like a 403 response (forbidden) 
  4. It is choking on some JavaScript (but this seems to be a bit of an outlier)

I think what might help is to show us what is the HTML you are trying to convert and perhaps we can see something you are missing.

I guess the wkhtmltopdf can be a bit finicky at times and so something minor could be the problem. I am guessing that if you had it working before on the other server, perhaps you missed transferring a file to the new server or the new server is not allowed to access something that the original server could. I would start with the HTML you are trying to convert and work from there. :)

Tim Hurd
Senior Application Developer
TimHurd.com

Thanks Tim:

I don't think calls via relative urls is the issue, as a have a page with none at all that also fails. The code below.

Any thoughts about what could be different on this server. If I had a notion I could approach the server admins with a request.

Thanks.

-----------

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
if(!isset($_GET['dos'])) {
die("No date specified!");
} else {
$dos = $_GET['dos'];
$dos_for_header = date("M d, Y",strtotime($dos."+ 7 days"));
$dos_for_PDF = date("m_d_Y",strtotime($dos));
$dos_for_labs = date("M d, Y",strtotime($dos));
}

if(!isset($_GET['facility'])) {
die("No facility specified!");
} else {
$facility_num = $_GET['facility'];
}

// load viewer library
$libraryPath = 'cmsCSoft/lib/viewer_functions.php';
$dirsToCheck = ['','../','../../','../../../','../../../../']; // add if needed: '/home/mdwoundconsult/public_html/'
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

############Limit logged in users to only their facilities #####
///make sure logged in
if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }
///now keep out anyone who might get to this by changing querystring value if he doesn't belong wirth this facility
$facilities_list = $CURRENT_USER['facilities'];
$cleanedValue = trim($facilities_list,"\t");
$facility_array = explode("\t",$cleanedValue);
if(!in_array($facility_num,$facility_array)) {
die("You do not have access to this area!");
} // end if
#####################


// load records from 'patients' who are active and from this facility
list($patientsRecords, $patientsMetaData) = getRecords(array(
'tableName' => 'patients',
'loadUploads' => false,
'allowSearch' => false,
'where' => 'active =1 AND facility ='.$facility_num,
));


// load records from 'visits' for the facility and dos passed in the querystring
// from this we will get the numbers of the patients and the visit type (new or followup)
list($visitsRecords, $visitsMetaData) = getRecords(array(
'tableName' => 'visits',
'loadUploads' => false,
'allowSearch' => false,
'orderBy' => 'room_number ASC',
'where' => "facility='".$facility_num."' AND date_of_service='".$dos."' AND followup !='1'",
));


/// pmg slim down the facilities table
$facility_query = "SELECT num, name FROM cmsb_facilities WHERE num=".$facility_num;
$facilitiesRecords= mysql_select_query($facility_query, $indexedArray = false);
// load records from 'facilities' to get the name
/*list($facilitiesRecords, $facilitiesMetaData) = getRecords(array(
'tableName' => 'facilities',
'loadUploads' => false,
'allowSearch' => false,
'where' => 'num='.$facility_num,
));*/
$facilitiesRecord = @$facilitiesRecords[0];
$facility_name = $facilitiesRecord['name'];

// load records from 'labs' for this particular date check for particualr patient below
list($labsRecords, $labsMetaData) = getRecords(array(
'tableName' => 'labs',
'loadUploads' => false,
'allowSearch' => false,

));

if (@$_REQUEST['pdf']) {
createPDF_fromOutput('attachment', 'Rounding_List_'.$dos_for_PDF.'.pdf');
}

?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Create Rounding List</title>

<style media="all">
body {
font-family:Verdana,Arial, sans-serif;
font-size:9px;
margin:0;
padding:0px;
}
.bold_it{
font-weight:bold;
}
table {
margin:5px;
padding:0px;
}

</style>
</head>
<body>

<div <!--class="Section1"-->>

<h3>Nursing Home: <?php echo $facility_name; ?>- <?php echo $dos_for_header; ?></h3>
<?php $patient_num = 1; ?>
<table width="100%" border="1" cellpadding="2" cellspacing="0">
<tr class="bold_it">
<td>Number</td>
<td>Patient Name</td>
<td>Room/Bed</td>
<td>Allergies</td>
<td>Medications</td>
<td>PMH</td>
<td>Tests/Consults</td>
</tr>
<?php $patients_formerly_seen_array=array();?>
<?php foreach($visitsRecords as $visitsRecord) {

$visit_type = $visitsRecord['visit_type:label'];

$patient_number = $visitsRecord['patient'];
array_push($patients_formerly_seen_array,$patient_number);

//$check_next_visit = $visitsRecord['check_next_visit'];
$recommended_tests = join(', ', $visitsRecord['recommended_tests:labels']);
$recommended_consults = join(', ', $visitsRecord['recommended_consults:labels']);

foreach($patientsRecords as $patientsRecord) {
if($patientsRecord['num']==$patient_number) {
$allergies = join(', ', $patientsRecord['medicine_allergies:labels']);
if($patientsRecord['medicine_allergy_other']) {
$allergies .= " ".$patientsRecord['medicine_allergy_other'];
}
$patient_name = $patientsRecord['last_name'].", ".$patientsRecord['first_name'];
$room_bed = $patientsRecord['room_bed'];
$medications = $patientsRecord['medications'];
$pmh = $patientsRecord['pmh'];
/// pmg add test results for rounding sheet

///now get MOLST info
$molst = "";
if($patientsRecord['dnr']) {$molst .= "&nbsp;DNR"; }
if($patientsRecord['dni']) {$molst .= "&nbsp;DNI"; }
if($patientsRecord['dnh']) {$molst .= "&nbsp;DNH"; }
if($patientsRecord['no_iv']) {$molst .= "&nbsp;No IV"; }
if($patientsRecord['no_feeding_tube']) {$molst .= "&nbsp;No Feeding Tube"; }
if($patientsRecord['comfort_only']) {$molst .= "&nbsp;Comfort Only"; }


$test_results = "";

/// are there labs for this day?? If so, check for this patient and then gather
if($labsRecords) {
foreach($labsRecords as $labsRecord) {
$dos_for_this_lab = date("M d, Y",strtotime($labsRecord['exam_date']));
if($labsRecord['patient'] == $patient_number && $dos_for_this_lab ==$dos_for_labs) {
if($labsRecord['abpi']) {
$test_results .= "ABPI: ".$labsRecord['abpi']."<br>";
}
if($labsRecord['arterial_doppler']) {
$test_results .= "Art. Doppler: ".$labsRecord['arterial_doppler']."<br>";
}
if($labsRecord['venous_doppler']) {
$test_results .= "Ven. Doppler: ".$labsRecord['venous_doppler']."<br>";
}
if($labsRecord['xrays']) {
$test_results .= "XRay: ".$labsRecord['xrays']."<br>";
}
if($labsRecord['mri']) {
$test_results .= "MRI: ".$labsRecord['mri']."<br>";
}
if($labsRecord['bone_scan']) {
$test_results .= "Bone scan: ".$labsRecord['bone_scan']."<br>";
}
} // end if

}// end foreach labrecord

} // end if labRecords

break;
}// end if $patientsRecord['num']
} // end foreach($patientsRecords)



/// now build the table
?>
<tr>
<td width="5%"><?php echo $patient_num;?></td>
<td width="15%"><span class="bold_it"><?php echo $patient_name;?></span><br/><span style='font-size:0.6em;font-weight:bold;'><?php echo $molst;?></span></td>
<td width="5%"><?php echo $room_bed;?></td>
<td width="10%"><?php echo $allergies;?></td>
<td width="20%"><?php echo $medications; ?></td>
<td width="25%"><?php echo $pmh; ?></td>
<td width="20%"><?php if(!empty($recommended_tests)) {?><span style="font-size:10px;">Rec. Tests: <?php echo $recommended_tests; ?></span><br /><?php }?>
<?php if(!empty($recommended_consults)) {?><span style="font-size:10px;">Rec. Consults: <?php echo $recommended_consults; ?></span><?php }?>
<!-- pmg add -->
<?php if(!empty($test_results)) {?>
<br><span style="font-size:10px;">Results: <?php echo $test_results; ?></span>
<?php } ?>
</tr>

<?php //if(!empty($check_next_visit)) {?>
<!-- <tr><td colspan="7" height="20" class="text10_bold">Check >> <?php //echo $check_next_visit;?></td></tr>-->
<?php //}?>
<tr><td colspan="7" height="20"><span class="bold_it">Home | Hosp | Visit | Exp </span> -- Summary:&nbsp;</td></tr>

<?php
$patient_num++;
} // end foreach $visitsRecords ?>
</table>
<?php /*Now add list of those patients not seen last time*/?>
<?php
$more_patients = false;
$more_patients_array = array();
foreach($patientsRecords as $patientsRecord) {
///if the patient number is not in the formerly seen group and the patient has no PMH or Medications
///he must be new since nurses can't enter those values
if(!in_array($patientsRecord['num'],$patients_formerly_seen_array) && !$patientsRecord['pmh']) {
$more_patients = true;
$temp_array=array($patientsRecord['room_bed'],$patientsRecord['last_name'],$patientsRecord['first_name']);
array_push($more_patients_array,$temp_array);
}
} // end foreach($patientsRecords as $patientsRecord)
if($more_patients) { ?>
<h3>New Patients Since Last Rounds</h3>
<table width="100%" border="1" cellpadding="2" cellspacing="0">
<tr><td>Number</td><td>Patient Name</td><td>Room/Bed</td></tr>
<?php $more_patient_num=1;?>
<?php foreach($more_patients_array as $more_patient) {
echo "<tr><td width='10%'>".$more_patient_num."</td><td width='20%'>".$more_patient[1].", ".$more_patient[2]."</td><td width='70%'>".$more_patient[0]."</td></tr>";
$more_patient_num++;
}
?>
</table>
<?php } // end if($more_patients)
?>

</div>
</body>
</html>

Hi pgplast,

So what you show there is the PHP code used to generate the HTML. Do you have this page hosted on the public web so we can visit it? I think what we need to see is the resulting HTML generated by this PHP. I am assuming that the script looks at the resulting HTML code and uses that to build the PDF. If the PHP generates a relative link or a link that is pointing to a file that doesn't exist, it may then have the issue. If we can see the page up on the new server, we can look at the source code and see if there are any links/resources there that may be an issue.

Hopefully you get what I am saying. :)

Tim Hurd
Senior Application Developer
TimHurd.com

Thanks for the reply, Tim.

Al the pages that give access to these functions require user authentication. I will open a secod. level request so I can share credentials.

I have tried this with both v 1.09 and v 1.10 of createPDF and both fail.

Interestingly, v. 1.09 continues to work flawlessly on our old,server, and the pages that work there are the same ones that fail on the new server. I didn't change any of the code, so it would seem to suggests a difference in server setting.

I have been over it with the web host, (LiquidWeb), but no joy.

Hope you'll be able to see something when I submit for 2nd level.... and thanks.

Hi pgplast, 

CreatePDF works by using the wkhtml2pdf binary to make a browser request for a page and then turning it into a PDF.

However, the way your web server is setup, it has both an external IP address and hostname (the one we all use) and a private internal IP address used only inside the web hosting company's network.   The server is configured to disallow any internal requests to its external IP.  Sometimes this prevents things from working at all, but in your case, we can still make a request to the web server via its internal IP address.  The way to do this is to add this line at the bottom to createPDF.php:

// Note: If this doesn't work try https:// or finding the server's internal IP with 127.0.0.1, $_SERVER["LOCAL_ADDR"], `ipconfig /all`,
// ... or `ifconfig -a` or ask server admins for server's internally accessible  hostname
//$GLOBALS['CREATEPDF_TEMPDIR_URL']       = "http://" . @$_SERVER['HTTP_HOST'] . dirname(@$_SERVER['SCRIPT_NAME']);
$GLOBALS['CREATEPDF_TEMPDIR_URL']       = "https://" . @$_SERVER['SERVER_ADDR'] . dirname(@$_SERVER['SCRIPT_NAME']);

Can you test now?  I think that might fix it for you.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

Dave:

Thanks so much. You solved it, (as expected).

You guys provide the best support ever!