Example #1
0
 function generate_document()
 {
     $settings = Settings::get($this->user['database'])->toArray();
     if (!isset($_POST['link'])) {
         die;
     }
     $host = "http://" . $settings['aws_host_url'] . '/';
     if (substr($_POST['link'], 0, 5) == 'EZPRO') {
         $prefix = "EZPRO";
     } else {
         $prefix = "DTMS";
     }
     // Instantiate S3 Client
     $S3Client = S3Client::factory(array('key' => $settings['aws_access_key_id'], 'secret' => $settings['aws_secret_access_key']));
     switch ($prefix) {
         case "EZPRO":
             $year = substr($_POST['link'], 5, 4);
             $month = substr($_POST['link'], 9, 2);
             $search = "EZPRO" . $year . $month;
             $result = $S3Client->listObjects(array('Bucket' => $settings['aws_bucket'], 'MaxKeys' => 1, 'Prefix' => "EZPRO/POD/" . $year . "/" . $month . str_replace($search, '/', $_POST['link'])));
             break;
         default:
             $year = substr($_POST['link'], 5, 4);
             $month = substr($_POST['link'], 10, 2);
             $search = "DTMS_" . $year . "_" . $month . "_";
             $result = $S3Client->listObjects(array('Bucket' => $settings['aws_bucket'], 'MaxKeys' => 1, 'Prefix' => "DTMS/" . $year . "/" . $month . str_replace($search, '/', $_POST['link']) . "."));
             break;
     }
     if (isset($result['Contents'])) {
         $link = $host . $result['Contents'][0]['Key'];
     } else {
         die;
     }
     echo $link;
     $data = file_get_contents($link);
     $pdf = new PDFlib();
     $pdf->begin_document("", "");
     for ($frame = 1;; $frame++) {
         $pdf->create_pvf("/tracking/pvf/image", $data, "");
         $bol = $pdf->load_image("auto", "/tracking/pvf/image", "page=" . $frame);
         if ($bol == 0) {
             break;
         }
         $imagewidth = $pdf->get_value("imagewidth", $bol) * 72 / $pdf->get_value("resx", $bol);
         $imageheight = $pdf->get_value("imageheight", $bol) * 72 / $pdf->get_value("resy", $bol);
         $pdf->begin_page_ext($imagewidth, $imageheight, "");
         $pdf->fit_image($bol, 0, 0, "");
         $pdf->end_page_ext("");
         $pdf->delete_pvf("/tracking/pvf/image");
     }
     $pdf->end_document("");
     $buf = $pdf->get_buffer();
     print $buf;
 }