473,466 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Writing large data to PDF giving system out of memory Exception

1 New Member
Hi am trying to write large data to PDF but giving system out of memory Exception.

step1:
Expand|Select|Wrap|Line Numbers
  1.  using (SqlDataReader dr = cmd.ExecuteReader())
  2.                             {
  3.  
  4.                                 Int64 counter = 0;
  5.  
  6.  
  7.  
  8.                                 setBLR.Append("<table border = '1' width='100%'>");
  9.                                 setBLR.Append("<meta http-equiv=");
  10.                                 setBLR.Append("Content-Type");
  11.                                 setBLR.Append("content=");
  12.                                 setBLR.Append("text/html;");
  13.                                 setBLR.Append("charset=utf-8");
  14.                                 setBLR.Append("/>");
  15.                                 int t;
  16.  
  17.  
  18.  
  19.                                 #region "show header/footer"
  20.                                 if (i.header.ToUpper() == "Y")
  21.                                 {
  22.                                     setBLR.Append("<tr>");
  23.                                     for (t = 0; t < dr.FieldCount; t++)
  24.                                     {
  25.                                         setBLR.Append("<td>" + dr.GetName(t) + "</td>");
  26.                                     }
  27.  
  28.                                     setBLR.Append("</tr>");
  29.  
  30.                                 }
  31.                                 #endregion
  32.                                 while (dr.Read())
  33.                                 {
  34.                                     counter++;
  35.                                     setBLR.Append("<tr>");
  36.  
  37.                                     for (t = 0; t < dr.FieldCount; t++)
  38.                                     {
  39.  
  40.  
  41.                                         setBLR.Append("<td>" + dr[t].ToString() + "</td>");
  42.                                     }
  43.  
  44.                                     setBLR.Append("</tr>");
  45.                                 }
  46.  
  47.                                 setBLR.Append("</tr></table>");
  48.  
  49.  
  50.  
  51.  
  52.                                 StringReader sr = new StringReader(setBLR.ToString());
  53.                                 string shoheader = i.header.ToString();
  54.                                 converttopdf(setBLR.ToString(), i.file.ToString(), shoheader, i, counter);
  55.  
  56.                             }
  57.  
  58. Step 2:
  59.  public void converttopdf(string HTMLString, string fileLocation,string Header, Item i,Int64 counter)
  60.         {
  61.             try
  62.             {
  63.                 Document document = new Document();
  64.                 List<IElement> htmlarraylist = new List<IElement>();
  65.                 Phrase phrase = null;
  66.                 //Full path to the Unicode Arial file
  67.                 string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
  68.  
  69.  
  70.                 phrase = new Phrase();
  71.                 PdfWriter.GetInstance(document, new FileStream(fileLocation, FileMode.Create));
  72.                 document.Open();
  73.  
  74.  
  75.  
  76.                 var arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
  77.                 FontFactory.Register(arialFontPath);
  78.                 BaseFont bf = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, true);
  79.                 iTextSharp.text.Font FontAr = new iTextSharp.text.Font(bf);
  80.                 iTextSharp.text.FontFactory.RegisterDirectory(arialFontPath);
  81.                 StyleSheet styles = new StyleSheet();
  82.                 styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.FONTSIZE, "16");
  83.                 styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.COLOR, "navy");
  84.                 styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.FONTWEIGHT, "bold");
  85.                 styles.LoadTagStyle(HtmlTags.P, HtmlTags.INDENT, "30px");
  86.                 styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "Arial Unicode MS");
  87.                 styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
  88.  
  89.                 if (!String.IsNullOrWhiteSpace(i.addRowCount) && i.rowCountPosition.ToLower() == "top")
  90.                 {
  91.  
  92.                     StringBuilder bs = new StringBuilder();
  93.                     bs.Append("<table border = '1' width='100%'>");
  94.                     bs.Append("<tr>");
  95.                     bs.Append("<td>" + "Total Row Count:" + counter + "</td>");
  96.                     bs.Append("</tr>");
  97.                     bs.Append("</table>");
  98.  
  99.                     htmlarraylist = HTMLWorker.ParseToList(new StringReader(bs.ToString() + HTMLString.ToString()), styles);
  100.  
  101.                 }
  102.                 else if (!String.IsNullOrWhiteSpace(i.addRowCount) && i.rowCountPosition.ToLower() == "bottom")
  103.                 {
  104.  
  105.                     StringBuilder bs = new StringBuilder();
  106.                     bs.Append("<table border = '1' width='100%'>");
  107.                     bs.Append("<tr>");
  108.                     bs.Append("<td>" + "Total Row Count: " + counter + "</td>");
  109.                     bs.Append("</tr>");
  110.                     bs.Append("</table>");
  111.  
  112.                     htmlarraylist = HTMLWorker.ParseToList(new StringReader(HTMLString.ToString() + bs.ToString()), styles);
  113.                 }
  114.                 else
  115.                 {
  116.                     htmlarraylist = HTMLWorker.ParseToList(new StringReader(HTMLString.ToString()), styles);
  117.  
  118.                 }
  119.  
  120.  
  121.                 for (int k = 0; k < htmlarraylist.Count; k++)
  122.                 {
  123.                     document.Add((IElement)htmlarraylist[k]);
  124.  
  125.                 }
  126.  
  127.  
  128.                 document.Close();
  129.             }
  130.             catch (Exception ex)
  131.             {
  132.  
  133.                 throw ex;
  134.             }
  135.  
  136.         }
Nov 15 '16 #1
1 2369
Luuk
1,047 Recognized Expert Top Contributor
  1. Define 'large'
  2. On what line is the 'system out of memory Exception ' raised?

@1: is Large something in kiloBytes, megaBytes, gigaBytes, or bigger....
@2: I think the line on which the exception occurs is a line that starts with 'setBLR.Append(.....'
Nov 26 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Luk Vloemans | last post by:
Hi, I'm trying to copy data onto unmanaged memory in C#. I found the how you would normally do it in C++: uint eventMask = 0; IntPtr uMask = Marshal.AllocHGlobal(Marshal.SizeOf(eventMask));...
2
by: Aravind | last post by:
Hi, I am ruuning to out of memory exception , My system has RAM of 4 GB and virtual memory paging size set to 4GB .When I check the memory occupied by the process during the exception , it is less...
2
by: PVV30 | last post by:
Hi, I am currently involved in development of customer database. This database contains around 150,000 records. We have a search screen where users may search customers. However when search to...
5
by: LP | last post by:
Hello, We running VB.NET application which gets massive amounts of data from SQL Server, loads data into DataTables, then re-arranges data into tabular structure and outputs it to a flat file....
11
by: ulyses | last post by:
Let's assume I have following file: 2938929384902491233..... 923949919199191919112.... File contains INTs only. What is more they are huge. For example first row in file may contain integer...
4
by: Joel | last post by:
I'm sorry if this question has been asked before, but is it possible to define a 2 D array of type double with dimensions of the order 65536 x 65536 ? I'm working on a face recognition algorithm...
0
by: OrganicPanda | last post by:
Hey, I'm trying to read lines from very large log files and write them off in to smaller text files, effectively splitting the log files into more manageable sizes. For example one log file is...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi Guys, I have a real serious problem that stoped me doing any progress in my project. in one of my webpages I have a wizard of more then 13 pages and in every page some Ajax controls,...
1
by: =?Utf-8?B?SHVzYW0=?= | last post by:
Hi EveryBody: I have the following code to download the data from my web application: the code is: Dim rawan As New List(Of String) ' for File Name Dim rawan1 As New List(Of Byte()) ' for...
3
by: sriram347 | last post by:
Hi I am a newbie to ASP.NET. I developed a web page (project type is web application) and I keep getting this error. B]Error message : "System.AccessViolation Exception attempted to read or...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.