Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Font size too small: 0

I think maybe an error because pdf has more than 1 page and it creates all pages of pdf on 1 page
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: iTextSharp.text.DocumentException: Font size too small: 0

Source Error:



Line 1666:            StringReader s_tr = new StringReader(s_tw.ToString());
Line 1667:            HTMLWorker html_worker = new HTMLWorker(doc);
Line 1668:            html_worker.Parse(s_tr);
Line 1669:            doc.Close();
Line 1670:            Response.Write(doc);
  

 Source File:  C:\Users\    Line:  1668 

Stack Trace: 



[DocumentException: Font size too small: 0]
   iTextSharp.text.pdf.PdfDocument.Add(IElement element) +6159
   iTextSharp.text.Document.Add(IElement element) +176
   iTextSharp.text.html.simpleparser.HTMLWorker.ProcessTable() +89
   iTextSharp.text.html.simpleparser.HTMLTagProcessor_TABLE.EndElement(HTMLWorker worker, String tag) +68
   iTextSharp.text.html.simpleparser.HTMLWorker.EndElement(String tag) +52
   iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) +1367
   iTextSharp.text.html.simpleparser.HTMLWorker.Parse(TextReader reader) +78
   miguide.WebForm25.sll() in C:\Users:1668
   miguide.WebForm25.Page_Load(Object sender, EventArgs e) in C:\Users:38
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +52
   System.Web.UI.Control.OnLoad(EventArgs e) +97
   System.Web.UI.Control.LoadRecursive() +61
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +693


What I have tried:

C#
string attachment = "attachment; filename=" + "abc" + ".pdf";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/pdf";
            StringWriter s_tw = new StringWriter();
            HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
            h_textw.AddStyleAttribute("font-size", "7pt");
            h_textw.AddStyleAttribute("color", "Black");
           this.Page.RenderControl(h_textw);//Name of the Panel
            Document doc = new Document();
            doc = new Document(PageSize.A4, 5, 5, 15, 5);
            FontFactory.GetFont("Times New Roman", 14);
            PdfWriter.GetInstance(doc, Response.OutputStream);
            doc.Open();           
            StringReader s_tr = new StringReader(s_tw.ToString());
            HTMLWorker html_worker = new HTMLWorker(doc);
            html_worker.Parse(s_tr);
            doc.Close();
            Response.Write(doc);
Posted
Updated 7-Oct-20 15:35pm
v3
Comments
Afzaal Ahmad Zeeshan 1-Nov-19 7:09am    
Maybe try setting a font. Although I am not an expert in iTextSharp, but I feel like you are only getting the font, not setting it anywhere. Maybe I am wrong, but the error says something like that.
Richard MacCutchan 1-Nov-19 9:50am    
You are right, see my suggestions below.

1 solution

C#
FontFactory.GetFont("Times New Roman", 14);

The GetFont method returns a Font reference which you need to capture, and pass in to iTextSharp. Something like:
C#
Font myTimesFont = FontFactory.GetFont("Times New Roman", 14);
// not sure how you pass this in ...


[edit]
See itextsharp select font - Google Search[^]
[/edit]
 
Share this answer
 
v2
Comments
Member 14192879 1-Nov-19 20:23pm    
I used the same as suggested by you but the problem is that when my pdf has only one page then it shows me pdf but when my pdf has more than one page then it shows an error font size is too small. how can I create no of pages in pdf or it creates automatically page?
Richard MacCutchan 2-Nov-19 4:37am    
Sorry, I have not used iTextSharp. You need to look at your code to see what happens when there is more than one page being created. I can only guess that somewhere you are missing some code that sets or resets the font.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900