Hi am trying to write large data to PDF but giving system out of memory Exception.
step1: - using (SqlDataReader dr = cmd.ExecuteReader())
-
{
-
-
Int64 counter = 0;
-
-
-
-
setBLR.Append("<table border = '1' width='100%'>");
-
setBLR.Append("<meta http-equiv=");
-
setBLR.Append("Content-Type");
-
setBLR.Append("content=");
-
setBLR.Append("text/html;");
-
setBLR.Append("charset=utf-8");
-
setBLR.Append("/>");
-
int t;
-
-
-
-
#region "show header/footer"
-
if (i.header.ToUpper() == "Y")
-
{
-
setBLR.Append("<tr>");
-
for (t = 0; t < dr.FieldCount; t++)
-
{
-
setBLR.Append("<td>" + dr.GetName(t) + "</td>");
-
}
-
-
setBLR.Append("</tr>");
-
-
}
-
#endregion
-
while (dr.Read())
-
{
-
counter++;
-
setBLR.Append("<tr>");
-
-
for (t = 0; t < dr.FieldCount; t++)
-
{
-
-
-
setBLR.Append("<td>" + dr[t].ToString() + "</td>");
-
}
-
-
setBLR.Append("</tr>");
-
}
-
-
setBLR.Append("</tr></table>");
-
-
-
-
-
StringReader sr = new StringReader(setBLR.ToString());
-
string shoheader = i.header.ToString();
-
converttopdf(setBLR.ToString(), i.file.ToString(), shoheader, i, counter);
-
-
}
-
-
Step 2:
-
public void converttopdf(string HTMLString, string fileLocation,string Header, Item i,Int64 counter)
-
{
-
try
-
{
-
Document document = new Document();
-
List<IElement> htmlarraylist = new List<IElement>();
-
Phrase phrase = null;
-
//Full path to the Unicode Arial file
-
string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
-
-
-
phrase = new Phrase();
-
PdfWriter.GetInstance(document, new FileStream(fileLocation, FileMode.Create));
-
document.Open();
-
-
-
-
var arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
-
FontFactory.Register(arialFontPath);
-
BaseFont bf = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, true);
-
iTextSharp.text.Font FontAr = new iTextSharp.text.Font(bf);
-
iTextSharp.text.FontFactory.RegisterDirectory(arialFontPath);
-
StyleSheet styles = new StyleSheet();
-
styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.FONTSIZE, "16");
-
styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.COLOR, "navy");
-
styles.LoadTagStyle(HtmlTags.DIV, HtmlTags.FONTWEIGHT, "bold");
-
styles.LoadTagStyle(HtmlTags.P, HtmlTags.INDENT, "30px");
-
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "Arial Unicode MS");
-
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
-
-
if (!String.IsNullOrWhiteSpace(i.addRowCount) && i.rowCountPosition.ToLower() == "top")
-
{
-
-
StringBuilder bs = new StringBuilder();
-
bs.Append("<table border = '1' width='100%'>");
-
bs.Append("<tr>");
-
bs.Append("<td>" + "Total Row Count:" + counter + "</td>");
-
bs.Append("</tr>");
-
bs.Append("</table>");
-
-
htmlarraylist = HTMLWorker.ParseToList(new StringReader(bs.ToString() + HTMLString.ToString()), styles);
-
-
}
-
else if (!String.IsNullOrWhiteSpace(i.addRowCount) && i.rowCountPosition.ToLower() == "bottom")
-
{
-
-
StringBuilder bs = new StringBuilder();
-
bs.Append("<table border = '1' width='100%'>");
-
bs.Append("<tr>");
-
bs.Append("<td>" + "Total Row Count: " + counter + "</td>");
-
bs.Append("</tr>");
-
bs.Append("</table>");
-
-
htmlarraylist = HTMLWorker.ParseToList(new StringReader(HTMLString.ToString() + bs.ToString()), styles);
-
}
-
else
-
{
-
htmlarraylist = HTMLWorker.ParseToList(new StringReader(HTMLString.ToString()), styles);
-
-
}
-
-
-
for (int k = 0; k < htmlarraylist.Count; k++)
-
{
-
document.Add((IElement)htmlarraylist[k]);
-
-
}
-
-
-
document.Close();
-
}
-
catch (Exception ex)
-
{
-
-
throw ex;
-
}
-
-
}
1 2369 Luuk 1,047
Recognized Expert Top Contributor - Define 'large'
- 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(.....'
Sign in to post your reply or Sign up for a free account.
Similar topics
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));...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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 ...
| |