2013-10-05 118 views
0

我們無法更改從以下代碼生成的pdf字體大小任何人都可以幫助我們?如何使用iTextSharp更改我的PDF文檔的字體大小

我們希望在更改字體大小後將該html文件轉換爲pdf。

using iTextSharp.text; 
using iTextSharp.text.html.simpleparser; 
using iTextSharp.text.pdf; 

protected void ConvertToPDFNow() 
{ 

StringWriter sw = new StringWriter(); 

    HtmlTextWriter w = new HtmlTextWriter(sw); 

     print.RenderControl(w); 

     string htmWrite = sw.GetStringBuilder().ToString(); 

    Response.ContentType = "application/pdf"; 


    Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf"); 

    Response.Cache.SetCacheability(HttpCacheability.NoCache); 

    htmWrite = Regex.Replace(htmWrite, "</?(a|A).*?>", ""); 

    htmWrite = htmWrite.Replace("\r\n", ""); 

    StringReader reader = new StringReader(htmWrite); 

    Document doc = new Document(PageSize.A4); 
    //Creating Document of A4 Size 
    HTMLWorker parser = new HTMLWorker(doc); 

    PdfWriter.GetInstance(doc, Response.OutputStream); 

    doc.Open(); 

    try 
    { 
    //rendering Html File     
    parser.Parse(reader); 
    } 

    catch (Exception ex) 
    {     
    } 
    finally 
    { 
     doc.Close(); 
    } 
    } 

回答

0

嘗試應用樣式表:

... 
    var style = new StyleSheet(); 
    style.LoadTagStyle("body", "size", "12px"); 
    parser.SetStyleSheet(style); 
... 
-1

下面的C#代碼工作飛馳改變itextpdf字體大小:

var style = new StyleSheet(); 
style.LoadTagStyle("body", "size", "8px"); 
HTMLWorker htmlworker = new HTMLWorker(document); 
htmlworker.SetStyleSheet(style); 
+1

我認爲這將是對OP和進一步遊客更有幫助,當你爲你的內涵添加一些解釋。 – reporter

相關問題