0

ここに私のXHTMLがあります:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<META content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<table cellspacing="0" cellpadding="0" align="Center"
    style="table-layout: fixed; word-wrap: break-word; width: 97%"
    bordercolor="4f81BD" border="1">
    <tbody>
        <tr style="color: white;">
            <td height="31" bgcolor="#4f81BD"
                style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px"
                align="Center"><span style="font-weight: Bold">Type</span></td>
            <td bgcolor="#4f81BD"
                style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px"
                align="Center"><span style="font-weight: Bold">Custodian
            Name</span></td>
            <td bgcolor="#4f81BD"
                style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px"
                align="Center"><span style="font-weight: Bold">Relationship
            to Owner</span></td>
            <td bgcolor="#4f81BD"
                style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px"
                align="Center"><span style="font-weight: Bold">Percent</span></td>
            <td bgcolor="#4f81BD"
                style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px"
                align="Center"><span style="font-weight: Bold">Minor
            Name</span></td>
            <td bgcolor="#4f81BD"
                style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px"
                align="Center"><span style="font-weight: Bold">For the
            State of</span></td>
        </tr>
        <tr style="font-family: SansSerif;" align="center">
            <td
                style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;"
                align="Center"><span style="font-weight: Bold">
            UTMA/UGMA</span></td>
            <td
                style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;"
                align="Center"><span>QQQQQQQQQQQQQQQQQQQQQQQQQ
            MMMMMMMMMMMMMMMMMMMMMMMMMM</span></td>
            <td
                style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;"
                align="Center"><span>Common Law Husband</span></td>
            <td
                style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;"
                align="Center"><span>15%</span></td>
            <td
                style="border-left: solid; border-bottom: solid; border-top: none; border-Right: solid; border-width: 1px;"
                align="Center">RRRRRRRRRRRRRRRRRRRRRRRR BBBBBBBBBBBBBBBBBBBBBB</td>
            <td
                style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;"
                align="Center"><span>DC</span></td>
        </tr>
    </tbody>
</table>
</body>
</html>

このコードでPDFに変換しようとすると:

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import org.xhtmlrenderer.pdf.ITextRenderer;
    import com.lowagie.text.DocumentException;

    public class Practice {
        public static void main(String[] args) throws 
IOException, DocumentException {
            String inputFile = "sample.xhtml";
            String url = new File(inputFile).toURI().toURL().toString();
            String outputFile = "firstdoc.pdf";
            OutputStream os = new FileOutputStream(outputFile);
            ITextRenderer renderer = new ITextRenderer();
            renderer.setDocument(url);
            renderer.layout();
            renderer.createPDF(os);

            os.close();
        }
    }

それは私にこの出力を与えています:

ここに画像の説明を入力

しかし、ブラウザで XHTML を開くと、次のようになります。

ここに画像の説明を入力

問題がわかりません。私の主な目的は、その与えられたスペースで言葉を壊すことです. 私は iText 2.0.8 を使用していますが、会社が許可していないため、他の API を使用できません。どんな提案でも大いに役立ちます。

4

2 に答える 2

1

XHTML+CSS を PDF に変換するライブラリである Flying Saucer (org.xhtmlrenderer.pdf.ITextRenderer) を使用しています。PDF の生成には iText を使用します。

問題が CSS サポートにある場合は、Flying Saucer を検討する必要があります。XHTML と CSS のレンダリングは、iText を使用してレンダリングされたコンテンツを PDF に変換する前に行われます。

于 2012-07-12T12:12:54.137 に答える
0

数年前のバージョンの iText を使用しています。現在のバージョンを使用して、問題が解決されたかどうかを確認してみませんか? この間、彼らは HTML と XML を PDF に (またはその逆に) 変換するという膨大な量の作業を行ってきました。実際、それは彼らが取り組んできた主要なことだと思います。

于 2012-07-12T06:18:00.990 に答える