Convert from URL

Typeset.sh is unable to convert an URL into HTML, but it can be easily accomplished using PHP. When using relative paths in your HTML, ensure to set the appropriate base path for resolving those URLs.

// Make sure this is a trusted path!
$url = 'https://typeset.sh/samples/invoice.html';
$base = dirname($url);
$urlResolver = \Typesetsh\UriResolver::all(null, $base, [__DIR__.'/public']);

// Alternativly you could use \Typesetsh\Resource\Cache class as well for this.
$html = file_get_contents($url);

$result = \Typesetsh\createPdf($html, $urlResolver);
$result->toFile(__DIR__.'/invoice.pdf');

Last updated