2013-07-04 40 views
0

我已經創建了用於從HTML文件準備PDF的代碼。我的問題是生成的PDF不顯示我的HTML表格的邊框。我沒有使用任何CSS文件,所有的豎框都是內聯寫入的。以下是我的HTML示例。顯示頁眉/頁腳和HTML表格網格線[使用iTextSharp生成HTML到PDF]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head> 
<body> 
<table cellpadding="0" cellspacing="0" border="0" width="100%" style=" font-family:'Times New Roman', Times, serif; font-size:12px; margin:20px 0px; border:10px solid #000; color:#000;"> 
<tr> 
     <td width="40%" align="center"><img src="[LOGOIMAGE]" alt="logo" /></td> 
     <td width="30%" align="center" style="border-left:1px solid #000;">June, 26 2013<br />page 1 of 3</td> 
     <td width="30%" align="center" style="border-left:1px solid #000;">123456<br />Name</td> 
    </tr> 
</table> 
</body> 
</html> 

我也嘗試增加邊框寬度高達10px的,因爲谷歌搜索時我發現,一些其他開發商也面臨同樣的問題,嘗試這種解決它,但是這並沒有爲我工作。

我正在使用下面的代碼來生成PDF。

Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition", "attachment;filename=Details.pdf"); 
Response.Cache.SetCacheability(HttpCacheability.NoCache); 
// Document d = new Document(new Rectangle(100f, 300f)); 
var doc = new Document(PageSize.A4, 50, 50, 25, 25); 

// Create a new PdfWriter object, specifying the output stream 
var output = new MemoryStream(); 
// var writer = PdfWriter.GetInstance(doc, output); 

string path = Server.MapPath("pdfs"); 
PdfWriter.GetInstance(doc, new FileStream(path + "/doc3.pdf", FileMode.Create)); 
PdfWriter.GetInstance(doc, Response.OutputStream); 
doc.Open(); 
string contents = File.ReadAllText(Server.MapPath("myfile.html")); 
contents = contents.Replace("[LOGOIMAGE]", Server.MapPath("App_Data/images/logo.jpg")); 

var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null); 

// Enumerate the elements, adding each one to the Document... 
foreach (var htmlElement in parsedHtmlElements) 
    doc.Add(htmlElement as IElement); 
doc.Close(); 
Response.Write(doc); 
Response.End(); 

回答

0

如果您更改border =「1」,它們將顯示出來。

相關問題