2012-06-22 47 views
0
public void genreatePdf() 
    { 
     StringBuilder sb = new StringBuilder(); 
     sb.Append("<table>"); 
     sb.Append("<tr><td><img src='images/my.jpg'/></td></tr>"); 
     sb.Append("<tr><td>some text</td></tr>"); 
     sb.Append("</table>"); 

     string path = Server.MapPath("~/invoice/invoice.pdf"); 
     Document document = new Document(PageSize.A4); 
     PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create)); 
     document.Open(); 
     document.Add(new Paragraph(strMailMsg.ToString())); 
     document.Close(); 
    } 

输出如何创建一个PDF文件包含图像和表格使用iTextSharp的pdf文件的

<table><tr><td><img src='images/my.jpg'/></td></tr><tr><td>some text</td></tr></table> 

QUS:预期格式是像图片和文字中有一个表。为什么没有在该格式上创建PDF文件。

回答

0

您需要创建一个表格并将其附加到pdf文件中。它不是通过追加XHTML来完成的,而是使用C#的内部表格。

Table aTable = new Table(2, 2); // 2 rows, 2 columns 
theTable.AddCell("0.0"); 
theTable.AddCell("0.1"); 
theTable.AddCell("1.0"); 
theTable.AddCell("1.1"); 

//add the table to the document 
document.Add(theTable); 

here是一个带有itextsharp的简单教程。

相关问题