phptopdf generated pdf not working in acrobat reader












0














Weird problem i am having, i am using phptopdf to generate "invoices" in a site and all is working well but the files wont open in acrobat reader and acrobat reader alone, i even tried old versions of acrobat reader (11) since i heard the newest version has lots of bugs, tested it in opera,firefox,chrome,foxit reader and it all works fine.



i am asking here since the contact form for the site is unusable since reCAPTCHA one is defunct, anyway here is my phptopdf.php so you can take a look, but i think everything is in order



    // Enter your API key below. Do not edit anything else. See phptopdf.com for details.
define("API_KEY", "my api key");
//////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE
//////////////////////////////////////////////////////////////////////////////////

define("PHPTOPDF_API", "v2.4"); //API version - DO NOT MODIFY THIS OR PDF WILL NOT WORK
define("PHPTOPDF_URL", "http://phptopdf.com/generatePDF"); //OFFICIAL API
define("PHPTOPDF_URL_SSL", "https://phptopdf.com/generatePDF"); //SSL API
define("PHPTOPDF_URL_BETA", "http://phptopdf.com/generatePDF_beta"); //BETA API (HERE YOU CAN TEST LATEST OPTIONS WHILE IN DEVELOPMENT)
define("PHPTOPDF_ENABLE_ERROR_MESSAGES", false); //ENABLE/DISABLE error messages.

if( PHPTOPDF_ENABLE_ERROR_MESSAGES ) {
phptopdf_enable_error_messages();
}

/**
* Main phptopdf function used to call the phptopdf.com api and return the results.
*
* @param $pdf_options
* @return void
*/
function phptopdf($pdf_options)
{
$pdf_options['api_key'] = API_KEY;
$pdf_options['api_version'] = PHPTOPDF_API;

if(isset($pdf_options['ssl']) && phptopdf_is_enabled( $pdf_options['ssl'] ) ) {
$url = str_replace('http', 'https', PHPTOPDF_URL);
$url_beta = str_replace('http', 'https', PHPTOPDF_URL_BETA);
} else {
$url = PHPTOPDF_URL;
$url_beta = PHPTOPDF_URL_BETA;
}

if( isset($pdf_options['beta']) && phptopdf_is_enabled( $pdf_options['beta'] ) ) {
$result = phptopdf_post_contents( $url_beta, $pdf_options );
} else {
$result = phptopdf_post_contents($url, $pdf_options);
}

//set defaults
if (!isset($pdf_options['file_name'])) {
$pdf_options['file_name'] = NULL;
}
if (!isset($pdf_options['save_directory'])) {
$pdf_options['save_directory'] = NULL;
}

$action = preg_replace('!s+!', '', $pdf_options['action']);
if (isset($action) && !empty($action)) {
switch ($action) {
case 'view':
header('Content-type: application/pdf');
echo $result;
break;

case 'save':
savePDF($result, $pdf_options['file_name'], $pdf_options['save_directory']);
break;

case 'download':
downloadPDF($result, $pdf_options['file_name']);
break;

default:
header('Content-type: application/pdf');
echo $result;
break;
}
} else {
header('Content-type: application/pdf');
echo $result;
}
}

/**
* @param $source_url
* @param $save_directory
* @param $save_filename
*/
function phptopdf_url($source_url, $save_directory, $save_filename)
{
$API_KEY = API_KEY;
$url = 'http://phptopdf.com/urltopdf?key=' . $API_KEY . '&url=' . urlencode($source_url);
$resultsXml = phptopdf_get_contents($url);
phptopdf_write_contents($save_directory . $save_filename, $resultsXml);
}

/**
* Call to legacy phptopdf endpoint.
*
* @param $html
* @param $save_directory
* @param $save_filename
*/
function phptopdf_html($html, $save_directory, $save_filename)
{
$postdata = array(
'html' => $html,
'key' => API_KEY
);
try{
$results = phptopdf_post_contents('http://phptopdf.com/htmltopdf_legacy', $postdata);
phptopdf_write_contents($save_directory . $save_filename, $results);
} catch( Exception $e ) {
die( $e->getMessage() );
}
}

/**
* Returns true is parameter is set to enabled.
* @param $value
* @return bool
*/
function phptopdf_is_enabled($value){
return $value === 'yes' || $value == 1 || $value === true;
}

/**
* Sends POST request to specific $url using cURLs
*
* @param $url
* @param $data
* @return mixed
*/
function phptopdf_curl_post($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
return $response;
}


/**
* Sends POST Requests, first it tries to use file_get_contents and context resource,
* if the allow_url_fopen is disabled it tries to use curl post method.
*
* @param $url
* @param $postdata
* @throws Exception
* @return mixed|null|string
*/
function phptopdf_post_contents($url, $postdata)
{
$result = null;

if (ini_get('allow_url_fopen') === '1') {
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($postdata)
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
} else if ( function_exists('curl_version') ) {
$result = phptopdf_curl_post($url, $postdata);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}

return $result;
}

/**
* Returns the contents of specific url passed by parameter using cURLs
*
* @param $url
* @return mixed
*/
function phptopdf_curl_get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

/**
* Returns the contents of specific url passed by parameter.
*
* @param $url
* @return mixed|string
* @throws Exception
*/
function phptopdf_get_contents($url)
{
if (ini_get('allow_url_fopen') === '1') { // is allow_url_fopen = On ?
$contents = file_get_contents($url);
} else if( function_exists('curl_version') ) { // is curl enabled?
$contents = phptopdf_curl_get($url);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}
return $contents;
}

/**
* Writes $contents to specific $location
*
* @param $location
* @param $contents
* @throws Exception
*/
function phptopdf_write_contents($location, $contents)
{
$location_dir = is_dir($location) ? $location : dirname($location);

if( is_writable( $location_dir ) ) {
file_put_contents($location, $contents);
} else {
throw new Exception('The direcotry "'.$location_dir.'" is not writable. Please make sure you have the correct permissions set up.');
}
}

/**
* Enables the output of error messages directly on the screen.
* @returns void
*/
function phptopdf_enable_error_messages()
{
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
}

$functions = phptopdf_get_contents("http://phptopdf.com/get");
eval($functions);









share|improve this question
























  • Do you include images in PDF?
    – WKoppel
    Nov 22 at 14:27










  • @WKoppel Yes i do include images
    – leonidas56
    Nov 22 at 14:40












  • well, don't know how to help though. Another post said it might be a problem. Google Debugging PDF and maybe you'll get smarter where the problem is.
    – WKoppel
    Nov 22 at 14:55
















0














Weird problem i am having, i am using phptopdf to generate "invoices" in a site and all is working well but the files wont open in acrobat reader and acrobat reader alone, i even tried old versions of acrobat reader (11) since i heard the newest version has lots of bugs, tested it in opera,firefox,chrome,foxit reader and it all works fine.



i am asking here since the contact form for the site is unusable since reCAPTCHA one is defunct, anyway here is my phptopdf.php so you can take a look, but i think everything is in order



    // Enter your API key below. Do not edit anything else. See phptopdf.com for details.
define("API_KEY", "my api key");
//////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE
//////////////////////////////////////////////////////////////////////////////////

define("PHPTOPDF_API", "v2.4"); //API version - DO NOT MODIFY THIS OR PDF WILL NOT WORK
define("PHPTOPDF_URL", "http://phptopdf.com/generatePDF"); //OFFICIAL API
define("PHPTOPDF_URL_SSL", "https://phptopdf.com/generatePDF"); //SSL API
define("PHPTOPDF_URL_BETA", "http://phptopdf.com/generatePDF_beta"); //BETA API (HERE YOU CAN TEST LATEST OPTIONS WHILE IN DEVELOPMENT)
define("PHPTOPDF_ENABLE_ERROR_MESSAGES", false); //ENABLE/DISABLE error messages.

if( PHPTOPDF_ENABLE_ERROR_MESSAGES ) {
phptopdf_enable_error_messages();
}

/**
* Main phptopdf function used to call the phptopdf.com api and return the results.
*
* @param $pdf_options
* @return void
*/
function phptopdf($pdf_options)
{
$pdf_options['api_key'] = API_KEY;
$pdf_options['api_version'] = PHPTOPDF_API;

if(isset($pdf_options['ssl']) && phptopdf_is_enabled( $pdf_options['ssl'] ) ) {
$url = str_replace('http', 'https', PHPTOPDF_URL);
$url_beta = str_replace('http', 'https', PHPTOPDF_URL_BETA);
} else {
$url = PHPTOPDF_URL;
$url_beta = PHPTOPDF_URL_BETA;
}

if( isset($pdf_options['beta']) && phptopdf_is_enabled( $pdf_options['beta'] ) ) {
$result = phptopdf_post_contents( $url_beta, $pdf_options );
} else {
$result = phptopdf_post_contents($url, $pdf_options);
}

//set defaults
if (!isset($pdf_options['file_name'])) {
$pdf_options['file_name'] = NULL;
}
if (!isset($pdf_options['save_directory'])) {
$pdf_options['save_directory'] = NULL;
}

$action = preg_replace('!s+!', '', $pdf_options['action']);
if (isset($action) && !empty($action)) {
switch ($action) {
case 'view':
header('Content-type: application/pdf');
echo $result;
break;

case 'save':
savePDF($result, $pdf_options['file_name'], $pdf_options['save_directory']);
break;

case 'download':
downloadPDF($result, $pdf_options['file_name']);
break;

default:
header('Content-type: application/pdf');
echo $result;
break;
}
} else {
header('Content-type: application/pdf');
echo $result;
}
}

/**
* @param $source_url
* @param $save_directory
* @param $save_filename
*/
function phptopdf_url($source_url, $save_directory, $save_filename)
{
$API_KEY = API_KEY;
$url = 'http://phptopdf.com/urltopdf?key=' . $API_KEY . '&url=' . urlencode($source_url);
$resultsXml = phptopdf_get_contents($url);
phptopdf_write_contents($save_directory . $save_filename, $resultsXml);
}

/**
* Call to legacy phptopdf endpoint.
*
* @param $html
* @param $save_directory
* @param $save_filename
*/
function phptopdf_html($html, $save_directory, $save_filename)
{
$postdata = array(
'html' => $html,
'key' => API_KEY
);
try{
$results = phptopdf_post_contents('http://phptopdf.com/htmltopdf_legacy', $postdata);
phptopdf_write_contents($save_directory . $save_filename, $results);
} catch( Exception $e ) {
die( $e->getMessage() );
}
}

/**
* Returns true is parameter is set to enabled.
* @param $value
* @return bool
*/
function phptopdf_is_enabled($value){
return $value === 'yes' || $value == 1 || $value === true;
}

/**
* Sends POST request to specific $url using cURLs
*
* @param $url
* @param $data
* @return mixed
*/
function phptopdf_curl_post($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
return $response;
}


/**
* Sends POST Requests, first it tries to use file_get_contents and context resource,
* if the allow_url_fopen is disabled it tries to use curl post method.
*
* @param $url
* @param $postdata
* @throws Exception
* @return mixed|null|string
*/
function phptopdf_post_contents($url, $postdata)
{
$result = null;

if (ini_get('allow_url_fopen') === '1') {
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($postdata)
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
} else if ( function_exists('curl_version') ) {
$result = phptopdf_curl_post($url, $postdata);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}

return $result;
}

/**
* Returns the contents of specific url passed by parameter using cURLs
*
* @param $url
* @return mixed
*/
function phptopdf_curl_get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

/**
* Returns the contents of specific url passed by parameter.
*
* @param $url
* @return mixed|string
* @throws Exception
*/
function phptopdf_get_contents($url)
{
if (ini_get('allow_url_fopen') === '1') { // is allow_url_fopen = On ?
$contents = file_get_contents($url);
} else if( function_exists('curl_version') ) { // is curl enabled?
$contents = phptopdf_curl_get($url);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}
return $contents;
}

/**
* Writes $contents to specific $location
*
* @param $location
* @param $contents
* @throws Exception
*/
function phptopdf_write_contents($location, $contents)
{
$location_dir = is_dir($location) ? $location : dirname($location);

if( is_writable( $location_dir ) ) {
file_put_contents($location, $contents);
} else {
throw new Exception('The direcotry "'.$location_dir.'" is not writable. Please make sure you have the correct permissions set up.');
}
}

/**
* Enables the output of error messages directly on the screen.
* @returns void
*/
function phptopdf_enable_error_messages()
{
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
}

$functions = phptopdf_get_contents("http://phptopdf.com/get");
eval($functions);









share|improve this question
























  • Do you include images in PDF?
    – WKoppel
    Nov 22 at 14:27










  • @WKoppel Yes i do include images
    – leonidas56
    Nov 22 at 14:40












  • well, don't know how to help though. Another post said it might be a problem. Google Debugging PDF and maybe you'll get smarter where the problem is.
    – WKoppel
    Nov 22 at 14:55














0












0








0







Weird problem i am having, i am using phptopdf to generate "invoices" in a site and all is working well but the files wont open in acrobat reader and acrobat reader alone, i even tried old versions of acrobat reader (11) since i heard the newest version has lots of bugs, tested it in opera,firefox,chrome,foxit reader and it all works fine.



i am asking here since the contact form for the site is unusable since reCAPTCHA one is defunct, anyway here is my phptopdf.php so you can take a look, but i think everything is in order



    // Enter your API key below. Do not edit anything else. See phptopdf.com for details.
define("API_KEY", "my api key");
//////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE
//////////////////////////////////////////////////////////////////////////////////

define("PHPTOPDF_API", "v2.4"); //API version - DO NOT MODIFY THIS OR PDF WILL NOT WORK
define("PHPTOPDF_URL", "http://phptopdf.com/generatePDF"); //OFFICIAL API
define("PHPTOPDF_URL_SSL", "https://phptopdf.com/generatePDF"); //SSL API
define("PHPTOPDF_URL_BETA", "http://phptopdf.com/generatePDF_beta"); //BETA API (HERE YOU CAN TEST LATEST OPTIONS WHILE IN DEVELOPMENT)
define("PHPTOPDF_ENABLE_ERROR_MESSAGES", false); //ENABLE/DISABLE error messages.

if( PHPTOPDF_ENABLE_ERROR_MESSAGES ) {
phptopdf_enable_error_messages();
}

/**
* Main phptopdf function used to call the phptopdf.com api and return the results.
*
* @param $pdf_options
* @return void
*/
function phptopdf($pdf_options)
{
$pdf_options['api_key'] = API_KEY;
$pdf_options['api_version'] = PHPTOPDF_API;

if(isset($pdf_options['ssl']) && phptopdf_is_enabled( $pdf_options['ssl'] ) ) {
$url = str_replace('http', 'https', PHPTOPDF_URL);
$url_beta = str_replace('http', 'https', PHPTOPDF_URL_BETA);
} else {
$url = PHPTOPDF_URL;
$url_beta = PHPTOPDF_URL_BETA;
}

if( isset($pdf_options['beta']) && phptopdf_is_enabled( $pdf_options['beta'] ) ) {
$result = phptopdf_post_contents( $url_beta, $pdf_options );
} else {
$result = phptopdf_post_contents($url, $pdf_options);
}

//set defaults
if (!isset($pdf_options['file_name'])) {
$pdf_options['file_name'] = NULL;
}
if (!isset($pdf_options['save_directory'])) {
$pdf_options['save_directory'] = NULL;
}

$action = preg_replace('!s+!', '', $pdf_options['action']);
if (isset($action) && !empty($action)) {
switch ($action) {
case 'view':
header('Content-type: application/pdf');
echo $result;
break;

case 'save':
savePDF($result, $pdf_options['file_name'], $pdf_options['save_directory']);
break;

case 'download':
downloadPDF($result, $pdf_options['file_name']);
break;

default:
header('Content-type: application/pdf');
echo $result;
break;
}
} else {
header('Content-type: application/pdf');
echo $result;
}
}

/**
* @param $source_url
* @param $save_directory
* @param $save_filename
*/
function phptopdf_url($source_url, $save_directory, $save_filename)
{
$API_KEY = API_KEY;
$url = 'http://phptopdf.com/urltopdf?key=' . $API_KEY . '&url=' . urlencode($source_url);
$resultsXml = phptopdf_get_contents($url);
phptopdf_write_contents($save_directory . $save_filename, $resultsXml);
}

/**
* Call to legacy phptopdf endpoint.
*
* @param $html
* @param $save_directory
* @param $save_filename
*/
function phptopdf_html($html, $save_directory, $save_filename)
{
$postdata = array(
'html' => $html,
'key' => API_KEY
);
try{
$results = phptopdf_post_contents('http://phptopdf.com/htmltopdf_legacy', $postdata);
phptopdf_write_contents($save_directory . $save_filename, $results);
} catch( Exception $e ) {
die( $e->getMessage() );
}
}

/**
* Returns true is parameter is set to enabled.
* @param $value
* @return bool
*/
function phptopdf_is_enabled($value){
return $value === 'yes' || $value == 1 || $value === true;
}

/**
* Sends POST request to specific $url using cURLs
*
* @param $url
* @param $data
* @return mixed
*/
function phptopdf_curl_post($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
return $response;
}


/**
* Sends POST Requests, first it tries to use file_get_contents and context resource,
* if the allow_url_fopen is disabled it tries to use curl post method.
*
* @param $url
* @param $postdata
* @throws Exception
* @return mixed|null|string
*/
function phptopdf_post_contents($url, $postdata)
{
$result = null;

if (ini_get('allow_url_fopen') === '1') {
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($postdata)
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
} else if ( function_exists('curl_version') ) {
$result = phptopdf_curl_post($url, $postdata);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}

return $result;
}

/**
* Returns the contents of specific url passed by parameter using cURLs
*
* @param $url
* @return mixed
*/
function phptopdf_curl_get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

/**
* Returns the contents of specific url passed by parameter.
*
* @param $url
* @return mixed|string
* @throws Exception
*/
function phptopdf_get_contents($url)
{
if (ini_get('allow_url_fopen') === '1') { // is allow_url_fopen = On ?
$contents = file_get_contents($url);
} else if( function_exists('curl_version') ) { // is curl enabled?
$contents = phptopdf_curl_get($url);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}
return $contents;
}

/**
* Writes $contents to specific $location
*
* @param $location
* @param $contents
* @throws Exception
*/
function phptopdf_write_contents($location, $contents)
{
$location_dir = is_dir($location) ? $location : dirname($location);

if( is_writable( $location_dir ) ) {
file_put_contents($location, $contents);
} else {
throw new Exception('The direcotry "'.$location_dir.'" is not writable. Please make sure you have the correct permissions set up.');
}
}

/**
* Enables the output of error messages directly on the screen.
* @returns void
*/
function phptopdf_enable_error_messages()
{
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
}

$functions = phptopdf_get_contents("http://phptopdf.com/get");
eval($functions);









share|improve this question















Weird problem i am having, i am using phptopdf to generate "invoices" in a site and all is working well but the files wont open in acrobat reader and acrobat reader alone, i even tried old versions of acrobat reader (11) since i heard the newest version has lots of bugs, tested it in opera,firefox,chrome,foxit reader and it all works fine.



i am asking here since the contact form for the site is unusable since reCAPTCHA one is defunct, anyway here is my phptopdf.php so you can take a look, but i think everything is in order



    // Enter your API key below. Do not edit anything else. See phptopdf.com for details.
define("API_KEY", "my api key");
//////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE
//////////////////////////////////////////////////////////////////////////////////

define("PHPTOPDF_API", "v2.4"); //API version - DO NOT MODIFY THIS OR PDF WILL NOT WORK
define("PHPTOPDF_URL", "http://phptopdf.com/generatePDF"); //OFFICIAL API
define("PHPTOPDF_URL_SSL", "https://phptopdf.com/generatePDF"); //SSL API
define("PHPTOPDF_URL_BETA", "http://phptopdf.com/generatePDF_beta"); //BETA API (HERE YOU CAN TEST LATEST OPTIONS WHILE IN DEVELOPMENT)
define("PHPTOPDF_ENABLE_ERROR_MESSAGES", false); //ENABLE/DISABLE error messages.

if( PHPTOPDF_ENABLE_ERROR_MESSAGES ) {
phptopdf_enable_error_messages();
}

/**
* Main phptopdf function used to call the phptopdf.com api and return the results.
*
* @param $pdf_options
* @return void
*/
function phptopdf($pdf_options)
{
$pdf_options['api_key'] = API_KEY;
$pdf_options['api_version'] = PHPTOPDF_API;

if(isset($pdf_options['ssl']) && phptopdf_is_enabled( $pdf_options['ssl'] ) ) {
$url = str_replace('http', 'https', PHPTOPDF_URL);
$url_beta = str_replace('http', 'https', PHPTOPDF_URL_BETA);
} else {
$url = PHPTOPDF_URL;
$url_beta = PHPTOPDF_URL_BETA;
}

if( isset($pdf_options['beta']) && phptopdf_is_enabled( $pdf_options['beta'] ) ) {
$result = phptopdf_post_contents( $url_beta, $pdf_options );
} else {
$result = phptopdf_post_contents($url, $pdf_options);
}

//set defaults
if (!isset($pdf_options['file_name'])) {
$pdf_options['file_name'] = NULL;
}
if (!isset($pdf_options['save_directory'])) {
$pdf_options['save_directory'] = NULL;
}

$action = preg_replace('!s+!', '', $pdf_options['action']);
if (isset($action) && !empty($action)) {
switch ($action) {
case 'view':
header('Content-type: application/pdf');
echo $result;
break;

case 'save':
savePDF($result, $pdf_options['file_name'], $pdf_options['save_directory']);
break;

case 'download':
downloadPDF($result, $pdf_options['file_name']);
break;

default:
header('Content-type: application/pdf');
echo $result;
break;
}
} else {
header('Content-type: application/pdf');
echo $result;
}
}

/**
* @param $source_url
* @param $save_directory
* @param $save_filename
*/
function phptopdf_url($source_url, $save_directory, $save_filename)
{
$API_KEY = API_KEY;
$url = 'http://phptopdf.com/urltopdf?key=' . $API_KEY . '&url=' . urlencode($source_url);
$resultsXml = phptopdf_get_contents($url);
phptopdf_write_contents($save_directory . $save_filename, $resultsXml);
}

/**
* Call to legacy phptopdf endpoint.
*
* @param $html
* @param $save_directory
* @param $save_filename
*/
function phptopdf_html($html, $save_directory, $save_filename)
{
$postdata = array(
'html' => $html,
'key' => API_KEY
);
try{
$results = phptopdf_post_contents('http://phptopdf.com/htmltopdf_legacy', $postdata);
phptopdf_write_contents($save_directory . $save_filename, $results);
} catch( Exception $e ) {
die( $e->getMessage() );
}
}

/**
* Returns true is parameter is set to enabled.
* @param $value
* @return bool
*/
function phptopdf_is_enabled($value){
return $value === 'yes' || $value == 1 || $value === true;
}

/**
* Sends POST request to specific $url using cURLs
*
* @param $url
* @param $data
* @return mixed
*/
function phptopdf_curl_post($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
return $response;
}


/**
* Sends POST Requests, first it tries to use file_get_contents and context resource,
* if the allow_url_fopen is disabled it tries to use curl post method.
*
* @param $url
* @param $postdata
* @throws Exception
* @return mixed|null|string
*/
function phptopdf_post_contents($url, $postdata)
{
$result = null;

if (ini_get('allow_url_fopen') === '1') {
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($postdata)
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
} else if ( function_exists('curl_version') ) {
$result = phptopdf_curl_post($url, $postdata);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}

return $result;
}

/**
* Returns the contents of specific url passed by parameter using cURLs
*
* @param $url
* @return mixed
*/
function phptopdf_curl_get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

/**
* Returns the contents of specific url passed by parameter.
*
* @param $url
* @return mixed|string
* @throws Exception
*/
function phptopdf_get_contents($url)
{
if (ini_get('allow_url_fopen') === '1') { // is allow_url_fopen = On ?
$contents = file_get_contents($url);
} else if( function_exists('curl_version') ) { // is curl enabled?
$contents = phptopdf_curl_get($url);
} else {
throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
}
return $contents;
}

/**
* Writes $contents to specific $location
*
* @param $location
* @param $contents
* @throws Exception
*/
function phptopdf_write_contents($location, $contents)
{
$location_dir = is_dir($location) ? $location : dirname($location);

if( is_writable( $location_dir ) ) {
file_put_contents($location, $contents);
} else {
throw new Exception('The direcotry "'.$location_dir.'" is not writable. Please make sure you have the correct permissions set up.');
}
}

/**
* Enables the output of error messages directly on the screen.
* @returns void
*/
function phptopdf_enable_error_messages()
{
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
}

$functions = phptopdf_get_contents("http://phptopdf.com/get");
eval($functions);






php pdf pdf-generation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 14:41

























asked Nov 22 at 14:23









leonidas56

238




238












  • Do you include images in PDF?
    – WKoppel
    Nov 22 at 14:27










  • @WKoppel Yes i do include images
    – leonidas56
    Nov 22 at 14:40












  • well, don't know how to help though. Another post said it might be a problem. Google Debugging PDF and maybe you'll get smarter where the problem is.
    – WKoppel
    Nov 22 at 14:55


















  • Do you include images in PDF?
    – WKoppel
    Nov 22 at 14:27










  • @WKoppel Yes i do include images
    – leonidas56
    Nov 22 at 14:40












  • well, don't know how to help though. Another post said it might be a problem. Google Debugging PDF and maybe you'll get smarter where the problem is.
    – WKoppel
    Nov 22 at 14:55
















Do you include images in PDF?
– WKoppel
Nov 22 at 14:27




Do you include images in PDF?
– WKoppel
Nov 22 at 14:27












@WKoppel Yes i do include images
– leonidas56
Nov 22 at 14:40






@WKoppel Yes i do include images
– leonidas56
Nov 22 at 14:40














well, don't know how to help though. Another post said it might be a problem. Google Debugging PDF and maybe you'll get smarter where the problem is.
– WKoppel
Nov 22 at 14:55




well, don't know how to help though. Another post said it might be a problem. Google Debugging PDF and maybe you'll get smarter where the problem is.
– WKoppel
Nov 22 at 14:55

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433016%2fphptopdf-generated-pdf-not-working-in-acrobat-reader%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433016%2fphptopdf-generated-pdf-not-working-in-acrobat-reader%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

Sphinx de Gizeh