Im trying to print to our printers connected to Google Cloud Print via Google Chrome using PHP SDK. The Printer we are trying to print is a Thermal Printer and we use the same code to print on other Thermal Printer without any issues, the issue we had is specific to this Printer http://www.zjiang.com/en/init.php/product/index?id=42
We had installed the said PHP SDK and tried to send a URL to print, and we are getting the response as An error occurred while printing the doc. Error code:
403 Message:Could not convert to PDF.
This is due to the Layout error, as we understand from here, So i'm looking on how to specify this Layout settings on https://github.com/yasirsiddiqui/php-google-cloud-print SDK.
Here is the function which is doing that,
public function sendPrintToPrinter($printerid,$printjobtitle,$filepath,$contenttype) {
// Check if we have auth token
if(empty($this->authtoken)) {
// We don't have auth token so throw exception
throw new Exception("Please first login to Google by calling loginToGoogle function");
}
// Check if prtinter id is passed
if(empty($printerid)) {
// Printer id is not there so throw exception
throw new Exception("Please provide printer ID");
}
// Open the file which needs to be print
$handle = fopen($filepath, "rb");
if(!$handle)
{
// Can't locate file so throw exception
throw new Exception("Could not read the file. Please check file path.");
}
// Read file content
$contents = file_get_contents($filepath);
// Prepare post fields for sending print
$post_fields = array(
'printerid' => $printerid,
'title' => $printjobtitle,
'contentTransferEncoding' => 'base64',
'content' => base64_encode($contents), // encode file content as base64
'contentType' => $contenttype
);
// Prepare authorization headers
$authheaders = array(
"Authorization: Bearer " . $this->authtoken
);
// Make http call for sending print Job
$this->httpRequest->setUrl(self::PRINT_URL);
$this->httpRequest->setPostData($post_fields);
$this->httpRequest->setHeaders($authheaders);
$this->httpRequest->send();
$response = json_decode($this->httpRequest->getResponse());
// Has document been successfully sent?
if($response->success=="1") {
return array('status' =>true,'errorcode' =>'','errormessage'=>"", 'id' => $response->job->id);
}
else {
return array('status' =>false,'errorcode' =>$response->errorCode,'errormessage'=>$response->message);
}
}
I expect the print to go smoothly to the said printers without any errors, since we use the same code to print on almost all printers expect these.