Created
April 3, 2021 09:43
-
-
Save gaffling/fd2a95ad9f1ca605a20910b36c45fe7e to your computer and use it in GitHub Desktop.
[URL2PDF] pdflayer.com API to generate a PDF from an URL #php #function #pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ---------------------------------------------------------------------------- */ | |
/* [URL2PDF] pdflayer.com API to generate a PDF from an URL #php #function #pdf */ | |
/* ---------------------------------------------------------------------------- */ | |
function url2pdf($url, $licensekey='a2ce7bfc1f9be9d8ca741365fc532ab2') { | |
// GET YOUR API ACCESS KEY - https://pdflayer.com/dashboard | |
ini_set('user_agent', 'Mozilla/5.0'); | |
$api = 'http://api.pdflayer.com/api/convert?access_key=' . $licensekey . '&document_url=' . $url; | |
$filename = str_replace('www.', '', pathinfo($url, PATHINFO_FILENAME) . '.pdf'); | |
if (!headers_sent()) { | |
header('Content-type: application/pdf'); | |
header('Content-Disposition: inline; filename="' . $filename . '"'); | |
header('Content-Transfer-Encoding: binary'); | |
#header('Content-Length: ' . filesize($file)); | |
header('Accept-Ranges: bytes'); | |
@readfile($api); | |
} else { | |
@copy($api, $filename); | |
return '<a href="'.$filename.'">'.$filename.'</a>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment