当使用html2ps API显示pdf时,图像显示为空白

问题描述:

我正在使用pdf创建脚本,我正尝试使用html2ps API创建我的pdf。我的代码可以正常工作,我的测试机器具有Windows 7专业版和PHP版本5.3.5。现在我已经将我的文件上传到服务器上了(具有Linux和PHP版本5.2.15)在显示我的图片时出现问题。我的pdf文件没有图片,但图像的空白。我的网页的其他布局工作正常。如果任何人可以帮助我如何解决这个问题。这里是我的HTML2PDF脚本代码...当使用html2ps API显示pdf时,图像显示为空白

 
_dest_filename = $dest_filename; 
     } 

     function process($tmp_filename, $content_type) 
     { 
     copy($tmp_filename, $this->_dest_filename); 
     } 
    } 

    class MyFetcherMemory extends Fetcher { 
     var $base_path; 
     var $content; 

     function MyFetcherMemory($content, $base_path) { 
     $this->content = $content; 
     $this->base_path = $base_path; 
     } 

     function get_data($url) { 
     if (!$url) { 
      return new FetchedDataURL($this->content, array(), ""); 
     } else { 
      // remove the "file:///" protocol 
      if (substr($url,0,8)=='file:///') { 
      $url=substr($url,8); 
      // remove the additional '/' that is currently inserted by utils_url.php 
      if (PHP_OS == "WINNT") $url=substr($url,1); 
      } 
      return new FetchedDataURL(@file_get_contents($url), array(), ""); 
     } 
     } 

     function get_base_url() { 
     return 'file:///'.$this->base_path; 
     } 
    } 

    function convert_to_pdf($html, $path_to_pdf, $base_path='') { 
     $pipeline = PipelineFactory::create_default_pipeline('', 
                  ''); 
     $pipeline->fetchers[] = new MyFetcherMemory($html, $base_path); 

     // Override destination to local file 
     $pipeline->destination = new MyDestinationFile($path_to_pdf); 

     $baseurl = ''; 
     $media =& Media::predefined('A4'); 
     $media->set_landscape(true); 
     $media->set_margins(array('left' => 40, 
           'right' => 5, 
           'top' => 5, 
           'bottom' => 0)); 
     $media->set_pixels(1024); 

     global $g_config; 
     $g_config = array(
         'cssmedia'  => 'screen', 
         'scalepoints' => '1', 
         'renderimages' => true, 
         'renderlinks' => false, 
         'renderfields' => false, 
         'renderforms' => false, 
         'mode'   => 'php', 
         'encoding'  => '', 
         'debugbox'  => false, 
         'pdfversion' => '1.4', 
         'ps2pdf'  => 'ps2pdf', 

         'pslevel'  => '1', 
         'draw_page_border' => false 
         ); 
     $pipeline->configure($g_config); 
     $pipeline->process_batch(array($baseurl), $media); 
     } 
     ?> 


我已经定义了一个函数用于获取HTML

 
function generate_product_pdf($pid) 
{ 
.......my html code 
return $html; 
} 

在此先感谢...

+0

如何将图像包含在HTML中?检查图片URL是否正确,图片名称中没有空格,整个URL是小写,并确保路径是绝对路径(例如http://yoursite.com/path/to/image.jpg)。您问题中的脚本不完整或缺失,HTML代码将有助于回答您的问题。 – satrun77 2011-06-11 11:18:05

Linux机器可能无法访问图片通过您提供的URL。因此,它与DNS相关(如硬编码IP或不存在的域),托管相关(如图像位于http-auth保护的文件夹中)或代码错误(可检查操作系统)。无法调试它,很难说。