我有一個HTML
標記,其中有HTML
Table
和Images
。我正在使用iTextSharp API
來轉換HTML markup to PDF
。但是,不幸的是,iTextSharp
無法將包含圖像&表的HTML
標記導出爲PDF。無法使用C#在asp.net中使用iTextSharp API將HTML標記導出爲PDF?
錯誤:未找到網絡路徑。
結果必然是:
代碼:
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: </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();
}
我知道這個錯誤是由於圖像路徑。但是,無法解決。
任何解決方案?
幫助讚賞!
它爲你工作嗎? –
pdf不是按照我所展示的設計創建的......!它扭曲... :( –
是的,但你有沒有試圖進入圖像的完整物理路徑(如我在我的回答中所建議的)? –