Zend PDF charset - croatian chartchters not suported - tried everything please HELP - zend-framework

Here is my code to create PDF document I cant see č ć ž š đ i tried importing .TTF file but can t import and use ttf properly please help
$pdf = new Zend_Pdf();
// Add new page to the document
$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
// Draw something on a page
// Set font
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER), 20);
///tried to import TTF not working
//$goodDogCoolFont = Zend_Pdf_Font::fontWithPath('dokumenti/cro.TTF');
//$page->setFont($goodDogCoolFont, 36);
// Draw text
#
$page->setFillColor(Zend_Pdf_Color_Html::color('#990000'));
$page->drawText('Račćšđžčun za apartman AID '.$this->ukupnacjena[1]['AID'] , 10, 800, 'Windows-1250');// UTF-8 Also doesnt work
pdfData = $pdf->render();
$filename = $this->ukupnacjena[1]['OD-DO'];
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="'.$filename.'.pdf"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
echo $pdfData;

I was facing similar issues with German Characters and found solution by replacing such characters[UMLAUTS in my situation] with its equivalent HTML Code like :
$str='German chars ü ä ö';
$str = html_entity_decode($str, ENT_COMPAT, "UTF-8");
$page->drawText($str, 115, 524,"UTF-8");
Will Print
German chars ü ä ö
May help you.....

I can see similar problems on this post. It i s actually a import problem.
Unicode characters not showing in Zend_Pdf?

Related

Html encode in perl excluding html tags

$encoded = encode_entities($input, '<>&"');
This will encode the <,>,&,".But how to exclude these things from the encoding??
There is an example in the documentation:
$encoded = encode_entities($input, '^\n\x20-\x25\x27-\x7e');

Perl split string at character entity reference

Quick Perl question with hopefully a simple answer. I'm trying to perform a split on a string containing non breaking spaces ( ). This is after reading in an html page using HTML::TreeBuilder::XPath and retrieving the string needed by $titleString = $tree->findvalue('/html/head/title')
use HTML::TreeBuilder::XPath;
$tree = HTML::TreeBuilder::XPath->new;
$tree->parse_file( "filename" );
$titleString = $tree->findvalue('/html/head/title');
print "$titleString\n";
Pasted below is the original string and below that the string that gets printed:
Mr Dan Perkins (Active)
Mr?Dan Perkins?(Active)
I've tried splitting $titleString with #parts = split('\?',$titleString); and also with the original nbsp, though neither have worked. My hunch is that there's a simple piece of encoding code to be added somewhere?
HTML code:
<html>
<head>
<title>Dan Perkins (Active)</title>
</head>
</html>
You shouldn't have to know how the text in the document is encoded. As such, findvalue returns an actual non-breaking space (U+00A0) when the document contains . As such, you'd use
split(/\xA0/, $title_string)
-or-
split(/\x{00A0}/, $title_string)
-or-
split(/\N{U+00A0}/, $title_string)
-or-
split(/\N{NBSP}/, $title_string)
-or-
split(/\N{NO-BREAK SPACE}/, $title_string)

How to decode an email attachment received as a Base64 text

I have an email backup file which is purely text. How can I retrieve the document (PDF, images, word files) attached to it as a normal file?
Select the long string of text which appears in your email. That is probably one of the attachments, it usually starts like this:
--bcaec554d754b0f76a04d9fda578--
--bcaec554d754b0f77204d9fda57a
Content-Type: application/pdf; name="test.pdf"
Content-Disposition: attachment; filename="Otest.pdf"
Content-Transfer-Encoding: base64
X-Attachment-Id: 9ba6310dffca527f_0.1
Copy this long string and paste it in the Base64 decoder found here.
Download the output and rename it by adding the appropriate extension to it. For example testfile.pdf or filename.docx.
There you go. You just recreated your lost attachment using Base64 decoding.
This is how to do it in PHP decode to a file
function base64_to_jpeg( $inputfile, $outputfile ) {
/* read data (binary) */
$ifp = fopen( $inputfile, "rb" );
$imageData = fread( $ifp, filesize( $inputfile ) );
fclose( $ifp );
/* encode & write data (binary) */
$ifp = fopen( $outputfile, "wb" );
fwrite( $ifp, base64_decode( $imageData ) );
fclose( $ifp );
/* return output filename */
return( $outputfile );
}
in HTML if you want to just display in web / using HTML
<img src="data:image/png;base64,Your_Base_64_Code_Here">
You can use For use as CSS background:
url('data:image/png;base64,Your_Base_64_Code_Here')

replace arabic charset with hashtag preg_replace?

I've made my own PHP script and my problem with hashtags
and I've added preg_replace function to replace tags to hashtags its working well when i use English charsets but in Arabic or any other language its not working
where is the problem in my code ?
$post = #preg_replace('/(^|\s)#(\w+)/', '<a class=\"hashtag\" href="hashtag.php?tag=\2">\1#\2</a>', $post);
i want preg_repalce to replace none english tags too how ?
i found it
this is how to match arabic hastags
$post = #preg_replace('/(#\w+)/u', '<a class="hashtag" href="hashtag.php?tag=\1">\1</a>', $post);

how to make QR codes in perl cgi

I'm trying to create a website with forms for people to fill out and when the user presses submit button the texts in each form field are concatenated into a single text string to be used to make a QR code. How could I do this and what language would be the best for most browsers to be compatible.
In addition, I would like to have the text fields have a new line (\n) associated with it to make the format a little more pretty when the user scans the QR code.
Please let me know.. Thanks in advance.. could you include a sample code of a website that has three text areas to concatenate?
The Imager::QRCode module makes this easy. I just knocked the following up in 5 minutes.
#!/Users/quentin/perl5/perlbrew/perls/perl-5.14.2/bin/perl
use v5.12;
use CGI; # This is a quick demo. I recommend Plack/PSGI for production.
use Imager::QRCode;
my $q = CGI->new;
my $text = $q->param('text');
if (defined $text) {
my $qrcode = Imager::QRCode->new(
size => 5,
margin => 5,
version => 1,
level => 'M',
casesensitive => 1,
lightcolor => Imager::Color->new(255, 255, 255),
darkcolor => Imager::Color->new(0, 0, 0),
);
my $img = $qrcode->plot($text);
print $q->header('image/gif');
$img->write(fh => \*STDOUT, type => 'gif')
or die $img->errstr;
} else {
print $q->header('text/html');
print <<END_HTML;
<!DOCTYPE html>
<meta charset="utf-8">
<title>QR me</title>
<h1>QR me</h1>
<form>
<div>
<label>
What text should be in the QR code?
<textarea name="text"></textarea>
</label>
<input type="submit">
</div>
</form>
END_HTML
}
How could I do this and what language would be the best for most browsers to be compatible.
If it runs on the server then you just need to make sure the output is compatible across browsers; so use GIF or PNG.
could you include a sample code of a website that has three text areas to concatenate?
Just use a . to concatenate string variables in Perl.
my $img = $qrcode->plot($foo . $bar . $baz);
Add binmode to display the image of the qr code, for example:
print $q->header('image/png');
binmode STDOUT;
$img->write(fh => \*STDOUT, type => 'png');