使用 html2ps API 显示 pdf 时图像显示为空白
我正在研究 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; }
提前致谢...
I am working on pdf creation script i am trying to create my pdf using html2ps API. My code works fine with my testing machine having Windows 7 professional edition and php version 5.3.5. Now i have uploaded my files on server(having Linux and php version 5.2.15 ) there is a problem while display of my pictures. My pdf file have no picture but blank space for image. other layout of my page works fine. If any one can help me how i can fix this issue. Here is my code for html2pdf script...
_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); } ?>
I have defined a function for getting html
function generate_product_pdf($pid) { .......my html code return $html; }
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Linux 计算机可能无法通过您提供的 URL 访问图像。因此,它要么与 DNS 相关(例如硬编码 IP 或不存在的域)、与托管相关(例如图像位于 http-auth 受保护的文件夹中),要么与代码中的错误(可以检查操作系统)有关。如果没有办法调试它,很难说。
Linux machine probably can't access images by URL that you provide. So its either DNS-related (like hard-coded IP or non-existant domain), hosting related (like images are in a http-auth protected folder) or error in the code (which can check for OS). Without means to debug it, its hard to tell.