I am using pdfcrowd to convert php file into pdf but it converts blank pdf. What may be the issue? Do pdfcrowd convert php file?
Code is here
<?php
require 'pdfcrowd.php';
try
{
$client = new Pdfcrowd("nabinashahi", "2ef55554fe4c2d23b52b8e080cac867g");// create an API client instance
// $pdf = $client->convertURI('http://www.google.com/');
$pdf = $client->convertFile("C:/xampp/htdocs/pdf/page.php");// convert a web page and store the generated PDF into a $pdf variable
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: no-cache");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"google_com.pdf\"");
echo $pdf;// send the generated PDF
}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}
?>
I believe the problem is that you are not converting the output generated by your php file, but the actual php file itself. pdfCrowd is able to convert HTML into pdf - I don't think they handle php source code that well, and I don't think thats what you want to do :-)
Related
I'm using the PHP library FPDF to generate PDFs on my website.
It works GREAT on all devices EXCEPT Mac. It saves a .html file instead of .pdf.
Even iPhones work perfectly.
Here is my code:
<?php
require('includes/fpdf/fpdf.php');
class PDF extends FPDF {}
$mypdf = new FPDF();
// Content of PDF begins
// [...]
// Content of PDF ends
$file = utf8_decode('test.pdf');
$mypdf->Output('F', 'includes/exports/'.$file);
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"". basename($file) ."\"");
readfile('includes/exports/'.$file);
exit(); ?>
Thank you for your help!
The only way to achieve it is by storing the PDF and showing a download link to the user. Good workaround
I run PDF file through localhost in php there is a option in browser of printing the PDF and I dont want it to be print.
Here is my code:
header('Content-type: application/pdf');
readfile('The C# 4.0 complete reference.pdf');
die();
kindly help me
try this code
<?php
header("Content-type:application/pdf");
// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");
// The PDF source is in original.pdf
readfile("original.pdf");
?>
Actually I want to convert html into word(.doc). I am using the following code to convert html to word
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; Filename=SaveAsWordDoc.doc");
But This code is requesting force download in client system. How can i write the file in server as Word DoCument. Please Help me to resolve my problem.
In my program I want to add a download option to download the currently straming video. I tried this code:
$psp = "Tom_20_amp__20Jerry_20race-1.flv";
header("Content-type:application/octet-stream");
header("Content-Disposition:attachment;filename=$psp");
But I get this error:
"C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\Tom_20_amp__20Jerry_20race-1-5.flv" is not a valid FLV file.
the video streaming properly. please guide me
Change you're header from :
header("Content-type:application/octet-stream");
To :
header("Content-type: video/flv");
Then you can do :
header("Content-Disposition:attachment;filename=\"$psp\"");
//allways a good idea to let the browser know how much data to expect
header("Content-length: " . filesize($psp) . "\n\n");
echo file_get_contents($psp); //$psp should contain the full path to the video
If you are looking to allow files to be downloaded instead of streamed then something like this should work. You will obviously need to change the paths.
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="download.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
EDIT
In your case it will be something like this.
// We'll be outputting a video
header('Content-type: video/flv');
// It will be called video.flv
header('Content-Disposition: attachment; filename="video.flv"');
// The PDF source is in original.flv
readfile('original.flv');
I am creating an xml file on the fly. When a user generates this file I want it to open up a download file dialog with the content that was generated. There is no actual file because it is just generated through php. Any ideas on how to do this?
This is what worked for me. In readfile('newfile.xml'); make sure to give the path of the file correctly. This php page is called from an html page with anchor tag which says - download:
<?php
header('Content-disposition: attachment; filename="newfile.xml"');
header('Content-type: "text/xml"; charset="utf8"');
readfile('newfile.xml');
?>
source: How do I force the browser to download a file to disk instead of playing or displaying it?
Send a content-disposition attachment header.
header('Content-disposition: attachment; filename=advertise.xml');
header ("Content-Type:text/xml");
//output the XML data
echo $xml;
// if you want to directly download then set expires time
header("Expires: 0");