使用itextsharp的图像和CSS

时间:2015-03-19 16:31:15

标签: c# asp.net itextsharp

在asp.net网页表单中,我使用itextsharp将包含Gridview的Panel保存为PDF文件 我在Gridview之前有3行显示(gridview的公司徽标,地址和标题)。
创建的PDF没有徽标+所有CSS(不应用颜色,字体等) 我已将itextsharp更新为最新版本,但没有成功
这是我的aspx代码:

<asp:Panel runat="server" ID="PaidOrdersPanel">
<!-- to be shown on PDF-->
<img src="http://dev.123.com/img/logo.png" style="width: 249px; height: auto; display: none;" />
<span style="color: #10598B; font-weight: normal; font-size: 12px !important; display: none; font-family: Corbel;" id="h9">123 Inc.<br />
123 St.<br />
city<br />
postal code</span>
<h5 style="color: #10598B; display: none; text-align: center;">Paid orders report</h5>
<asp:GridView runat="server" ID="PaidOrdersGV" RowStyle-Wrap="false" AllowPaging="true" PageSize="10" Width="100%" CssClass="Grid" AlternatingRowStyle-CssClass="alt" AutoGenerateColumns="false"
    PagerStyle-CssClass="pgr" HeaderStyle-ForeColor="White" PagerStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" RowStyle-HorizontalAlign="Center" DataKeyNames="Document#"
     OnPageIndexChanging="PaidOrdersGV_PageIndexChanging" OnRowDataBound="PaidOrdersGV_RowDataBound" OnRowCommand="PaidOrdersGV_RowCommand">
    <EmptyDataTemplate>
     <div style="text-align: center;">no records found</div>
     </EmptyDataTemplate>
     <Columns>
     <asp:ButtonField CommandName="PaidOrders_Details" DataTextField="Document#" HeaderText="Document #" SortExpression="Document#" ItemStyle-ForeColor="Black" ItemStyle-Font-Underline="true" />
    <asp:BoundField DataField="Order#" HeaderText="order #" SortExpression="Order#" />
     <asp:BoundField DataField="Order Date" HeaderText="Order Date" SortExpression="Order Date" DataFormatString="{0:d}"></asp:BoundField>
    <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status"></asp:BoundField>
     <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" DataFormatString="{0:C2}"></asp:BoundField>
     </Columns>
</asp:GridView>
</asp:Panel>

和C#代码:

if (PaidOrdersGV.Rows.Count > 0)
{
    //to allow paging=false & change style.
    PaidOrdersGV.HeaderStyle.ForeColor = System.Drawing.Color.Black;
    PaidOrdersGV.BorderColor = Color.Gray;
    PaidOrdersGV.Font.Name = "Tahoma";
    PaidOrdersGV.DataSource = clsBP.get_PaidOrders(lbl_BP_Id.Text);
    PaidOrdersGV.AllowPaging = false;
    PaidOrdersGV.Columns[0].Visible = false;
    PaidOrdersGV.DataBind();

    //to PDF code 
    string attachment = "attachment; filename=myFile.pdf";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/pdf";
    StringWriter stw = new StringWriter();
    HtmlTextWriter htextw = new HtmlTextWriter(stw);
    htextw.AddStyleAttribute("font-size", "8pt");
    htextw.AddStyleAttribute("color", "Grey");

    PaidOrdersPanel.RenderControl(htextw);//Name of the Panel
    Document document = new Document();
    document = new Document(PageSize.A4, 5, 5, 15, 5);
    FontFactory.GetFont("Tahoma", 50, iTextSharp.text.BaseColor.BLUE);
    PdfWriter.GetInstance(document, Response.OutputStream);
    document.Open();

    StringReader str = new StringReader(stw.ToString());
    HTMLWorker htmlworker = new HTMLWorker(document);
    htmlworker.Parse(str);

    document.Close();
    Response.Write(document);
}

请告知

0 个答案:

没有答案