I need to create a pdf from .aspx page. In .aspx page user will enter so many values in textbox and gridview. It also has some tabs with different sections. I did used iTextSharp for creating simple pdf. But here i need to get the values from the page and need to read the tab controls. So is it posible to use iTextSharp or is there any opensource dll available for converting .aspx to pdf..
Give me some idea?
Thanks..
By using ITextsharp library,this can be done by using HTMLWorker :
First Create String builder;
private StringBuilder sb;
Then add pdf heading from textbox value as:
sb.Append("<p style=\"text-align: center;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtHeading + "</p>");
Then add subject to pdf from textbox value as:
sb.Append("<table><tr valign=\"top\"><td>Subj:</td><td style=\"font-size:" + fontSize + "px;font-weight:bold;text-decoration:underline;\">" + txtSubject.text + "</td></tr></table><br />");
Then add paragraphs from textbox value as:
sb.Append("<p style=\"text-align: left;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtParagraph + "</p><br/>");
for table creation take values in string[] array
sb.Append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0.5\"><thead><tr align=\"center\" valign=\"top\">");
foreach (string str in StringArray)
{
sb.Append("<th><strong>" + str + "</strong></th>");
}
sb.Append("</tr></thead>");
And so on.You can create pdf from textbox values of aspx page.
Itext Sharp quite easy .about tabs ,I dont know may be it will work ,as it works for paging ,I mean it converts all the matter in the paging ,in a single pdf
Click Here For Example
Related
I have a following code:
DataSourceSelectArguments sr = new DataSourceSelectArguments();
DataView dv = DurationSQL.Select(sr) as DataView;
if (dv.Count != 0)
{
GridView2.Rows[0].Cells[0].Text = "Duration: \r" + dv[0][0].ToString() + "\r|";
}
I would like to make the static text:
Duration:
Displayed in bold while the rest of the text has no styling applied any way to achieve this?
You can put HTML into the cell text to achieve this, while at the same time preventing that HTML from being HtmlEncoded, like this:
Put HTML into the cell:
GridView2.Rows[0].Cells[0].Text = "<b>Duration:</b><br />"
+ HttpUtility.HtmlEncode(dv[0][0].ToString()) + "<br />|";
I included a call to .HtmlEncode(), but if the value is e.g. a number you may even skip that.
Prevent HTML from being encoded (use it for your first column, based on the fact that you use Cells[0]):
<asp:BoundField DataField="YourColumn" HtmlEncode="False" />
string text = GridView1.Rows[0].Cells[0].Text;
var span1 = new HtmlGenericControl("span");
span1.InnerHtml = "<strong>Duration:</strong> \r" + text;
GridView2.Rows[0].Cells[0].Text = span1.InnerHtml;
Seemed to work thanks for the comment
I need to add some space between values to make in centralized,i'm using blank space in strings ,but its not good,i need to put the strings in parameters in the same paragraph.
paragraph = new iTextSharp.text.Paragraph("Vlr Notas:" + VlrNotas + " Vlr Débitos:" + VlrDebito + " Data De Crédito:" + DtCredito, font2);
paragraph.Alignment = iTextSharp.text.Element.ALIGN_LEFT;
document.Add(paragraph);
I'm doing this,i need to put "VlrNotas" align left and in the center of the page the "VlrDébitos",is there a way to put in absoluto position?
I been using HAP to parse my table, and it is showing up perfectly the way I want it in the webpage using this code..
foreach(var table in doc.DocumentNode.SelectNodes("//table"))
{
//Response.Write("Found: " + table.Id);
foreach(HtmlNode row in table.SelectNodes("tr"))
{
Response.Write("<br>");
foreach(HtmlNode cell in row.SelectNodes("th|td"))
{
Response.Write(cell.InnerHtml + "<br>");
}
}
}
it prints out like this..
Ali, Saleh(#82358)
PO Box: 0001
Abu Dhabi 0000
United Arab Emirates
Phone: +1234567890
Ali, Saleh(#82358)
PO Box: 0001
Abu Dhabi 0000
United Arab Emirates
Phone: +1234567890
etc...
I am trying to get it to write to a file exactly like that and am running into an issue, when I add this to the foreach statement to write the cells
sb1.Append(cell.InnerHtml + "<br>");
sb1.AppendLine();
sb1.Append("<br>");
and this after the complete loop
string str3 = str2.Replace("<br>", Environment.NewLine).Replace(" ", " ")
.Replace(" ", "");
System.IO.File.WriteAllText(#"C:\BBBBB.txt", str3);
When I look at the text file, it is almost looking the way it does in the webpage, but there is a lot of empty space that I have to deal with. However, if I save the html page as a text file (when running the app) from the browser it lays it out in text file exactly how it looks on the webpage.
I've tried, writing the cells innerHtml to a text file and have tried saving the cell inner text but either way, I still find myself having to replace strings.
How can I get the webpage layout to be the same when saved to a textfile?
I am trying to write a C# class that will return various code pieces to a view in MVC4. The code I am returning has both html and jquery in it. Currently I am doing the following:
output += "<table id =\"" + grid.name + "\"></table>\n";
output += "<div id=\"" + grid.pager + "\"></div>\n";
output += "jQuery(\"" + grid.name + "\") //and so on
This is my method. Output is a string. This string contains both html and jquery. I am simply returning output:
return output;
Then, in my view I am using #Html.Raw to convert the string:
#Html.Raw(MyMethod.GetString())
The problem is that the html elements a formatted correctly but the jquery elements are written to the page as plain text. Any ideas how I can get the page to turn the string into actual syntax? Should I return my string differently?
As Jquery is javascript, you should wrap this code in a <script> tag:
output += "<table id =\"" + grid.name + "\"></table>\n";
output += "<div id=\"" + grid.pager + "\"></div>\n";
output += "<script type=\"text/javascript\">jQuery(\"" + grid.name + "\");</script> //and so on
I am trying to format a string to add spaces in between the strings in c#.
summary.AppendFormat(" {0} {1}: {2}{3}</br> ", item.FirstName, item.LastName, item.Completed ? item.Summary : "not completed", item.Schedule == DateTime.MinValue ? "" : " (" + DateTime.ToShortDate(item.Schedule, user) + ")");
This should render in the HTML page as
First Round Suri Narayanan: recommend (3/2/2012)
but i am seeing this as like below in html page
First Round</br> Suri Narayanan: recommend (3/2/2012)</br>
if i edit the same using firebug, say if i put some space, then its getting formatted well and good.
Please let me know your comments on this.
You should use Literal like below.
<asp:Literal ID="Literal" runat="server" Mode="PassThrough"></asp:Literal>
Literal.text = "Your text"