Page 1 of 1

onlinepdfprinter

Posted: Thu May 28, 2009 3:08 pm
by nina
Hi
I am new in PHP and know maybe 1% only, but i am trying to make it work anyhow.
I am using joomla for my website anf i am using a component names EventList.
I am trying to generate PDF from daily events. So because i dont have any knowledge in PHP i am trying to get it through http://www.onlinepdfprinter.com

I am tryng to follow their step with some help from support to write the code, but still it is not working.

This is the Code what i got now, Am i doing something wrong?

Thanks for ur help everybody!


Code: Select all

function do_post_request($url, $data)  {
 
        $data     = array("options" => base64_encode(json_encode($data)));
        $ch       = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_PORT, "8888");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $response = curl_exec($ch);
    return $response;
 
    } // end do_post_request()
 
  function force_pdf_download($stream, $filename_to_save_as = "output.pdf") {
   
    if ($stream && (substr($stream, 0, 5) == "%PDF-")) {
   
      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Content-Length: ".strlen($stream));
      header("Content-Type: application/pdf");
      header("Content-Transfer-Encoding: binary");
      header("Content-Disposition: attachment; filename=\"${filename_to_save_as}\"");
   
      echo $stream;
   
    } // end if
   
  } // end force_pdf_download()
 
    function onlinepdfgenerator() {
 
        $url  = "http://www.onlinepdfprinter.com";
        $rows = & $this->get('Data');
 
        //echo $rows;
        //print_r($rows);
 
    $data = array(); // DATA TO SEND TO PDF PRINTER
 
    foreach ($rows as $row) {
 
      if (($row->times >= "06:00:00") && ($row->times < "09:00:00")) {
 
        $section = "morgen";
 
      } else if (($row->times >= "09:00:00") && ($row->times <= "12:00:00")) {
 
        $section = "vormittag";
 
      } else if (($row->times >= "12:00:00") && ($row->times <= "15:00:00")) {
 
        $section = "mittag";
 
      } else if (($row->times >= "15:00:00") && ($row->times <= "18:00:00")) {
 
        $section = "nachmittag";
 
      } else {
 
        $section = "abend";
 
      } // end if
 
      switch ($row->catname)    {
 
        case "Ausstellungen":
          $variable = "aust_${section}";
          break;
 
          case "Besichtigungen":
          $variable = "besi_${section}";
          break;
 
          case "Bildung":
          $variable = "bild_${section}";
          break;
 
          case "Brunch & Breakfast":
          $variable = "brun_${section}";
          break;
 
          case "Charity":
          $variable = "char_${section}";
          break;
 
          case "Familienfeste":
          $variable = "fami_${section}";
          break;
 
          case "Flohmärkte":
          $variable = "floh_${section}";
          break;
 
          case "Freizeitparks":
          $variable = "frei_${section}";
          break;
 
          case "Gartenfestivals":
          $variable = "gart_${section}";
          break;
 
          case "Gesundheit":
          $variable = "gart_${section}";
          break;
 
          case "Kinderwelten":
          $variable = "kind_${section}";
          break;
 
          case "Kirmes, Rummel":
          $variable = "kirm_${section}";
          break;
 
          case "Konzerte und Gesang":
          $variable = "konz_${section}";
          break;
 
          case "Märkte":
          $variable = "mark_${section}";
          break;
 
          case "Messen":
          $variable = "mess_${section}";
          break;
 
          case "Musik & Theater":
          $variable = "musi_${section}";
          break;
 
          case "Offene Türen":
          $variable = "aust_${section}";
          break;
 
          case "Saisonales":
          $variable = "sais_${section}";
          break;
 
          case "Sonstige":
          $variable = "sons_${section}";
          break;
 
          case "Special-Events":
          $variable = "spec_${section}";
          break;
 
          case "Sportveranstaltungen":
          $variable = "spor_${section}";
          break;
 
          case "Tagestipps":
          $variable = "tage_${section}";
          break;
 
      } // end switch
 
      $data["static_data"][$variable] .= "{$row->title} - {$row->datdescription}\n";
 
    } // end foreach
 
    $options = array("template"      => "test3.doc",
                     "api_key"       => "pRaDS-Iq9TS-4GUkN",
                     "static_data"   => $data["static_data"],
                     "rows_per_page" => 1,
               );
 
    //var_export($options);
    //exit;
 
    $pdf_data = $this->do_post_request($url, $options);
 
    $filename = "category_eventlist." . strftime("%Y-%m-%d", time()) . ".pdf";
 
    ob_clean();
 
    $this->force_pdf_download($pdf_data, $filename);
 
    exit;
 
    } // end onlinepdfgenerator()
 
 

Re: onlinepdfprinter

Posted: Thu May 28, 2009 3:16 pm
by anand

Re: onlinepdfprinter

Posted: Fri May 29, 2009 9:49 am
by nina
Yes thanks i checked it. But actually onlinepdfprinter does it automaticly, only my code is wrong i guess.
I made a template with variables like in their exampla, but the data is not comin on it.


Regards