15,905,915 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Mausam Bharati (Top 6 by date)
Mausam Bharati
9-Jul-13 7:57am
View
There is no error.A blank pdf page is generated.
protected void txtPDF_Click(object sender, EventArgs e)
{
PDFReport pdfReport = new PDFReport();
pdfReport.ReportProperty.ReportTable = "Bill";
pdfReport.ReportProperty.Columns = new System.Collections.Generic.Dictionary<string, string="">();
pdfReport.ReportProperty.Columns.Add("Emp Code", "Employee Code");
pdfReport.ReportProperty.Columns.Add("Status", "Employee Status");
pdfReport.ReportProperty.Columns.Add("Bill Type", "Employee BillType");
pdfReport.ReportProperty.Columns.Add("Financial Yr", "Financial Year");
pdfReport.ReportProperty.Columns.Add("Bill Date", "Bill Date From");
pdfReport.ReportProperty.Columns.Add("Approve Date", "Bill Date To");
Literal1.Text = pdfReport.HTMLToPdf(pdfReport.ReportProperty, "C:\\temp.pdf",Response.OutputStream);
}
this is my on button click event.
Mausam Bharati
9-Jul-13 7:51am
View
Excuse any error..I am a beginner. :(
Mausam Bharati
9-Jul-13 7:50am
View
This code is a function of a dll.The string htmlread2 is called from the other function.
using System;
using System.Collections;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace ReportLib
{
public class PDFReport
{
public struct _TableProperty
{
public string ReportTable { get; set; }
public Dictionary<string, string=""> Columns;
public string ReportCondition { get; set; }
}
public _TableProperty ReportProperty = new _TableProperty();
public string getReportHTML(_TableProperty tableProperty, Stream stream)
{
string sql = "select ";
string columnAdd="<table><tr>";
foreach (var column in tableProperty.Columns)//emp-Employee,b-2,c-3
{
sql += "["+column.Key+"]" + " as [" + column.Value + "],";
columnAdd += "<th> "+column.Value+" </th>";
}
columnAdd += "</tr>";
sql=sql.TrimEnd(',');
sql += " from " + tableProperty.ReportTable;
sql = sql + " where 1=1 " + (string.IsNullOrEmpty(tableProperty.ReportCondition) ? "" : "and " + tableProperty.ReportCondition);
SqlConnection _con = new SqlConnection(@"server=mausam-pc\sqlexpress;uid=sa;pwd=ngc;initial catalog=HRMSN");
SqlCommand _cmd = new SqlCommand(sql, _con);
_con.Open();
SqlDataReader _reader = _cmd.ExecuteReader();
while (_reader.Read())
{
columnAdd += "<tr>";
foreach (var column in tableProperty.Columns)
{
columnAdd += "<td>" + _reader[_reader.GetOrdinal(column.Value)] + "</td>";
//columnAdd += _reader.GetOrdinal(column.Value);
}
columnAdd += "</tr>";
}
columnAdd += "</table></tr>";
string htmlread = "<html><title>General</title><body>"+ columnAdd +"</body></html>";
if (_reader != null)
{
_reader.Close();
}
_con.Close();
return htmlread;
}
public string HTMLToPdf(_TableProperty ReportProperty, string FilePath,Stream stream)
{
string htmlread2 = getReportHTML(ReportProperty, stream);
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\myPDF.pdf", FileMode.Create));
document.Open();
iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath("pdfic.jpg"));
pdfImage.ScaleToFit(100, 50);
pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(180, 760);
document.Add(pdfImage);
iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
iTextSharp.text.html.simpleparser.XHTMLWorker hw = new iTextSharp.text.html.simpleparser.XHTMLWorker(document);
hw.Parse(new StringReader(htmlread2));
document.Close();
ShowPdf("myPDF.pdf");
return htmlread2;
}
private void ShowPdf(string s)
{
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + s);
Mausam Bharati
9-Jul-13 7:48am
View
What will be Chap0101.pdf in case of table from database generated through a dll?
Mausam Bharati
9-Jul-13 7:47am
View
http://www.codeproject.com/Questions/203481/HTML-convert-to-PDF-using-itextsharp
I have taken this code as reference.
Mausam Bharati
9-Jul-13 7:45am
View
I am sorry but this ain't my problem. The issue is that the pdf page gets generated but no data gets displayed over it. Perhaps it is not reading the table from the database.
Show More