I'm using this to output a pdf document :
$response = new \Symfony\Component\HttpFoundation\Response(file_get_contents($thefile), 200, [
'Content-Description' => 'File transfer',
'Content-Disposition' => 'filename="' . $filename . '"',
'Content-Transfer-Encoding' => 'binary',
'Content-Type' => 'application/pdf',
]);
unlink($thefile);
$response->send();
In the generated page, the header title is the link to the page.
How can I customize the title ?
You have to include the title inside the pdf.
I just have to generate the pdf from a script as src of an iframe !
This way the head title is kept !
<head>
<title>THE TITLE</title>
</head>
<body>
<iframe src="process.php"></iframe>
</body>
</html>
Or I could ajax the php script, and return the result in a container element (eg div)
Related
I am using DOMPDF version 2
i want to print Gujarati text in my pdf and gujarati font is displayed but it changed some text like "ટેસ્ટ ડેટા ચેક" is changed in pdf. not all character is changed but some merraged and special character is changed. I had tried multiple different gujarati fonts but same thing is happen in all.
<?php
use Dompdf\Dompdf;
require 'vendor/autoload.php';
$html = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
#font-face {
font-family: "notoSerifGujarati";
src:url(fonts/NotoSerifGujarati-VariableFont_wght.ttf)
}
.m {
font-family: "notoSerifGujarati";
}
</style>
</head>
<body>
<p class="m">
ટેસ્ટ ડેટા ચેક
</p>
</body>
</html>';
$tmp = sys_get_temp_dir();
$dompdf = new Dompdf([
'logOutputFile' => '',
// authorize DomPdf to download fonts and other Internet assets
'isRemoteEnabled' => true,
// all directories must exist and not end with /
'fontDir' => $tmp,
'fontCache' => $tmp,
'tempDir' => $tmp,
'chroot' => $tmp,
]);
$dompdf->loadHtml($html); //load an html
$dompdf->render();
$dompdf->stream('hello.pdf', [
'compress' => true,
'Attachment' => false,
]);
how text displayed in pdf
<?php
require_once __DIR__ . '/autoload.php';
$mpdf = new \Mpdf\Mpdf([
'PDFA' => true,
'PDFAauto' => true,
//'PDFAversion'=> 'A-3',
]);
$mpdf->SetAssociatedFiles([[
'name' => 'public_filename.xml',
'mime' => 'text/xml',
'description' => 'some description',
'AFRelationship' => 'Alternative',
'path' => __DIR__ . '/TaxInvoice.xml'
]]);
$rdf = '<rdf:Description rdf:about="" xmlns:zf="urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#">'."\n";
$rdf .= ' <zf:DocumentType>INVOICE</zf:DocumentType>'."\n";
$rdf .= ' <zf:DocumentFileName>ZUGFeRD-invoice.xml</zf:DocumentFileName>'."\n";
$rdf .= ' <zf:Version>1.0</zf:Version>'."\n";
$rdf .= ' <zf:ConformanceLevel>BASIC</zf:ConformanceLevel>'."\n";
$rdf .= '</rdf:Description>'."\n";
$mpdf->SetAdditionalXmpRdf($rdf);
$html = '
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
';
$mpdf->WriteHTML($html);
$mpdf->Output("mupdf.pdf","D");
erros from the validator
-ISO 19005-1:2005
Properties specified in XMP form shall use either the predefined schemas defined in XMP Specification, or extension schemas that comply with XMP Specification
-ISO 19005-1:2005
A file's name dictionary, as defined in PDF Reference 3.6.3, shall not contain the EmbeddedFiles key
-ISO 19005-1:2005
A file specification dictionary, as defined in PDF 3.10.2, shall not contain the EF key
I'm using PHP code to retrieve the content of .m3u8 with a Signed URL from AWS CloudFront.
I can't be able to play the chunk .ts files inside it since you need also to sign their URL.
So, using PHP code, I re-write the contents of .m3u8
<?php
$resourceKey = 'https://abcdefg.cloudfront.net/abcdef-1234.MOV_1000k*';
$expires = time() + 172800;
$customPolicy = <<<POLICY
{
"Statement": [
{
"Resource": "{$resourceKey}",
"Condition": {
"DateLessThan": {"AWS:EpochTime": {$expires}}
}
}
]
}
POLICY;
$signedUrl = $cloudFrontClient->getSignedUrl([
'url' => $resourceKey,
'policy' => $customPolicy,
'private_key' => public_path().'/pk-ABCDEFGHIJ.pem',
'key_pair_id' => 'ABCDEFGHIJ'
]);
$signedUrl = str_replace('*', '.m3u8', $signedUrl);
// get contents of the file and the query string
$content = file_get_contents($signedUrl);
parse_str(parse_url($signedUrl)['query'], $params);
$qs = "?Policy=".$params['Policy']."&Signature=".$params['Signature']."&Key-Pair-Id=".$params['Key-Pair-Id'];
// rewriting process
$replaceThis = array(".m3u8", ".ts");
$withThisValue = array(".m3u8".$qs, ".ts".$qs);
$content = str_replace($replaceThis, $withThisValue, $content);
?>
I was able to sign the .ts inside the .m3u8 file. But the problem now is that, how can I convert $content to something playable to HTML5 video with VideoJS without downloading the file contents using file_put_contents? I don't want to save it on the directory. Just to convert it on blob data or decode it and play it Something like this. Is this possible?
<!DOCTYPE html>
<html>
<head>
<title>My Site</title>
</head>
<body>
<video id='hls-example' class="video-js vjs-default-skin" width="640" height="480" controls>
<source src="<?php echo $content; ?>" type="application/x-mpegURL">
Your browser does not support the video tag.
</video>
<script src="https://vjs.zencdn.net/7.2.3/video.js"></script>
<script>
var player1 = videojs('hls-example');
</script>
</body>
</html>
PS: I tried AWS Lambda Edge. But, it doesn't work when there are many chunk .ts inside the m3u8 file. It returns an error that exceeds the Viewer Request Quota of 40KB.
My html to pdf conversion using wkhtmlpdf working fine without the <style> tag
but when I include the style tag it's not working that means not generating the pdf some one help me to solve this issue or let me know how to include my style.css in this format.
The way I handle this is as follows--
<?php
// create some HTML content
$html = '<!DOCTYPE html><html><head>
<style>
body {
margin: 0;
padding: 0;
}
...
</style></head><body>
<!-- Your body content -->
</body></html>';
$options = array(
"no-outline",
"binary" => "/usr/local/bin/wkhtmltopdf",
"margin-top" => ".25in",
"margin-right" => ".25in",
"margin-bottom" => ".55in",
"margin-left" => ".25in",
"zoom" => 1
);
$footer = '<!DOCTYPE html><html><head></head><body>...</body></html>';
$page_options = array('footer-html' => $footer);
$pdf->addPage($html, $page_options);
$pdf->saveAs('MY_PDF_NAME.pdf');
Hope this helps!
Best,
-Rush
I have searched for creating pdf file in symfony 2.3 but was not successful. I've got 2 bundle
Knp snapy bundle and another is
psliwa / PHPPdf
My task is just download pdf file on click. For this I have given the link in html.twig like
Download file
In pdf action I am generating the PDF file
In knp snapy bundle I am doing:
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
'some' => $vars
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
And got error
The exit status code '1' says something went wrong: stderr: "The
system cannot find the path specified.
Is wkpdftohtml necessary for installation if YES then how can I install on sharing based hosting.
In psliwa / PHPdf I have read the example from:
psliwa/PdfBundle
psliwa/PHPPdf
and got
unable to find twig file
If I change the $format = $this->get('request')->get('_format'); to $format='pdf'; then it show simple html file.
Unable to understand what should I do for completion of task...
Yes. For Knp Snappy Bundle, wkhtmltopdf is required and you need to configure it properly in the config.yml
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf #path to wkhtmltopdf binary
options: []
This is an excerpt from a controller in a live shared host environment using psliwa/PHPPdf:
$facade = $this->get('ps_pdf.facade');
$response = new Response();
$this->render('ManaClientBundle:Contact:roster.html.twig', array(
'date' => $found['latestDate'],
'center' => $location,
'roster' => $found['contactSet'],
), $response);
$date = new \DateTime($found['latestDate']);
$filename = str_replace(' ', '', $location) . date_format($date, '_Ymd') . '.pdf';
$xml = $response->getContent();
$stylesheet = $this->renderView('ManaClientBundle:Contact:contact.xml.twig', array());
$content = $facade->render($xml, $stylesheet);
return new Response($content, 200, array
('content-type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename=' . $filename
));