du6029076877 2012-07-09 12:38
浏览 242

为什么TCPDF会忽略我的内联CSS?

I am trying to create a PDF file using TCPDF. But When I tried to insert inline CSS into the HTML, it's displaying a blank page! Here are a few lines of my HTML:

pdf->AddPage();

// set font
$pdf->SetFont('helvetica', 'B', 20);

$pdf->Write(0, 'Example of HTML Justification', '', 0, 'L', true, 0, false, false, 0);

// create some HTML content
$html = '
<div id="wrapper" style="width:900px;height:auto;margin:0 auto;">
<div id="header" style="width:900px;height:180px;border-bottom:2px solid #5a5a5a;">
<div id="img" style="width:174px;height:87px;position:relative;top:10px;left:350px;"><img src="Untitled Document_files/logoticket.png" /></div>
<div id="text" style="width:250px;position:relative;left:315px;top:20px;font-family:Arial, Helvetica, sans-serif;font-weight:bold;font-size:14px;">E-TICKET/RESERVATION VOUCHER</div>
<div id="text2" style="width:200px;position:relative;left:345px;top:40px;font-family:Arial, Helvetica, sans-serif;
font-weight:bold;font-size:12px;">Visit - www.bookings.7sisters.in</div>
</div>
<div id="mainContent">
<div id="icon" style="width:600px;
height:37px;
position:relative;
left:190px;
top:20px;">
<img src="Untitled D.....

etc.

I am inserting the code in TCPDF example 39. But the output is only the TCPDF logo and the line "Example of HTML Justification". What's the reason? Or it does not support inline CSS?

  • 写回答

5条回答 默认 最新

  • douyuan4697 2012-07-11 15:42
    关注

    TCPDF has a very limited CSS support. It doesn't support all attributes.

    Currently, only the following CSS attributes are supported:

    • font-family
    • font-size
    • font-weight
    • font-style
    • color
    • background-color
    • text-decoration
    • width
    • height
    • text-align

    So try removing the other attributes, and tell if it works.

    Also, this is an active forum for TCPDF related discussion.

    TCPDF Documentation

    Alternatives to TCPDF that are definitely worth trying:

    domPDF

    Key Features

    • handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules
    • supports external stylesheets, either local or through http/ftp (via fopen-wrappers)
    • supports complex tables, including row & column spans, separate & collapsed border models, individual cell styling

    domPDF Documentation

    Helpful tutorial: http://kyokasuigetsu25.wordpress.com/2011/07/14/how-to-use-dompdf-with-css/

    mPDF

    Examples (both PHP and generated PDF) can be found here and here.

    mPDF Documentation

    Hope it helps :)

    评论

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染