Пример #1
0
 private function getContents($pdf_file)
 {
     $this->locked = true;
     // echo $file;
     $info = new Pdf($pdf_file);
     $pdf = new Base($pdf_file, array('singlePage' => true, 'noFrames' => false));
     $pages = $info->getPages();
     // print_r($pages);
     // print_r($pages);
     $random_dir = uniqid();
     $outputDir = Config::get('pdftohtml.output', dirname(__FILE__) . '/../output/' . $random_dir);
     if (!file_exists($outputDir)) {
         mkdir($outputDir, 0777, true);
     }
     $pdf->setOutputDirectory($outputDir);
     $pdf->generate();
     $fileinfo = pathinfo($pdf_file);
     $base_path = $pdf->outputDir . '/' . $fileinfo['filename'];
     $contents = array();
     for ($i = 1; $i <= $pages; $i++) {
         $content = file_get_contents($base_path . '-' . $i . '.html');
         if ($this->inlineCss()) {
             // $content = str_replace(array('<!--','-->'),'',$content);
             $parser = new Emogrifier($content);
             // print_r($parser);
             $content = $parser->emogrify();
         }
         file_put_contents($base_path . '-' . $i . '.html', $content);
         $contents[$i] = file_get_contents($base_path . '-' . $i . '.html');
     }
     $this->contents = $contents;
     $this->goToPage(1);
 }
Пример #2
0
 public function testInfoConfiguration()
 {
     $pdf = new Pdf(dirname(__FILE__) . '/source/test.pdf');
     $this->assertEquals('/usr/bin/pdfinfo', $pdf->bin());
     Config::set('pdfinfo.bin', '/usr/local/bin/pdfinfo');
     $this->assertEquals('/usr/local/bin/pdfinfo', $pdf->bin());
     Config::set('pdfinfo.bin', '/usr/bin/pdfinfo');
 }
Пример #3
0
 public function testChangePage()
 {
     $file = dirname(__FILE__) . '/source/test.pdf';
     $pdf = new Pdf($file);
     $html = $pdf->html();
     // echo count($html->find('body'));
     // print_r($html);
     $this->assertEquals(1, $html->getCurrentPage());
     $html->goToPage(1);
     $this->assertEquals(1, $html->getCurrentPage());
     $this->assertArrayHasKey('pages', $pdf->getInfo());
 }
Пример #4
0
 public function import(Destination $dest, $month, $year)
 {
     $url = 'http://www.machupicchu.gob.pe/rpt//DisponibilidadPorMes.cfm?idLugar=' . $dest->getId() . '&mes=' . $month . '&ano=' . $year;
     $fn = __DIR__ . '/d.pdf';
     $return = true;
     file_put_contents($fn, file_get_contents($url));
     $pdf = new Pdf($fn);
     $paragraphs = $pdf->html()->find('p.ft03');
     $ret = array();
     $curr = 0;
     foreach ($paragraphs as $i => $p) {
         if ($i == 0) {
             continue;
         }
         if ($i % 2 != 0) {
             $curr = $p->text();
         } else {
             $ret[$curr] = $p->text();
         }
     }
     if (empty($ret)) {
         $return = false;
         $date = Carbon::createFromDate($year, $month, 1);
         $lastDayofMonth = $date->format('t') + 1;
         $ret = array();
         for ($i = 1; $i < $lastDayofMonth; $i++) {
             $ret[$i] = 0;
         }
     }
     echo '<pre>';
     var_dump($ret);
     foreach ($ret as $day => $availability) {
         $date = Carbon::createFromDate($year, $month, $day);
         $e = $this->getContainer()->get('doctrine')->getRepository('AppBundle:TourDate')->findOneBy(array('date' => $date, 'destination' => $dest));
         if (empty($e)) {
             $e = new TourDate();
             $e->setDestination($dest);
             $e->setDate($date);
         }
         $e->setAvailability($availability);
         $this->getContainer()->get('doctrine')->getEntityManager()->persist($e);
         $this->getContainer()->get('doctrine')->getEntityManager()->flush();
     }
     return $return;
 }