0

と を含むHTMLマークアップがありHTML TableますImagesiTextSharp APIを変換するために使用していHTML markup to PDFます。ただし、残念ながら、画像と表を含むマークアップを PDFiTextSharpにエクスポートすることはできません。HTML

エラー: ネットワーク パスが見つかりませんでした。

結果は次のとおりです。 ここに画像の説明を入力

コード:

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using System.Data.SqlClient;
using System.Text;
using iTextSharp.text.html.simpleparser;
 public string strSelectUserListBuilder = @" <div style='width: 50%; border: 1 solid #000000; padding-bottom: 100; padding-left: 100;
        padding-right: 100; text-align: justify; text-justify: inter-word;'>
        <br />
        <table>
            <tr>
                <td>
                    <div id='divLeft'>
                        <p>
                            <img src='/images/log_out.png'  width='200' height='100' /></p>
                        <h2>
                            Packing slip</h2>
                        <h3>
                            Place this slip inside the box with your device.</h3>
                        <div id='divDeviceList' style='width: 600; text-align: left;' border='0' cellpadding='3'
                            cellspacing='1' rules='BOTH' frame='BOX'>
                            <table style='width: 600;'>
                                <tr>
                                    <td>
                                       <strong> ITEM</strong>
                                    </td>
                                    <td>
                                       <strong>  OFFER</strong>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        iPhone 5 32GB (AT&T)
                                    </td>
                                    <td>
                                        $205.00
                                    </td>
                                </tr>

                                <tr>
                                    <td align='right'>
                                    <hr />
                                     <strong><h3>Total Offer: &nbsp;</h3></strong>
                                    </td>
                                    <td>
                                    <hr />
                                      <strong> <h3>  $215.00</h3></strong>
                                    </td>
                                </tr>

                            </table>


                        </div>

                            <h3>
                                You have until 01/29/2014 to ship your device.</h3>
                        <p style='padding:10;'>
                            <i>If you send your device after the expiration date we cannot honor your initial offer.
                                We will not accept devices that have been reported lost or stolen.</i></p>
                        <br />
                    </div>
                </td>
                <td>
                    <div id='divRight'>
                     <div style='text-align:right;padding:15;'> <img src='/images/google-login.png' alt='barcode' /></div>
                        <table cellpadding='3' style='border: 1 solid orange;padding:20;'>

                        </tr>
                            <tr align='center'>
                                <td>
                                   <img src='/images/google-login.png'  />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <h3>
                                        'Find my iPhone' must be turned off</h3>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    This feature locks your device and will delay or reduce payment.
                                </td>
                            </tr>
                            <tr>
                                <td>
                                 <strong>How to deactivate:</strong></td>
                            </tr>
                            <tr>
                                <td>
                                    1. Tap the “settings” icon on your homescreen.</td>
                            </tr>
                            <tr>
                                <td>
                                    2. Tap iCloud from the settings menu. </td>
                            </tr>
                            <tr>
                                <td>
                                    3. If 'Find My iPhone' is on, tap the slider to turn it off.</td>
                            </tr>
                        </table>
                    </div>";

protected void HTMLToPDF()
    {

        String htmlText = strSelectUserListBuilder.ToString();
        Document document = new Document();
        PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "MySamplePDF.pdf", FileMode.Create));
        document.Open();
        iTextSharp.text.html.simpleparser.HTMLWorker hw =
                     new iTextSharp.text.html.simpleparser.HTMLWorker(document);
        hw.Parse(new StringReader(htmlText));
        document.Close();
    }

protected void Page_Load(object sender, EventArgs e)
{
         HTMLToPDF();
}

このエラーは画像パスが原因であることはわかっています。しかし、解決できません。

解決策はありますか?

助けて感謝!

4

2 に答える 2

0

見てみましょう:データベースからの画像を使用してitextsharpでpdfを作成する

すべての img-elements の src-attribute に完全な物理パスを指定する必要があります (例: <img src="c:\myproject\images\image.jpg"/>)。または、すべての画像の物理ベース フォルダーを iTextSharp に伝える可能性があります。

于 2014-01-07T10:05:11.423 に答える