Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] PDF data-sheet maker v.1.1


alverman

Recommended Posts

By default the function ProductsDataSheet () - line 355, looks in "products_image" as defined in pdf_datasheet_config.php:

define('PDF_ALT_IMAGE', 'products_image');

which is the TABLE_PRODUCTS DB field that holds the image info.

I don't know Photo Gallery contrib, but should not affect the PDF image display as long as it does not alter that DB field.

 

ivan

Link to comment
Share on other sites

  • Replies 179
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

apodigm wrote:

What version of the GD library do you have installed? Or can you verify that you have it installed. I believe that it is required to make this work.

 

Sorry my ignorance but i don't know what u mean with the GD library, how can i know what version i have installed or even if i have it installed???

 

Is it correct to say that NONE of your images (in PDF) are working?

yes, none of my images are working.

 

 

Have you installed the PDF Catalog contribution? (It would be interesting if the images are in there but not the datasheets.)

 

i have download it but is says:

"The generations of the catalogs are done in the administration module.

To start generation click on 'Generate catalog(s)' in 'Tools' directory"

 

it generates the pdf from the admin section and clients dont have acces to this module, anyway i will have to install and try in case i cant make Data Sheet works.

Link to comment
Share on other sites

Actually John, the only PHP image related function used in the mod is

GetImageSize()

which does not require GD image library to be installed, the library is required to create and manipulate images (...I might be wrong :( ).

ivan

Link to comment
Share on other sites

oh yes... you are right. I guess I am confused with the PDF Catalog mod. It has tons of image commands in it. I went cross eyed the other day trying to find a way to jam gif support and I guess they all just jumbled together.

 

I've lost sight of what the original code had, but I remember seeing a hardcode 'images' directory somewhere. maybe it was this around line 432:

 

$imagepath=DIR_WS_IMAGES.$print_catalog_array['image'];

 

I changed something where there was 'images/ and repaced it with the osC link. I can't imagine any other mod changing the product database that would keep this PDF datasheet from working.

 

xaol,

If you aren't able to catch it, you might want to try echoing out different variables to the browser during the pdf render so that you can try and see where the problem is. Basically anywhere you have the image being displayed, echo the resulting variable to make sure that it has the path and image name correct. You will probably want to comment out the last "output" line so that you can just view the echo'd text.

 

good luck!

Link to comment
Share on other sites

I have found out why it didnt work!!!!

 

I will tell if u promise not to kill me

 

 

 

i dont know why but when i uploaded the images to the server, the jpg extension converted to JPG and that was the cause of the problem.

 

So, the contribution works perfectly, thanks everybody and in special to Ivan and apodigm.

 

see u guys!!!

Link to comment
Share on other sites

Hi Carlos,

I'm glad it works and I think this is interesting, I'll keep it in mind; I did not suppose that upper/lower case could affect it.

 

John if u are interested in looking further into this, take a look at http://www.fpdf.org/ home of the FPDF library on which the PDF datasheet is based.

As far as .gif support it seems like it is not quite easy to achieve, there're some threads on this topic at FPDF forums.

 

ivan

Link to comment
Share on other sites

I thought GIF was patented, which means all developers have to pay a licensing fee ?

 

Thats why people have gone towards .PNG (which also supports transparency and higher bit depths. )

 

?

Special Effects / 3d + Flash

Link to comment
Share on other sites

I do not know if it also a matter of patent, according to the FPDF guy you do not need to de-compress it. It is more a technical problem due to the format structure that makes it difficult to parse it and embedd the image into the PDF.

Link to comment
Share on other sites

Also with gifs horizontal bands compress well (Like a blue sky)

 

but vertical bands do not (say blue ot white left to right).

 

PNG has addressed this issue ( I think )

 

Sorry a bit off topic.

Special Effects / 3d + Flash

Link to comment
Share on other sites

  • 4 weeks later...

Hi and thanks for the great contrib.

 

only problem i have with it is that the date expected is not working.

All products, even those not available yet show the line:

This product was added to our database on ......

anybody know how to get the:

This product will be available on .......

working?

Link to comment
Share on other sites

........... only problem i have with it is that the date expected is not working.

All products, even those not available yet show the line:

This product was added to our database on ......

actually the function looks for $print_catalog_array['status'] != 0 I think it is better if

if ($print_catalog['products_date_available'] == 0){

          $date =  TEXT_DATE_ADDED. $print_catalog_array['date_added'];

                   }else{

                   $date =  TEXT_DATE_AVAILABLE. $print_catalog_array['date_available'];

                   }

I have just uploaded the pdf_datasheet_functions.php w/ the necessary corrections, it includes the last bug fix: option prices do not display tax.

http://www.oscommerce.com/community/contributions,1077

 

thanx for spotting the error.

ivan

Link to comment
Share on other sites

  • 3 weeks later...

Hello

 

I tried to use this wonderfull mod, but it resist to work...

I?m using 2.2MS1, IE6 and the last PDF Datasheet Maker available.

 

I install it as the install.txt says (easy) but y only get a IE page as this:

 

%PDF-1.3 3 0 obj <>>>] /Contents 4 0 R>> endobj 4 0 obj <> stream x??TMo1??W?c???~??? TE*?@B??Y72ڬ?ݤ????8 ???l6??@?0?dz?7o?X?Ո?L???96m=e9? t*?6??2??j[;??'?{) 9??+MF7???s?Кq?a???? dJ??s??q???TFfђC?????.??0)??????z?-?T???L>???Q = lߵ7tȔNW??!Ϙ?P?fi??+? $?Cb?6W* K2(%?蒕??5??9 ????*9q?!kǾ?L?=??}?wݵ ߬?p?M?n??4? ?n?7?q?v???%9q?:??j?sY??pp8>Ǘv??n???-????Ŏ?8??r? ??ֵ?,??="?qG?#??t?F.%??v?"aBw?????$?I;????d?e?1?A??? m??????0HB??Br E3 ??H?i(????fTƣ?c?K{Y????"cI?朥]?g????3 ????ɭ?I5-?? ??܈?*??.??YKe[??q*{~<?ob?JK??]Y??,????4???D????:S&??'*c????7ס?????-???!???P,??????????t??E0??oe??s????2΢H???"????????? W?er?n????OGW/q˷?B?????յe4?tp?wD??{?zR??t??>??=+?W?<????^?b?~(????=Q?ƎqHy????.&?tW?dcH???k??>{??B?|???ՙ?9?=1????o endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <> stream ????JFIF22??LEAD Technologies Inc. V1.01?ۄ 4"@.0&4LCPOKCIHT_yfTYr[HIi?jr}????Qe?????y???>"">?WIW????????????????????????????????????????????????????? }!1AQa"q2???#B??R??$3br? %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz??????????????????????????????????????

???????????????????????????????????w!1AQaq"2?B???? #3R?br? $4?%?&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz???????????????????????????????????????

??????????????????????????????????????? ???P@PP@?94??k?k????g'? ??П?QO/???E??H-؟n?o???z????c??p}?P=-bV4?i??h???B?F??????u??? ?????????Q??????G??#? j?̚?I??tϣ|?? ??l?P?@?P@-?P@%P@??~?O ??:U%P@P@P@P@P@P@f?h??] ?ه_????qLB?$`?I?(/F_?^7Y?!??ѥHa@@om???23 ????????k Y?? ? ( ?'??/2?E?=Oz݌??%???Y3???m ?Z?^??a?]e??-???L(? A_ZO?ko'????E?j9uk?_m??????Ӄ????/??Ay?m(?G?Q?T?2ZP@P@CZ???????a"?_ҋ?Q=?ֲ? I?a??R?Z???t?:????[(>?g ??@׽@?5 ?ֵo??????l|?מ??-?vO??]4?"˺P??nf?Ϩ?z4$???~???[s??????>T? ?????????7u?????P[??k??Q%Ì?v??S?E8lK????2?{??A?~?[l+???????Ɛ?e??????Y?? 4?VU???N?B{? 홡?^/_?=~??P?b??????Dw*3?ݐz??;Rj?E?C ( ? ( ??H???X??g?zC?/%??.P???j?#Z???V???u??r?04?}* ??]?nE???;'?? ?E7???>M'Wwg??????5Ԥ?????9???? ?F?q?;?=A5?*Eo%?ͧ?-;T??%???$C?`??V?S??djv?U?????[?????@>?=??y? ??wE?r?f0 n????a?p???=0)?[0-4?|????LF?q?????@??@?@?z??}?????)*???#???(͍???*????z?j?? ? ( ? (.??:??=????Kbz?? ? &???!????C?}M*??濕H?e???O.Y??O*?=R?I?$}??7?C????@??h??~??? ?9_`??$w P??D?:Vct_??q?M???XVVb???h|??????@?????}?3?i?R?s?????uKa2?K?*K@*?Y?u4ܿ?{?/f??LM{?ء?{?$ր'GISzg??) ZG*?du????? ?+??ddr??? ? I?????Ԍ0??O???????F???3?e?????? 2??_?????/???? /???}P????=@?e?2 ???? ?N:??N?Y??:K˳F 1;G?ө?Η.?]?PU?ˮ??9TD??#-??9??N}d? X????C";FСX??g}G ]?Ia?QӺ<ʛbmz?NMW??ʶ kr??+1???o?A곿?s?j?.ș]??zw )D?????C@?'$?IL? ~??@ @???m"?y?P?E???(J?tJ?m?F?0 ?08??J?"?@??fv???P???H'?ہ???@ ?g?#???$??/s???G̽?ˎ??a?u?E?Ԭ???s?i??!?*?&j?#2Bc? $);?u? ??4???????Ԍ7?????????P?z??? ?u ???(7??????? ޾??bxPE?5 ?be?^?? ??.DwF?h??r?S?0?7;?ʞ u?L?? ?ԭ?b? wy?#???( c?z ?"?.-??o5?????^=jF?rȀE)???q?M4?!????9<?8???;? 1^?"??????????ǰ? T???(??s??B????????F7owaq~?2?.O?>?r?? ??T?????Z|??&?e?IP?0?KVw$?0 ? ( ? ˿?]-??xi??e?K?/{?G?=??j@PP-B?n!e`pG8?=?Ӱi?M*????".??ه֔?T4˵# ( ? ??j???GR??lq??ޕp?????+?ڳ'??n???)? ????9???4?H?1???l??,?#EHr;q?݊??????%?{ ??o?7'??C?V?$??亖?*W,Yj????????(2c~r=A?*%M?u?+?h?R?fX??? @?ʀ(Z??mV{[vd???I?^5??r?L?ճ?M?Z?1???4S ɍ??z?8"?Pi_?Q?e??? ? ( ?*?f?#????}MTc}??Y?1?w1;?????Sw?*@Z`?)?R?dP]????4,????}T???0,??%?;?`v??}*?mX???? ( o]r?"???*Fd^??]4ըəU??""?GEP??sP??"5?c?Cw?[z:???Ῑ???} W??_?x??Z??0???pH?O?????????X?eep???6{g {V>?OaƢqNOrk}B??4S??N l?㊗ 'f???????????i?p??u8??+??$䬌!??~D??ڞ????Q?3?>s?A??o??'Q?s?(???n-P@Esq?-,? ?? i7?F? .. ??Ĭ0?y???֍?dK?5?B?j??@ @ @?c u*FA ??ym????A? ?>???????V???j]????=??*z??5?y} h$( ?1|Ae+Im?[?d?پtY3??_η?5g l??+Ļgk%???????b?~u??$?a??,e?i????Iʆ??Ӂ?Ɖ+$? 96?>?????A??%??5?d?b?????~_??????o$?????ä?z^???w}??r;?v8??1Q?#?z?o[??I.?=?2 4j 9??f?o *??? ?]?;uшn???????wg??N??kv?2z?~S??????5Ԩ?I????m???@ɦH#2H?QJ?b????Ion??

m?4???}??փ???c??jE?p)??Ri??P@ @ d???U?A ??䶗Ό??cч????%r??ӡf??g`???C???VjV|???~??D?b )??R???? c??MI? ?(??'??6m}=i]?]???"k(?kǰ? ?y?v?X???#?Nq??I??IɽˌT~IRV?%?&???C+ y?4????Ո!????4" ??P???U9?????????F??W?$?lc?q?????U{W??)??????Ab???5Z+ a@G4? ????d??D?gʵ}?ST??`??~Q?'???{??-k-??ue??K?EQ$??Sh?L??? ??qbAA??S?{}:┢??% l2+ҙY???p0G????2>??,??????;??(e ? 8?Ka?T@PP?@P@&?W`T??c?8l??????߇?*}????Eq ?y̔?<~??{ִ?ch?}?芊?LP?L ? ( ?? @? ??͍? 9 ?`Q{Y혼$?NI@?U?~?z?AKW? s?D?G_,?ߖ~??d??v?0?E0&)????Gg?-?P@P%?8Wt????qAqEio?b??(?A???1s7ЌAqw????0??????? ??Qؽ?Dwr????T2|Rh ? @P@PP@ ? PS?Cp??5a?(??^? ?䎂Q?F???4?&?@b?????G?8????B=?[h!Ԧ??T?M#t?A??E??5?zj??6?vt??R?B樺"Q?3???????|??_? ?Q'?TZ9E????H?UE???? ?٨?C???}??i??D?????֝?{?????$ܬc?f????9/???il{???1??G&??Rع ?0Q?Տ$?4 ??Z(i?P@P?PH? (?R ?? (?R}???? 0!:u?u????1@?lW???ي?-???C? .??P?( ??)?P@ @ ??? endstream endobj 2 0 obj <> /XObject << /I1 8 0 R >> >> endobj 9 0 obj << /Producer (FPDF 1.51) /CreationDate (D:20030526185633) >> endobj 10 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /XYZ null null 1] /PageLayout /OneColumn >> endobj xref 0 11 0000000000 65535 f 0000001058 00000 n 0000009008 00000 n 0000000009 00000 n 0000000230 00000 n 0000001145 00000 n 0000001246 00000 n 0000001342 00000 n 0000001446 00000 n 0000009141 00000 n 0000009217 00000 n trailer << /Size 11 /Root 10 0 R /Info 9 0 R >> startxref 9327 %%EOF

 

Acrobat reader doesn?t star (is properly installed) I tested the www.chilipepper.it/catalog page works fine with the same computer and browser.

 

I have tested with the Opera 7.11, misteriously it seems to work Ok but taking about 15-30 seconds to open Acrobat reader and post the PDF.

 

I try with mozilla 1.3.1, and works fine...

 

Any Idea? how to make it work with IE?

 

Please HELP ME!!! :cry:

Link to comment
Share on other sites

Hi Javier,

I get this result when, during development, I make some errors in the functions file; the output starts but gets blocked by the error, correcting it and clicking refresh the page loads just like yours; if you made a correct installation it shouldn't happen and the only reason I can think of is in FAQ n? 2 here.

FDPF is the library used in this mod.

Are you testing it locally ?

 

ivan

Link to comment
Share on other sites

Hi Alverman

 

Thanks for your support. I?m tested it locally and from internet, but same result, even with a diferent IE version. The more extrange thing is that in your example page (www.chilipepper.it/catalog) works fine in all computer I have tested...

 

I made the correct instalation several times (is very easy following your instructions) and I don?t know why with mozilla works fine...

 

Any idea? I?ll check the faq about FPDF...

Link to comment
Share on other sites

Hi Alverman

 

I have read the FAQ but unfortunately I don't found any solution there.

The IE error that is posted seems to be a bug and if you go to other site and then return all works... for me no.

 

How can I force the FPDF to create the file in the tmp directory and then send to the browser in a new window? is this posible? If you can/want please detail me all process as my php skills are very very low... :oops:

 

I thought that with this it may work... forcing to open a pdf file in a new window. Your opinion?

 

Thanks in advance..

Link to comment
Share on other sites

If you want to generate a PDF file and store it to a local directory first and then download it, you should really give a try to Catalog products PDF reports by Gurvan Riou, it works on the admin side and creates a downloadable catalog, then it explains how to put the new links and create the necessary pages.

 

At the bottom of the functions file (pdf_datasheet_functions.php in my contrib) the line :

$pdf->Output("",false);

has to be modified into something like:

$pdf->Output("../".DIR_WS_CATALOG."temp_dir/".$products_id.".pdf",false);

where the first parameter gives path and filename of the new PDF.

It should be easy to port the same method to the PDF-datasheet.

 

..... I?m tested it locally and from internet, but same result, even with a diferent IE version.
I would think it has to do w/ your localhost installation but I can only guess, I'm not an expert.
Link to comment
Share on other sites

Hi Alverman

 

It seems there is no solution for me... :cry: I really need your contribution working. I was thinking about if php version has any thing to do with this issue. I?m using the PHP4.3.1 the latest non beta available.

 

I have instaled the last update for Internet Explorer 6, and the same...

 

Please I need one solution. No body has the same problem?... bad luck for me...

If the explorer don?t understand the file as it receive, why not we force to open it as a new window?

 

I don?t know if it?s hard to do, or if it?s possible, due my nule php skills. :oops:

Link to comment
Share on other sites

Hi

 

Maybe I have found something that make it works :D . I put a script found in the fpdf.org faq, at the end of your pdf_datasheet_functions.php, erasing or coment this:

    // Prints content to browser

   // $pdf->Output("",false);

 

and adding this:

//Determine a temporary file name in the current directory

$file=basename(tempnam(getcwd(),'tmp'));

rename($file,$file.'.pdf');

$file.='.pdf';

//Save PDF to file

$pdf->Output($file);

//JavaScript redirection

echo "<HTML><SCRIPT>document.location='$file';</SCRIPT></HTML>";

exit;

?>

 

The result: Is working, :)

 

Now I want to learn how to make the pdf open in a new popup page when you click on the icon, as style of "click to enlarge" and how to put a coment behind the icon of the PDF file as "click icon to view printer friendly", can you tell me the code? :oops:

 

As you can see I?m a total newbie with this... but if I can help someone with this "small solution" :wink: here is!

Link to comment
Share on other sites

Hi Javier,

 

You did not check the other contribution did you?

Just a little consideration: are you going to run your cart always from your localhost or will you go live sometime? If you load your cart on another server probably all the problems will be solved (but I'm not aware of your intentions or maybe you own a production server).

The PDF-datasheet is a nice toy to play with but it should be your last concern in order to run an OSC shopping cart (just my opinion), a little suggestion is to learn some php first.

But this is not what you want to hear :D so:

 

1) replace

$pdf->Output("",false);

in the functions file w/

$pdf->Output("pdf/datasheets/".$products_id.".pdf",false);

 

2) create a folder named "datasheets" inside "catalog/pdf" folder (Chmod 777 if you are under Unix, that means the application can write to that directory)

 

3) change the PDF icon link to:

<?php echo '<a href="' . tep_href_link('pdf_info.php', 'products_id=' . $product_info['products_id']) .'" target="_self">' . tep_image('pdf_files/pdf.gif') .'</a>'; ?></td>

 

4) create a new php file and call it pdf_infp.php and place these lines of code inside (you can duplicate an existing one and replace the code)

<?php

 require('includes/application_top.php');

 require('pdf/pdf_datasheet_functions.php');

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PDF_DATASHEET);



 $location = ' » <a href="' . tep_href_link(FILENAME_SHIPPING, '', 'NONSSL') . '" class="headerNavigation">' . NAVBAR_TITLE . '</a>';

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<title><?php echo TITLE; ?></title>

<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

<link rel="stylesheet" type="text/css" href="stylesheet.css">



</head>

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

<!-- header //-->

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<!-- header_eof //-->



<!-- body //-->

<table border="0" width="100%" cellspacing="3" cellpadding="3">

 <tr>

   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?> " cellspacing="0" cellpadding="2">

<!-- left_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>

<!-- left_navigation_eof //-->

   </table></td>

<!-- body_text //-->

   <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">

     <tr>

       <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">

         <tr>

           <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>

         </tr>

       </table></td>

     </tr>

     <tr>

       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

     </tr>

     <tr>

       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">

         <tr>

           <td class="main">

<?php

$file = $products_id .'.pdf';

$size_pdf_file=filesize('pdf/datasheets/'. $file )/1024;

$formatted = sprintf('%0.2f Kb', $size_pdf_file);

echo '<br><a href=pdf/datasheets/'.$file.' target=_blank>Click to download '.$file.'</a> ('.$formatted.')';?>

           </td>

         </tr>

       </table></td>

     </tr>

     <tr>

       <td align="right" class="main"><br><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT, '', 'NONSSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>

     </tr>

   </table></td>

<!-- body_text_eof //-->

   <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- right_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>

<!-- right_navigation_eof //-->

   </table></td>

 </tr>

</table>

<!-- body_eof //-->



<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>

<!-- footer_eof //-->

<br>

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

what does this do:

the first click on the PDF icon (in product_infp.php) takes you to the new page pdf_info.php, this page generates and stores the PDF file in the "datasheets" dir by means of require('pdf/pdf_datasheet_functions.php'); on top of the page; then the link "Click to download ...." opens a new window loading the just created PDF file. In this page you can put some other infos, for instance how to get Acrobat and bla, bla..........

You can see that this is not a straight operation, but requires two clicks to obtain the PDF.

I did not try any solution to get to the point in just one click, also I think you could run into the same problem of wierd characters showing up.

The names I gave to folder and files are just my choice, you can change them to whatever you want, just make sure there is a corrispondence in the code inside pdf_info.php.

I hope the above infos are all correct and complete, try playing w/ them and if you find a better solution let me know.

Ivan

Link to comment
Share on other sites

An interesting highbrid would be a PDF which maintains some formatting options. (Keeping bold text bold, for example). FPDF.org has a class which does just this, but I'm having a rough time trying to integrate the two. Here's that thread:

http://www.fpdf.org/read.php?f=1&i=3492&t=3476#3492

And here's the URL for the class:

http://www.fpdf.org/download/html2pdf.zip

 

As this is my first foray into PDF generating, though, I'm hoping that this both apeals to others and that someone else knows their stuff well enough to make this a trivial task.

 

Drew

Ain't this OSC just fabulous?

Link to comment
Share on other sites

Hi Alverman

 

Thank you for your help!! :D

 

Fisrt of all, I'll keep on mind your suggestion for learn PHP :oops: . I'm learning with posts and file comparing to found solutions, I know that isn't the right way, but is sometimes the fastest, unfortunately I haven't much time to this (work), but I will try to learn perhaps this summer if I find any good (and easy) Php book in Spanish, any suggestion?

 

Second: I followed your contrib, thank you for your time to teach me. It works wonderfull!!. I don't know why, but this code is not working for me:

 

$pdf->Output("pdf/datasheets/".$products_id.".pdf",false);

 

I need to put it with the other that I found in FPDF.org

 

//Determine a temporary file name in the current directory 

$file=basename(tempnam(getcwd(),'tmp')); 

rename($file,$file.'.pdf'); 

$file.='.pdf'; 

//Save PDF to file 

$pdf->Output("pdf/datasheets/".$products_id.".pdf",false);

//JavaScript redirection 

//echo "<HTML><SCRIPT>document.location='$file';</SCRIPT></HTML>"; 

?>

comenting the javascript redirection. If use without this mod, for me only displays a blank empty page in explorer.

 

The only thing is that this create 2 pdf files, one in directory datasheets that is correct, and another one in catalog, that have 0 bytes. Is not a trouble because it works, but may be improved...

 

Thank you for all! :D

Link to comment
Share on other sites

Ok - I got frustrated enough with text formatting to get stubborn. I overhauled this with a combination of Ivan's code, the tutorials on FPDF.org and the html2pdf class which I posted on the last page.

 

This code will format the following correctly in PDF format:

<b><a><i><br><p><li><ol><ul><h4><h3><h2>

 

It also displays the store name as a logo/image and multiple product images (from Contribution "Additional Images 1b").

 

There may be bugs - please post back here if you find any. I'm not formally uploading it to the contrib yet as it could use further modifications (reducing DB queries and further OSC-ifying) as well as testing. For now, it's been tailored to my needs and could use some further abstractions. It should be useful out of the box, however, for anyone needing to convert HTML text-formatting in their PDF.

 

In any case, here's the changed pdf_datasheet_functions.php:

 

 

define('FPDF_FONTPATH','pdf/font/');



require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PDF_DATASHEET);

require('pdf/pdf_datasheet_config.php');

require('pdf/fpdf.php');





define('FPDF_FONTPATH','font/');

define('LEFT_MARGIN',5);

define('RIGHT_MARGIN',5);

define('TOP_MARGIN',80);

define('IMAGES_X_FROM_RIGHT',80);

define('IMAGES_X_FROM_LEFT',150);

define('IMAGES_WIDTH',50);

define('IMAGES_VERT_DISTANCE',50);

define('PAGE_FORMAT','Letter');



define('HOME_PAGE_URL','http://my.site.com');

define('LOGO','pdf/logo.png');



define('TEXT_SIZE',10);

define('INDENT_SIZE',5);

define('ALLOWABLE_TAGS','<b><a><i><br><p><li><ol><ul><h4><h3><h2>');



class PDF extends FPDF

{

var $B;

var $I;

var $U;

var $HREF;

var $current_indent = LEFT_MARGIN;



function PDF($orientation='P',$unit='mm',$format=PAGE_FORMAT) {

  //Call parent constructor

  $this->FPDF($orientation,$unit,$format);

  //Initialization

  $this->B=0;

  $this->I=0;

  $this->U=0;

  $this->HREF='';

}

 



 function Header() {

 global $products_id;

 global $languages_id;



 // Product Description Info

   $products_description_query = tep_db_query("SELECT products_name from " . TABLE_PRODUCTS_DESCRIPTION . " 

	 WHERE products_id = '" . $products_id . "' AND                              language_id = '" . $languages_id . "'");

     $products_description = tep_db_fetch_array($products_description_query);



 // Product Info

   $products_query = tep_db_query("select products_model from " . TABLE_PRODUCTS . " where

                              products_id = " . $products_id);

     $products = tep_db_fetch_array($products_query);

  

 // Product Category Info

 $cPath = '';

 $cat_count_sql = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'");

 $cat_count_data = tep_db_fetch_array($cat_count_sql);

 if ($cat_count_data['count'] == 1) {

    	 $categories = array();

      $cat_id_sql = tep_db_query("select categories_name from " . TABLE_PRODUCTS_TO_CATEGORIES . " pc,  " . TABLE_CATEGORIES_DESCRIPTION . " cd where

                                 pc.products_id = '" . $products_id . "' and

                                 cd.categories_id = pc.categories_id");

    	 $cat_id_data = tep_db_fetch_array($cat_id_sql);

      tep_get_parent_categories($categories, $cat_id_data['categories_id']);



	 $size = sizeof($categories)-1;

	 for ($i = $size; $i >= 0; $i--) {

   if ($cPath != '') $cPath .= ' > ';

  	 $parent_id_sql = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where

                                    categories_id = '" . $categories[$i] . "'");

   $parent_id_data = tep_db_fetch_array($parent_id_sql);

   $cPath .= $parent_id_data['categories_name'];

	 }

	 if ($cPath != '') $cPath .= ' >> ';

	 $cPath .= $cat_id_data['categories_name'];

  	 }

 

   

 $path = $cPath;

 $products_name = $products_description['products_name'];

 $products_model = $products['products_model'];

 $home_page = HOME_PAGE_URL;



 $this->SetLeftMargin(LEFT_MARGIN);

 $this->SetRightMargin(RIGHT_MARGIN);

 

 // Logo

 $this->Image(LOGO,LEFT_MARGIN,10,75,0,png,$home_page);



 $this->SetLineWidth(0);



 //Today's date

 $this->SetTextColor(0,0,0);

 $date = strftime(DATE_FORMAT_LONG);

 

 $this->SetFont('Arial','',9);

 $this->Cell(0,8,$date .'  ',0,1,'R');

 $this->Ln(1);

 $x=$this->GetX();

 $y=$this->GetY();

 $this->Line($x,$y,$this->w-$this->rMargin,$y);

 $this->Ln(0.5);

 //Keep Y position

 $this->y0=$this->GetY();

 $this->Ln(0);

 



 $this->SetFont('arial','I',8);

 $breadcrumb_color_table=explode(",",BREADCRUMB_COLOR_TABLE);

 $this->SetFillColor($breadcrumb_color_table[0], $breadcrumb_color_table[1], $breadcrumb_color_table[2]);

 $breadcrumb_text_color=explode(",",BREADCRUMB_COLOR_TEXT);

 $this->SetTextColor($breadcrumb_text_color[0], $breadcrumb_text_color[1], $breadcrumb_text_color[2]);

 $this->Cell(0,5,$path .' >> '. $products_name,0,0,'L',1);

 $this->Ln(5);

 

 $this->SetFont('arial','B',24);

 $product_name_color_table=explode(",",PRODUCT_NAME_COLOR_TABLE);

 $this->SetFillColor($product_name_color_table[0], $product_name_color_table[1], $product_name_color_table[2]);

 $this->MultiCell(0,12,$products_name ,0,'L',1);

 $this->Ln(1);

 

 $this->SetTextColor($title_text_color[0], $title_text_color[1], $title_text_color[2]);

 $this->SetFont('arial','',TEXT_SIZE);

 $this->Cell(0,5,"Model: " . $products_model);

 $this->Ln(9);





}



function Footer() {

 $this->SetLeftMargin(LEFT_MARGIN);

 $this->SetRightMargin(RIGHT_MARGIN);



 $this->SetY(-20);

 $footer_color_cell=explode(",",FOOTER_CELL_BG_COLOR);

 $this->SetFillColor($footer_color_cell[0], $footer_color_cell[1], $footer_color_cell[2]);

 $this->MultiCell(0,5,"",0,'L',1);

 $x=$this->GetX();

 $y=$this->GetY();

 $this->SetLineWidth(1);

 $this->Line($x,$y,$this->w-$this->rMargin,$y);

 $this->SetFont('Arial','',9);

 $this->Cell($w,9,PDF_TITLE .' - '. OWNER_EMAIL_ADDRESS .' - '. STORE_ADDRESS,0,0,'L','','mailto:'. OWNER_EMAIL_ADDRESS);

 $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'R');

}







 function ShowImages() {

 global $products_id;

 $vert = $this->GetY();



 $product_image_query = tep_db_query("SELECT products_image FROM " . TABLE_PRODUCTS . " WHERE products_id = " . $products_id);

 if ($product_image = tep_db_fetch_array($product_image_query)) {  

	 $this->Image(DIR_WS_IMAGES . $product_image['products_image'],IMAGES_X_FROM_LEFT,$vert,IMAGES_WIDTH);

	 $vert += IMAGES_VERT_DISTANCE;

 }



 // FROM ADDITIONAL IMAGES 1b CONTRIB

 $additional_images_array = array();

 $additional_images_query = tep_db_query("SELECT medium_images FROM " . TABLE_ADDITIONAL_IMAGES . " WHERE products_id = " . $products_id);

 if (tep_db_num_rows($additional_images_query)) {

	 while ($additional_images = tep_db_fetch_array($additional_images_query)) {

   array_push ($additional_images_array, DIR_WS_IMAGES . $additional_images['medium_images']);

	 }

 }

 for ($i=0;$i<count($additional_images_array);$i++){ 

	 $heightwidth=getimagesize($additional_images_array[$i]);

	 $factor = $heightwidth[0]/$heightwidth[1];

	 $imagewidth=$heightwidth[0];

	 $imageheight=$heightwidth[1];



	 $this->Image($additional_images_array[$i],IMAGES_X_FROM_LEFT,$vert,IMAGES_WIDTH);

	 $vert += IMAGES_VERT_DISTANCE;

 }

 // END ADDITIONAL IMAGES 1b CONTRIB

}



function ShowPrice() {

 global $products_id;

 global $currencies;

 // Product Info

 $product_info_query = tep_db_query("SELECT products_price, products_tax_class_id from " . TABLE_PRODUCTS . " WHERE products_status = 1 and products_id = " . $products_id );

 $product_info = tep_db_fetch_array($product_info_query);

   

 if ($new_price = tep_get_products_special_price($products_id)) {

	 $products_price = 'Normal Price: ' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . ' <b>Special Price' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</b>';

   } else {

     $products_price = "Price: ".$currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));

   }

 $this->Ln(5);

 $this->Write(12,$products_price);

}





function WriteHTML() {

 global $products_id;

 global $languages_id;

 $product_query = tep_db_query("Select products_description from " . 

	 TABLE_PRODUCTS_DESCRIPTION . " where products_id = " . $products_id ." and language_id = " . $languages_id);

 if ($product = tep_db_fetch_array($product_query)){

	 $html = $product['products_description'];

 }

 else {

	 $html="No Description Provided";  

 }



 $html = html_entity_decode(strip_tags($html,ALLOWABLE_TAGS));

  //HTML parser

  $html=str_replace("n",' ',$html);

  $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);

  global $current_indent;

  foreach($a as $i=>$e)

  {

    if($i%2==0)

    {

  	 //Text



  	 if($this->HREF)

      $this->PutLink($this->HREF,$e);

  	 else {

     $this->Write(5,$e);

  	 }

    }

    else

    {

  	 //Tag

  	 if($e{0}=='/')

     $this->CloseTag(strtoupper(substr($e,1)));

  	 else

  	 {

      //Extract attributes

      $a2=explode(' ',$e);

      $tag=strtoupper(array_shift($a2));

      $attr=array();

      foreach($a2 as $v)

        if(ereg('^([^=]*)=["']?([^"']*)["']?$',$v,$a3))

      	 $attr[strtoupper($a3[1])]=$a3[2];

     $this->OpenTag($tag,$attr);

  	 }

    }

  }

}



function OpenTag($tag,$attr)

{

  global $current_indent;



 $h1 = 22;

 $h2 = 18;

 $h3 = 16;

 $h4 = 14;

 $line_break = 5;



  //Opening tag

 $this->SetLeftMargin($current_indent + LEFT_MARGIN);

  if($tag=='B' or $tag=='I' or $tag=='U')

    $this->SetStyle($tag,true);

  else if($tag=='H1') {

    $this->SetStyle('B',true);

    $this->SetFontSize($h1);

    $this->Ln($line_break * 2);

	 }

  else if($tag=='H2') {

    $this->SetStyle('B',true);

    $this->SetFontSize($h2);

    $this->Ln($line_break * 2);

	 }

  else if($tag=='H3') {

    $this->SetStyle('B',true);

    $this->SetFontSize($h3);

    $this->Ln($line_break * 2);

  }

  else if($tag=='H4') {

    $this->SetStyle('B',true);

    $this->SetFontSize($h4);

    $this->Ln($line_break * 2);

  }

  else if($tag=='A')

    $this->HREF=$attr['HREF'];

  else if($tag=='BR')

    $this->Ln($line_break);

  else if($tag=='P')

    $this->Ln($line_break);

  else if($tag=='UL' or $tag=='OL') {

   $this->SetLeftMargin($current_indent + INDENT_SIZE);

	 $current_indent += INDENT_SIZE;

  }

  else if($tag=='LI') {

	 $this->Ln($line_break);

   $this->Write(5, chr(149) . " ");

  }

}



function CloseTag($tag)

{

 global $current_indent;

 $line_break = 5;



  //Closing tag

  if($tag=='B' or $tag=='I' or $tag=='U')

    $this->SetStyle($tag,false);

  else if($tag=='H1' or $tag=='H2' or $tag=='H3' or $tag=='H4') {

    $this->SetFontSize(TEXT_SIZE);

    $this->SetStyle('B',false);

    $this->Ln($line_break);

  }

  else if($tag=='A')

    $this->HREF='';

  else if($tag=='P')

    $this->Ln($line_break);

  else if($tag=='UL' or $tag=='OL') {

	 $this->SetLeftMargin($current_indent - INDENT_SIZE);

	 $current_indent -= INDENT_SIZE;

  }

  else if($tag=='LI')

   $this->Ln($line_break);

}



function SetStyle($tag,$enable)

{

  //Modify style and select corresponding font

  $this->$tag+=($enable ? 1 : -1);

  $style='';

  foreach(array('B','I','U') as $s)

    if($this->$s>0)

  	 $style.=$s;

   $this->SetFont('',$style);

}



function PutLink($URL,$txt)

{

  //Put a hyperlink

  $this->SetTextColor(0,0,255);

  $this->SetStyle('U',true);

  $this->Write(5,$txt,$URL);

  $this->SetStyle('U',false);

  $this->SetTextColor(0);

}

}





$pdf=new PDF();

$pdf->Open();

$pdf->SetAutoPageBreak(true, 35);

$pdf->AddPage();

$pdf->ShowImages();

$pdf->SetRightMargin(IMAGES_X_FROM_RIGHT);

$pdf->WriteHTML();

$pdf->SetLeftMargin(LEFT_MARGIN);



$pdf->ShowPrice();

$pdf->Output();

exit;

 

Drew

Ain't this OSC just fabulous?

Link to comment
Share on other sites

  • 2 weeks later...

When I select the pdf graphic, the following occurs:

 

1054 - Unknown column 'p.PDF_ALT_IMAGE' in 'field list'



select p.products_id, pd.products_name, pd.products_description, p.PDF_ALT_IMAGE, p.products_model, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.products_status, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, s.expires_date, m.manufacturers_name from products p left join manufacturers m on p.manufacturers_id = m.manufacturers_id, products_description pd left join specials s on p.products_id = s.products_id where p.products_id = '26' and p.products_id = pd.products_id and pd.language_id = '1'



[TEP STOP]

 

I've found reference to 'PDF_ALT_IMAGE' in 'pdf_datasheet_functions.php' but nowhere to define it?

 

What do I need to do?

 

Penge

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...