2014-10-10 45 views
1

背景: 我想使用mPDF库在300dpi渲染名片。该文档具有应该填充画布的图像背景,然后覆盖各种文本元素。MPDF文档和图像DPI问题

尺寸: PDF文档设置为91mm x 61mm并且处于横向格式。

$pdf = new mPDF('utf-8', array(91,61), 0, '', 0, 0, 0, 0, 0, 'L'); 

我在配置中设置的分辨率如下;

$this->dpi = 300; $this->img_dpi = 300

我在300dpi的到相同的尺寸卡(91毫米X61毫米)在Photoshop中创建的图像,也。

我曾尝试使用标记如下添加图像到文档中的DIV中:

$html .= '<div style="position: absolute; left:0; right: 0; top: 0; bottom: 0;width:100%; height:100%"><img style="width:100%; height:100%" src="/assets/images/bg.jpg"></div>'; 

当显示PDF文档,图像似乎比文档小的,也就是说,它不是缩放以适合页面。事实上,图像只能在X和Y方向上填充大约55-60%的画布。

当我保存PDF文档并查看其Adobe Reader内的属性时,它被确认为91x61mm的正确尺寸。

有没有人有类似的问题或明白这里发生了什么?

我真的需要能够有一个300dpi的图像,这将完全填满页面。

我期待您的建议。

问候

詹姆斯

回答

1

你有不完全匹配在手册的recommendation的那些在“大小限制”在我的情况下,部分

的CSS样式,我有一个景观形象,是11x8 .5英寸150dpi的Photoshop中,这是匹配在MP3播放器的页面大小,我分开的清洁度的CSS

以防万一,我指定任何其他mpdf值或CSS设置

所以尝试更多的东西像这样的代码,该代码为我工作,定位与CSS &文本根据需要进行调整的DPI /页面大小:

$html = ' 
<html> 
<head> 
<style> 
    body { 
     position: relative; 
     text-align: center; 
     overflow: hidden; 
     page-break-inside: avoid; 
    } 
    #bg { 
     position: absolute; 
     left:0; 
     right: 0; 
     top: 0; 
     bottom: 0; 
    } 
    #bg img { 
     width: 100%; 
     height: 100%; 
     margin: 0; 
    } 
    #text1 { 
     top: 20%; 
     font-size: 20pt; 
     position: absolute; 
     width: 100%; 
     color: #fff; 
    } 
    #text2 { 
     top: 60%; 
     font-size: 16pt; 
     position: absolute; 
     width: 100%; 
     color: #ddd; 
    } 
</style> 
    </head> 
    <body> 
    <div id="bg"> 
     <img src="bg.png" /> 
    </div> 
    <div id="text1">John Smith</div> 
    <div id="text2">555-5555</div> 
</body> 
</html>'; 

$mpdf = new mPDF('UTF8','Letter-L',14,'Arial',0,0,0,0,0,0); 
$mpdf->dpi = 150; 
$mpdf->img_dpi = 150; 
$mpdf->WriteHTML($html); 
$mpdf->SetDisplayMode('fullpage'); 
$mpdf->Output(); 

当然还有做背景的简单方法...告诉身体或HTML在CSS中有一个背景图像,但然后你遇到this bug所以这不是我的第一个建议