我正在研究pdf创建脚本我正在尝试使用html2ps API创建我的pdf。我的代码适用于我的测试机器有Windows 7专业版和PHP版本5.3.5。现在我已将我的文件上传到服务器上(有Linux和php版本5.2.15),在显示我的图片时出现问题。我的pdf文件没有图片,但图片空白。我的页面的其他布局工作正常。如果任何人可以帮助我如何解决这个问题。这是我的html2pdf脚本代码......
_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 :(得分:0)
Linux机器可能无法通过您提供的URL访问图像。所以它与DNS相关(如硬编码的IP或不存在的域),托管相关(如图像在http-auth保护文件夹中)或代码中的错误(可以检查操作系统)。没有调试它的手段,很难说。