I was download and setup script from:http://www.html2pdf.fr/en
It works fine with default encoding, but when I try to generate docs with characters in CP-1251, I got white spaces instead of characters.
Also All my files in CP-1251,data in base in CP-1251 and as you can see I use simple font -Arial
Please, maybe exist some solution to get it to work.
P/s sorry for my english
ob_start();
include(dirname(__FILE__).'/res/exemple00.php');
$content = ob_get_clean();
require_once(dirname(__FILE__).'/../html2pdf.class.php');
try
{
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$content1=$html2pdf->Output('', 'S');
// Some php code
$db->query("set names cp1251");
$query="SELECT data from files Where id=$file_id ";
$result=$db->query($query);
$row=$result->fetch_assoc();
$content=($row['data']);
header('Content-Type: application/pdf');
header("Content-Length: ".strlen(content));
header('Content-Disposition: attachment; filename=Invoice#'.$invoice_id.'.pdf');
print $content;
}
catch(HTML2PDF_exception $e) { echo $e; } enter code here
I am not using this library, but are you setting your encoding in the HTML2PDF constructor?
$html2pdf = new HTML2PDF('P','A4','fr', true, 'CP-1251');
If it does not work, try 'cp1251' or 'CP1251', I do not find list of recognized encodings in the documentation. You can also use iconv and convert to UTF-8 as it seems to be a default.
Related
I have a php file that has data coming from the database called Casino-review.php
I just want to copy the php generated output data from this file to a new html file. I have tried lots of other thinks like OB functions, File contents functions, Copy functions, Fopen functions but, nothing work for me. Everthing is working properly creating file copying content but it's showing php code in it. Please help me.
here is the Output.
here is my code
$fileName = $title.".html";
$to = "casinos/all/".$fileName;
$from = "casinos/casino-review.php";
$newcontent = file_get_contents("$from");
if ($createFile = fopen($to, "w+")) {
fread($createFile, filesize($from));
fwrite($createFile, $newcontent);
fclose($createFile);
// echo "Wait for 5 seconds";
// setcookie("file", json_encode($casinoDetails), time() + 7400);
// header("REFRESH: 5;profile/$username/profile.php");
// echo "good";
}
I have finally found my answer
ob_start();
include("$from");
file_put_contents($to, ob_get_contents());
ob_end_clean();
Thanks #Innovin
I'm requesting an image from graph.facebook.com
The response header uses "content-type: image/jpeg" and prompts me to download instead of displaying it in the browser.
Is there a way (using PHP) to "intercept" the download and convert it to an image format?
Cheers.
UPDATE:
This kind of works. It returns the image to the browser (visible in Chrome's Network tab), but I'm not sure how to display it in an <img> tag:
<?php
$data = file_get_contents("https://www.petmd.com/sites/default/files/what-does-it-mean-when-cat-wags-tail.jpg");
// $data = base64_decode($data);
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
$qwe = imagepng($im);
imagedestroy($im);
return $qwe;
}
else {
echo 'An error occurred.';
}
?>
You code is invalid. You do not use return from non function as it makes no sense. If your case you need to replace
return $qwe;
with just plain
echo $qwe;
I'd also follow it by instant die(); and remove closing ?>. That should be all you need to make it work.
Not sure what is the point of fetching JPEG file but outputting PNG thought. You are gaining nothing but wasting time and resources, so the whole conversion code is pretty useless and echoing what you just downloaded should be perfecly sufficient:
header('Content-Type: image/jpeg');
$data = file_get_contents(".....");
if ($data !== false) {
echo $data;
}
die();
PS: As a homework, get rid of using file_get_contets() for network access and use cURL, esp. the network wrapper the former uses can be disabled.
I am trying to generate an .ods document using PHP Excel.
Below is the code i am using :
public function init() {
$this->objPHPExcel = new PHPExcel();
}
public function indexAction(){
$iexpertsMapper = new Application_Model_IExpertsMapper();
$response = $iexpertsMapper->getAllIExpertsPaymentDues();
$this->objPHPExcel->getProperties()->setCreator("D")
->setLastModifiedBy("D")
->setTitle("D")
->setSubject("D")
->setDescription("D")
->setKeywords("D")
->setCategory("D");
// Headers
$this->objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'H')
->setCellValue('B1', strtotime("today"))
->setCellValue('C1', 'CTPL');
// Redirect output to a client’s web browser (OpenDocument)
header('Content-Type: application/vnd.oasis.opendocument.spreadsheet');
header('Content-Disposition: attachment;filename=bank.ods');
$objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'OpenDocument');
ob_end_clean();
$objWriter->save('php://output');
exit;
}
Whenever i hit the code from the browser, an ods document is downloaded with gibberish text. I tried various things including adding ob_end_clean(); in my code. But nothing seems to work. Following text appears in my ODS document : �QĿi!��K�y3�J<���Z1�0?Y�L%zV.
This is what i see when i open the document :
For better or worse, I am storing binary information in a database table and am having a problem retrieving it. Each BLOB has a newline prepended to it upon retrieval, at least, I believe it's upon retrieval, as the binary object in the table is exactly the same size as the source file.
I've searched for a similar problem to mine, and the closest I have found is this However, I am using PDO instead of mysql_* and I have checked for empty lines prior to the opening
Here's the retrieval function stored in a separate file that I'm including in my test:
(in raw.php):
function return_raw_rawid($raw_id) {
$data = array();
$aggregate_data = array();
$sql = "SELECT * FROM `raw` WHERE `raw_id` = :rawid";
try {
$db_obj = dbCore::getInstance();
$query = $db_obj->dbh->prepare($sql);
$query->bindValue(':rawid', $raw_id);
if ($query->execute()) {
while($results = $query->fetch(PDO::FETCH_ASSOC)) {
$data['raw_id'] = $results['raw_id'];
$data['filename'] = $results['filename'];
$data['mime_type'] = $results['mime_type'];
$data['file_size'] = $results['file_size'];
$data['file_data'] = $results['file_data'];
$data['test_id'] = $results['test_id'];
$data['user_id'] = $results['user_id'];
$data['time'] = date('Y-m-d H:i:s', $results['time']);
$aggregate_data[] = $data;
} // while
} // if
$query->closeCursor();
return $aggregate_data;
} catch (PDOException $ex) {
$errors[] = $ex;
} // catch
}
Here's the code I'm testing it with in a separate file:
<?php
include 'core/init.php'; // Contains protect_page() and includes for return_raw_rawid
protect_page();
$blob_id = 20;
$blob = return_raw_rawid($blob_id);
$data = ltrim($blob[0]['file_data']);
$name = ltrim($blob[0]['filename']);
$size = ltrim($blob[0]['file_size']);
$type = ltrim($blob[0]['mime_type']);
header("Content-type: $type");
header("Content-length: $size");
header("Content-disposition: attachment; filename=$name");
header("Content-Description: PHP Generated Data");
echo $data;
When I load this page in my browser, it will prompt me to download the file identified by blob_id and has the correct filename and type. However, upon downloading it and opening in ghex, I see that the first byte is '0A' Using cmp original_file downloaded_file I determine that the only difference is this first byte. Googling led me to the ltrim() function that I've (perhaps too) liberally applied above.
I can't tell for sure if this problem is not being caused during upload, though as I said before, I don't believe it is since the "file_size" value in phpmyadmin is exactly the same as the source file. I'm not sure if the use of the aggregate_data array in the retrieval function could be to blame or what.
Any help is greatly appreciated!
Are you sure those 4 header lines are being properly executed? 0x0A is the newline char. You could have a newline in your core/init.php triggering output, and the headers are never executed. With display_errors/error_reporting off, you'd never see the warnings about "headers not sent - output started at line X...".
http://sourceforge.net/projects/phpqrcode/, is a great library but i can't find how to return the png image as a string, the basic examples are
QRcode::png('code data text', 'filename.png'); // creates file
QRcode::png('some othertext 1234'); // creates code image and outputs it directly into browser
i checked the documentation and nothing, help! :B
ob_start();
QRCode::png('text', null);
$imageString = base64_encode( ob_get_contents() );
ob_end_clean();
$qrTempDir = 'path/to/your/temp';
$filePath = $qrTempDir.'/'.uniqid();
QRcode::png('some text', $filePath);
$qrImage = file_get_contents($filePath);
unlink($filePath);
This should be what you're looking for. You can extend it to show an image like that:
<img src="data:image/png;base64,<?php echo base64_encode($qrImage) ?>" />
Unfortunately, the library does not support any other method at the moment, because calling the QRcode::png function without the file parameter not only makes it send those headers, but it also exits the code execution, so there is no retracting or overwriting the headers.
I ran into the same problem as #iim.hlk
This is what i did slightly modified #Lusitanian his answer to this
ob_start();
QRCode::png($string);
$imageString = base64_encode( ob_get_clean() );
header('Content-Type: text/html');
This fixes the header issue by simply overwriting it. Not clean or anything but it works for the purpose.
this works for me
include '../phpqrcode/qrlib.php';
$content = "any content";
ob_start();
QRcode::png($content);
$result_qr_content_in_png = ob_get_contents();
ob_end_clean();
// PHPQRCode change the content-type into image/png... we change it again into html
header("Content-type: text/html");
$result_qr_content_in_base64 = base64_encode($result_qr_content_in_png);
then in your html file
<img src="data:image/jpeg;base64,$result_qr_content_in_base64'"/>