မဂၤလာပါ။ကၽြန္ေတာ္ကေတာ့ ေမာင္ရဲထက္ေအာင္ ျဖစ္ပါတယ္။
Spiceworks Myanmar company မွာ web developer အျဖစ္ဝင္ေရာက္လုပ္ကိုင္ေနပါတယ္။ဒီတစ္ပတ္မွာေတာ့ က်ြန္ေတ့ာ္အေနနဲ႕Zend Pdf ကို အသံုးျပဳေတာ့မယ္ဆိုရင္ သိထားသင့္တဲ့ code ေတြကိုေလ့လာထားသေလာက္႐ွင္းျပမွာျဖစ္ပါတယ္။
ဒီLINKမွာေလ့လာနိုင္ပါတယ္ခင္ဗ်။
https://devzone.zend.com/1064/zend_pdf-tutorial/
ပထမဆံုးအေနနဲ႔ pdf တစ္ခုတည္ေဆာက္လိုက္ပါမယ္။
new keyword ခံျပီး zend_pdf()ဆိုျပီးေရးေပးရပါမယ္။
Create a new PDF.
require_once 'Zend/Pdf.php';
$pdf = new Zend_Pdf();
ေနာက္ျပီးေတာ့ file လမ္းေျကာင္းေ႐ြျပီး file name သတ္မွတ္ေပးရပါမယ္။
Load PDF document from a file. $fileName = '/path/to/your/file.pdf'; $pdf = new Zend_Pdf($fileName);
fontေ႐ြးမယ္ဆို setFontဆိုျပီးfont name သတ္မွတ္ေပးရပါမယ္။
fontအမ်ိဳးအစားေတြအမ်ားႀကီးပါတယ္။ႀကိဳက္တဲ့fontကို ေ႐ြးခ်ယ္အသံုးျပဳနိုင္ပါတယ္။
$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 20);
- Zend_Pdf_Font::FONT_COURIER
- Zend_Pdf_Font::FONT_COURIER_BOLD
- Zend_Pdf_Font::FONT_COURIER_OBLIQUE (identical to Zend_Pdf_Font::FONT_COURIER_ITALIC)
- Zend_Pdf_Font::FONT_HELVETICA
- Zend_Pdf_Font::FONT_HELVETICA_OBLIQUE (identical to Zend_Pdf_Font::FONT_HELVETICA_ITALIC)
- Zend_Pdf_Font::FONT_HELVETICA_BOLD_OBLIQUE (identical to Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC)
- Zend_Pdf_Font::FONT_SYMBOL
- Zend_Pdf_Font::FONT_TIMES_ROMAN
- Zend_Pdf_Font::FONT_TIMES
- Zend_Pdf_Font::FONT_TIMES_BOLD
- Zend_Pdf_Font::FONT_TIMES_ITALIC
- Zend_Pdf_Font::FONT_ZAPFDINGBATS
documentေတြေရးေတာ့မယ္ဆိုရင္ေတာ့ drawText keywordကိုသံုးရပါမယ္။
You can write text pdf file as
$page->drawText('Hello world!', 600, 300);
imageေတြထည့္ခ်င္တယ္ဆိုရင္ေတာ့ imageWithPathဆိုၿပီး လမ္းေၾကာင္းေလးထည့္ေပးပါ။
pageရဲ႕WidthေတြHeightေတြသတ္မွတ္ခ်င္တယ္ဆိုရင္ေတာ႕ getHeight(),getWidth()နဲ႔ေရးေပးရပါမယ္။
$Image=Zend_Pdf_Image::imageWithPath('D:\xampp\htdocs\zend_pdf\public\img\chomp.jpg');
$pageHeight = $page->getHeight();
$pageWidth = $page->getWidth();
$imageHeight = 72;
$imageWidth = 72;
$topPos = $pageHeight - 16;
$leftPos = 400;
$bottomPos = $topPos - $imageHeight;
$rightPos = $leftPos + $imageWidth;
$page->drawImage($Image, $leftPos, $bottomPos,$rightPos, $topPos);
Document pages size သတ္မွတ္ခ်င္တယ္ဆိုရင္ new Zend_Pdf_Page ခံၿပီး Zend_Pdf_Page::SIZE_A4_LANDSCAPE ထည့္ေပးရပါမယ္။
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER); $pageHeight = $page->getHeight(); $pageWidth = $page->getWidth(); $pdf->pages[ ] = ($page);
- Zend_Pdf_Page::SIZE_A4
- Zend_Pdf_Page::SIZE_LETTER
- Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE
- Zend_Pdf_Page::SIZE_A4_LANDSCAPE
document ကို save မယ္ဆိုရင္ save keywordကိုအသံုးျပဳရပါမယ္။
pdf->save($fileName);
pdf file ကို browserမွာ ေပၚခ်င္တယ္ဆိုရင္ render keyword သံုးရပါမယ္။
$pdf->render( );
ကၽြန္ေတာ္သိသေလာက္ ေနာက္ထပ္လည္း ေလ့လာျဖစ္တာေလးေတြ Sharing လုပ္ေပးသြားပါ့မယ္ ခင္္ဗ်။
ဖတ္ရႈေပးတဲ့အတြက္လည္း အားလံုးကို ေက်းဇူးတင္ပါတယ္ ခင္ဗ်ာ။
