Just another WordPress.com weblog

Archive for the ‘Uncategorized’ Category

How to generate html to pdf using tcpdf?

To generate pdf from html using tcpdf, follow the below steps:

Step1: Download tcpdf library from below link
http://sourceforge.net/projects/tcpdf/files/

Step2: Add tcpdf folder in your project at path :: Your_project/lib/tcpdf

Step3: Create html file at any place you wants.. Than create one function in model file.. to generate pdf like below:


public function generatePdf($couponIds)
{
$filename = " HERE PATH OF HTML FILE WILL COME" ; //EG: Mage::getBaseDir().'/app/locale/en_US/template/email/coupon.html' this will return file coupon.html
$logoImage = Mage::getBaseDir().'/skin/frontend/default/default/images/logo_pdf.jpg'; //logo image path
$ptemplate = file_get_contents($filename);
$couponFindReplace = array(
'##LOGO_IMAGE##' =>$logoImage ,
'##FOOTER_TEXT_IMAGE##' =>$footertextImage
}
//Above array is to change content dynamically.
$after_replace = strtr($ptemplate, $couponFindReplace);
$pdf_html = $after_replace;
require_once(Mage::getBaseDir().'/lib/tcpdf/config/lang/eng.php');
require_once(Mage::getBaseDir().'/lib/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('PDF Title');
$pdf->SetAuthor('Author');
$pdf->SetKeywords('PDF','tcpdf','html');
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$lg = Array();
$lg['a_meta_charset'] = 'UTF-8';
$lg['a_meta_dir'] = 'ltr';
$lg['a_meta_language'] = 'en';
$lg['w_page'] = 'page';
$pdf->SetFont('times','',20); //set font of pdf and default font size is 20
//set some language-dependent strings
$pdf->setLanguageArray($lg);

// add a page
$pdf->AddPage();
$pdf->writeHTML($coupon_pdf_html, true, 0, true, true);
//$pdf->Output('test.pdf','D'); //this will create pdf and download at a time..
/*START:: To create pdf at particular location in server*/
$file_name = 'test.pdf';
$file_name_path = Mage::getBaseDir().'/media/coupons/'.'test.pdf';
if(file_exists($file_name_path))
{
unlink($file_name_path);
}
$pdf->Output($file_name_path,'F');
@chmod($file_name_path, 0777);
/*END:: To create pdf at particular location in server*/
return $file_name;
}

above function will generate pdf

The above are the steps to create simple pdf..

If the above code is helpful to you than do reply….

Thanks,
Bijal Bhavsar:)

Advertisements

2010 in review

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Fresher than ever.

Crunchy numbers

Featured image

A helper monkey made this abstract painting, inspired by your stats.

A Boeing 747-400 passenger jet can hold 416 passengers. This blog was viewed about 6,800 times in 2010. That’s about 16 full 747s.

In 2010, there were 31 new posts, growing the total archive of this blog to 69 posts. There were 2 pictures uploaded, taking up a total of 16kb.

The busiest day of the year was July 20th with 96 views. The most popular post that day was Products not showing in category view in magento 1.4.0.1.

Where did they come from?

The top referring sites in 2010 were magentocommerce.com, google.co.in, mysillypointofview.wordpress.com, magentocookbook.wordpress.com, and en.search.wordpress.com.

Some visitors came searching, mostly for magento getsession, how to set session in magento, magento get session, magento jointable, and magento-community/riconeitzel_vertnav.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

Products not showing in category view in magento 1.4.0.1 June 2010
4 comments

2

How to write simple Query in magento ? April 2010
1 Like on WordPress.com,

3

How to set session and get session in magento September 2009

4

Magento : Get Current Category – Category Id June 2010
1 comment

5

Fatal error: Call to a member function toOptionArray() on a non-object October 2010

Magento Basics

UPS shipping method for xml is not working-solved

if UPS shipping method for XML is not working then try this

open file :: app\code\core\Mage\Usa\Model\Shipping\Carrier\Ups.php
on line number 639
code is :: if (in_array($code, $allowedMethods)) {

if you remove this condition the UPS will work for your site.
here it shows every methods provided by UPS….

–VIshal Surani

Query to display just arrived product

$_parent_category = Mage::app()->getStore()->getRootCategoryId();
$storeId = Mage::app()->getStore()->getStoreId();

$_productCollection = Mage::getResourceModel(‘catalog/product_collection’)
->addAttributeToSelect(‘*’)
->setStoreId($storeId)
->addStoreFilter($storeId)
->addAttributeToFilter(‘status’,’1′)
->setOrder(‘created_at’, ‘desc limit 1’)
->load();

Query to display best selling product

$storeId = Mage::app()->getStore()->getId();

$products = Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘*’)
->addStoreFilter($storeId)
->setOrder(‘ordered_qty’, ‘desc’)
->load(); //best sellers on top

SQL to delete all orders

This query is very helpful to delete all records of orders from the database.

Please replace “YOUR_DB_NAME” with your database name

— Reset Magento TEST Data

SET FOREIGN_KEY_CHECKS=0;

— reset dashboard search queries
TRUNCATE `catalogsearch_query`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;

— reset sales order info
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;

— Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

— set appropriate prefixes for orders, invoices, shipments, credit memos
INSERT INTO  `YOUR_DB_NAME`.`eav_entity_store` (`entity_store_id` ,`entity_type_id` ,`store_id` ,`increment_prefix` ,`increment_last_id`) VALUES (‘1′,  ’11’,  ‘1’,  ‘1’,  ‘000000000’);
update `eav_entity_store` set `increment_prefix`= 1 where `entity_type_id`=’4′ and `store_id`=’1′;
update `eav_entity_store` set `increment_last_id`= ‘000000000’ where `entity_type_id`=’4′ and `store_id`=’1′;

INSERT INTO  `YOUR_DB_NAME`.`eav_entity_store` (`entity_store_id` ,`entity_type_id` ,`store_id` ,`increment_prefix` ,`increment_last_id`) VALUES (‘2′,  ’16’,  ‘1’,  ‘2’,  ‘000000000’);
update `eav_entity_store` set `increment_prefix`= 2 where `entity_type_id`=’18’ and `store_id`=’1′;
update `eav_entity_store` set `increment_last_id`= ‘000000000’ where `entity_type_id`=’18’ and `store_id`=’1′;

INSERT INTO  `YOUR_DB_NAME`.`eav_entity_store` (`entity_store_id` ,`entity_type_id` ,`store_id` ,`increment_prefix` ,`increment_last_id`) VALUES (‘3′,  ’19’,  ‘1’,  ‘3’,  ‘000000000’);
update `eav_entity_store` set `increment_prefix`= 3 where `entity_type_id`=’24’ and `store_id`=’1′;
update `eav_entity_store` set `increment_last_id`= ‘000000000’ where `entity_type_id`=’24’ and `store_id`=’1′;

INSERT INTO  `YOUR_DB_NAME`.`eav_entity_store` (`entity_store_id` ,`entity_type_id` ,`store_id` ,`increment_prefix` ,`increment_last_id`) VALUES (‘4′,  ’23’,  ‘1’,  ‘4’,  ‘000000000’);
update `eav_entity_store` set `increment_prefix`= 4 where `entity_type_id`=’28’ and `store_id`=’1′;
update `eav_entity_store` set `increment_last_id`= ‘000000000’ where `entity_type_id`=’28’ and `store_id`=’1′;

If this post is helpful to you than please do write feedback.

– Bijal Bhavsar