How to create a pdf of product list

Hello,

i wanted to ask for guide on how to create a pdf of product list and download.

Try: Setup -> Modules -> Products -> Max number of products in combos select lists (0=no limit)

Show list of products.

Then Print from Browser.

Set it back to former value afterwards.

Best regards

@casati,

Please how do i print from browser. also when i set it to 0 the combo list it does not save the value.

Secondly, i had my way around generating pdf from product list but one last thing illudes me. I can generate full product list but i cannot generate pdf of only results from a particular category: THis is my code below;

<?php ob_start(); require('fpdf/fpdf.php'); require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; if (! empty($conf-\>categorie-\>enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $htmlother=new FormOther($db); $form=new Form($db); $textColour = array( 0, 0, 0 ); $headerColour = array( 100, 100, 100 ); $tableHeaderTopTextColour = array( 255, 255, 255 ); $tableHeaderTopFillColour = array( 125, 152, 179 ); $tableHeaderTopProductTextColour = array( 0, 0, 0 ); $tableHeaderTopProductFillColour = array( 143, 173, 204 ); $tableHeaderLeftTextColour = array( 99, 42, 57 ); $tableHeaderLeftFillColour = array( 184, 207, 229 ); $tableBorderColour = array( 50, 50, 50 ); $tableRowFillColour = array( 213, 170, 170 ); $chartXPos = 20; $chartYPos = 250; $chartWidth = 160; $chartHeight = 80; $chartXLabel = "Product"; $chartYLabel = "2009 Sales"; $chartYStep = 20000; $chartColours = array( array( 255, 100, 100 ), array( 100, 255, 100 ), array( 100, 100, 255 ), array( 255, 255, 100 ), ); $data = array( array( 9940, 10100, 9490, 11730 ), array( 19310, 21140, 20560, 22590 ), array( 25110, 26260, 25210, 28370 ), array( 27650, 24550, 30040, 31980 ), ); if (! empty($conf-\>categorie-\>enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $limit = GETPOST("limit")?GETPOST("limit","int"):$conf-\>liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); // Initialize technical object to manage hooks of thirdparties. Note that conf-\>hooks_modules contains array array $hookmanager-\>initHooks(array($contextpage)); $object = new Product($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels = $extrafields-\>fetch_name_optionals_label('product'); $search_array_options=$extrafields-\>getOptionalsFromPost($extralabels,'','search_'); $arrayfields=array( 'p.ref'=\>array('label'=\>$langs-\>trans("Ref"), 'checked'=\>1), //'pfp.ref_fourn'=\>array('label'=\>$langs-\>trans("RefSupplier"), 'checked'=\>1, 'enabled'=\>(! empty($conf-\>barcode-\>enabled))), 'p.label'=\>array('label'=\>$langs-\>trans("Label"), 'checked'=\>1), 'p.barcode'=\>array('label'=\>$langs-\>trans("Gencod"), 'checked'=\>($contextpage != 'servicelist'), 'enabled'=\>(! empty($conf-\>barcode-\>enabled))), 'p.duration'=\>array('label'=\>$langs-\>trans("Duration"), 'checked'=\>($contextpage != 'productlist'), 'enabled'=\>(! empty($conf-\>service-\>enabled))), 'p.sellprice'=\>array('label'=\>$titlesellprice, 'checked'=\>1, 'enabled'=\>empty($conf-\>global-\>PRODUIT_MULTIPRICES)), 'p.minbuyprice'=\>array('label'=\>$langs-\>trans("BuyingPriceMinShort"), 'checked'=\>1, 'enabled'=\>(! empty($user-\>rights-\>fournisseur-\>lire))), 'p.desiredstock'=\>array('label'=\>$langs-\>trans("DesiredStock"), 'checked'=\>1, 'enabled'=\>(! empty($conf-\>stock-\>enabled) && $user-\>rights-\>stock-\>lire && $contextpage != 'service')), 'p.tobatch'=\>array('label'=\>$langs-\>trans("ManageLotSerial"), 'checked'=\>0, 'enabled'=\>(! empty($conf-\>productbatch-\>enabled))), 'p.stock'=\>array('label'=\>$langs-\>trans("PhysicalStock"), 'checked'=\>1, 'enabled'=\>(! empty($conf-\>stock-\>enabled) && $user-\>rights-\>stock-\>lire && $contextpage != 'service')), 'p.accountancy_code_sell'=\>array('label'=\>$langs-\>trans("ProductAccountancySellCode"), 'checked'=\>0), 'p.accountancy_code_buy'=\>array('label'=\>$langs-\>trans("ProductAccountancyBuyCode"), 'checked'=\>0), 'p.datec'=\>array('label'=\>$langs-\>trans("DateCreation"), 'checked'=\>0, 'position'=\>500), 'p.tms'=\>array('label'=\>$langs-\>trans("DateModificationShort"), 'checked'=\>0, 'position'=\>500), 'p.tosell'=\>array('label'=\>$langs-\>trans("Status").' ('.$langs-\>trans("Sell").')', 'checked'=\>1, 'position'=\>1000), 'p.tobuy'=\>array('label'=\>$langs-\>trans("Status").' ('.$langs-\>trans("Purchases").')', 'checked'=\>1, 'position'=\>1000) ); $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,'; $sql.= ' p.fk_product_type, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,'; $sql.= ' p.tobatch, p.accountancy_code_sell, p.accountancy_code_buy,'; $sql.= ' p.datec as date_creation, p.tms as date_update,'; //$sql.= ' pfp.ref_fourn as ref_supplier, '; $sql.= ' MIN(pfp.unitprice) as minsellprice'; // Add fields from extrafields foreach ($extrafields-\>attribute_label as $key =\> $val) $sql.=",ef.".$key.' as options_'.$key; // Add fields from hooks $parameters=array(); $reshook=$hookmanager-\>executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager-\>resPrint; $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p'; if (is_array($extrafields-\>attribute_label) && count($extrafields-\>attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)"; if (! empty($search_categ) || ! empty($catid)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; // multilang if (! empty($conf-\>global-\>MAIN_MULTILANGS)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$langs-\>getDefaultLang() ."'"; $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall); // if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($type)) { if ($type == 1) $sql.= " AND p.fk_product_type = '1'"; else $sql.= " AND p.fk_product_type <\> '1'"; } if ($sref) $sql .= natural_search('p.ref', $sref); if ($snom) $sql .= natural_search('p.label', $snom); if ($sbarcode) $sql .= natural_search('p.barcode', $sbarcode); if (isset($tosell) && dol_strlen($tosell) \> 0 && $tosell!=-1) $sql.= " AND p.tosell = ".$db-\>escape($tosell); if (isset($tobuy) && dol_strlen($tobuy) \> 0 && $tobuy!=-1) $sql.= " AND p.tobuy = ".$db-\>escape($tobuy); if (dol_strlen($canvas) \> 0) $sql.= " AND p.canvas = '".$db-\>escape($canvas)."'"; if ($catid \> 0) $sql.= " AND cp.fk_categorie = ".$catid; if ($catid == -2) $sql.= " AND cp.fk_categorie IS NULL"; if ($search_categ \> 0) $sql.= " AND cp.fk_categorie = ".$db-\>escape($search_categ); if ($search_categ == -2) $sql.= " AND cp.fk_categorie IS NULL"; if ($fourn_id \> 0) $sql.= " AND pfp.fk_soc = ".$fourn_id; if ($search_tobatch != '' && $search_tobatch \>= 0) $sql.= " AND p.tobatch = ".$db-\>escape($search_tobatch); if ($search_accountancy_code_sell) $sql.= natural_search('p.accountancy_code_sell', $search_accountancy_code_sell); if ($search_accountancy_code_sell) $sql.= natural_search('p.accountancy_code_buy', $search_accountancy_code_buy); $parameters=array(); $reshook=$hookmanager-\>executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager-\>resPrint; $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,"; $sql.= " p.fk_product_type, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,"; $sql.= ' p.datec, p.tms'; // Add fields from extrafields foreach ($extrafields-\>attribute_label as $key =\> $val) $sql.=",ef.".$key; // Add fields from hooks $parameters=array(); $reshook=$hookmanager-\>executeHooks('printFieldSelect',$parameters); // Note that $action and $object may have been modified by hook $sql.=$hookmanager-\>resPrint; //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet $nbtotalofrecords = 0; if (empty($conf-\>global-\>MAIN_DISABLE_FULL_SCANLIST)) { $result = $db-\>query($sql); $nbtotalofrecords = $db-\>num_rows($result); } $pdf = new FPDF('P', 'mm', 'A4'); $pdf-\>SetTextColor( $textColour[0], $textColour[1], $textColour[2] ); $pdf-\>AddPage(); $pdf-\>SetFont('Arial','B',12); $pdf-\>Cell(0,10, "Demande D'approvissionement",1,0,C); $pdf-\>SetTextColor( $textColour[0], $textColour[1], $textColour[2] ); $pdf-\>SetFont( 'Arial', '', 12 ); $pdf-\>Write( 10, "Emmetteur De La Demande:" ); $pdf-\>Ln( 7 ); $pdf-\>SetFont( 'Arial', '', 12 ); $pdf-\>Write( 6, "Travaux Concernes:" ); $pdf-\>Ln( 7 ); $pdf-\>SetFont( 'Arial', '', 12 ); $pdf-\>Write( 6, "No de chassis:" ); $pdf-\>Ln( 7 ); $pdf-\>SetFont( 'Arial', '', 12 ); $pdf-\>Write( 6, "Client:" ); $pdf-\>Ln( 12 ); $pdf-\>SetFont( 'Arial', 'B', 12 ); // "PRODUCT" cell $pdf-\>SetTextColor( $tableHeaderTopProductTextColour[0], $tableHeaderTopProductTextColour[1], $tableHeaderTopProductTextColour[2] ); $pdf-\>SetFillColor( $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0] ); $pdf-\>Cell( 15, 12, " REF", 1, 0, 'C', true ); $pdf-\>SetTextColor( $tableHeaderTopProductTextColour[0], $tableHeaderTopProductTextColour[1], $tableHeaderTopProductTextColour[2] ); $pdf-\>SetFillColor( $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0] ); $pdf-\>Cell( 48, 12, " Designation fourniture", 1, 0, 'C', true ); $pdf-\>SetTextColor( $tableHeaderTopProductTextColour[0], $tableHeaderTopProductTextColour[1], $tableHeaderTopProductTextColour[2] ); $pdf-\>SetFillColor( $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0] ); $pdf-\>Cell( 20, 12, " Unité", 1, 0, 'C', true ); $pdf-\>SetTextColor( $tableHeaderTopProductTextColour[0], $tableHeaderTopProductTextColour[1], $tableHeaderTopProductTextColour[2] ); $pdf-\>SetFillColor( $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0] ); $pdf-\>Cell( 55, 12, " Qté en besoin", 1, 0, 'L', true ); $pdf-\>SetTextColor( $tableHeaderTopProductTextColour[0], $tableHeaderTopProductTextColour[1], $tableHeaderTopProductTextColour[2] ); $pdf-\>SetFillColor( $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[0] ); $pdf-\>Cell( 55, 12, " Fabrication Utiles", 1, 0, 'C', true ); $pdf-\>Ln( 12 ); $fill = false; $row = 0; $sql.= $db-\>order($sortfield,$sortorder); $sql.= $db-\>plimit($limit \+ 1, $offset); $resql = $db-\>query($sql); if ($resql) { $num = $db-\>num_rows($resql); $i = 0; $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form-\>multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields $product_static=new Product($db); $product_fourn =new ProductFournisseur($db); $var=true; while ($i < min($num,$limit)) { $objp = $db-\>fetch_object($resql); $pdf-\>SetFont( 'Arial', 'B', 10 ); $pdf-\>Cell( 15, 12, " " . $product_static-\>ref = $objp-\>ref, 1, 0, 'L', $fill ); $pdf-\>Cell( 48, 12, " " . dol_trunc($objp-\>label,40), 1, 0, 'L', $fill ); $pdf-\>Cell( 20, 12, " " . $objp-\>desiredstock, 1, 0, 'L', $fill ); foreach ($extrafields-\>attribute_label as $key =\> $val){ $tmpkey='options_'.$key; $pdf-\>Cell( 55, 12, " " .$extrafields-\>showOutputField($key, $objp-\>$tmpkey, '', 1), 1, 0, 'L', $fill ); } $i++; $pdf-\>Ln( 12 );} } // Simple table $pdf-\>Output('demande.pdf', D); ?\>