wpcubed.com Forum Index wpcubed.com
WPCubed GmbH Support Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to create a report template from an HTML file

 
Post new topic   Reply to topic    wpcubed.com Forum Index -> wPDFControl/RTF2PDF
View previous topic :: View next topic  
Author Message
jkourany



Joined: 18 Feb 2010
Posts: 1

PostPosted: Fri Feb 19, 2010 12:03 am    Post subject: How to create a report template from an HTML file Reply with quote

I am trying to evaluate the use of RTF2PDF /TextDynamic Server with the Reporting Option from withing an ASP.NET application. The objective is to have the end user create document templates in HTML (such as an Invoice Template) and produce a PDF file from the given template. To accomplish this I use the following procedure:


1. Create an HTML file containning apropiate fields , groups, headers and footers using the reporting template syntax of your control.

2. load the HTML file into an RTF2PDF control memo property
3. perform TokenToTemplate conversion using [[ and ]] as start/end markers
4. invoke CreateReport method
5. use onReportState and onFieldGetText events to supply field data.

The problem I am having with the demo DLL is that the OnReportState event never gets fired, only the OnFieldGetText gets fired. It seems that report template functionality is not active or enabled in this version. Am I doing something wrong????

Below is the code and html file used:

public partial class html2pdf : System.Web.UI.Page
{
SqlConnection dbConn = null;
SqlCommand spQuoteHdr = null;
SqlCommand spQuoteDet = null;
SqlDataReader qHdr = null;
SqlDataReader qDet = null;
protected void Page_Load(object sender, EventArgs e)
{
int bookID = Convert.ToInt32(Session["BID"]);
int quoteID = 382;
int revID = 0;

dbConn = framework.getSqlConnection();
dbConn.Open();
try
{
spQuoteHdr = getQuoteHdr(dbConn);
spQuoteHdr.Parameters["@pBookID"].Value = bookID;
spQuoteHdr.Parameters["@pQuoteID"].Value = quoteID;
spQuoteHdr.Parameters["@pRevID"].Value = revID;


spQuoteDet = getQuoteDet(dbConn);
spQuoteDet.Parameters["@pBookID"].Value = bookID;
spQuoteDet.Parameters["@pQuoteID"].Value = quoteID;
spQuoteDet.Parameters["@pRevID"].Value = revID;
spQuoteDet.Parameters["@pFshowGroups"].Value = true;
spQuoteDet.Parameters["@pFshowMaterials"].Value = false;

buildReport();
}
finally
{
dbConn.Close();
dbConn.Dispose();
}


}
public void buildReport()
{
string fileName = Server.MapPath(sys.framework.getTempPath()) + "htmlSample.html";
if (File.Exists(fileName))
{
wPDF.RTF2PDF p = new wPDF.RTF2PDF();
p.SetLicense("---", "---", 0);
p.Memo.LoadFromFile(fileName, false, "html");



//p.Memo.TextCommandStr(17, 0, "[[\r\n]]\r\n:\r\n#");

IWPTextCursor cursor = p.Memo.TextCursor;
cursor.FieldsFromTokens("[[", "]]", "");

p.OnReportState += new RTF2PDF.ReportStateEvent(p_OnReportState);
p.OnFieldGetText += new RTF2PDF.FieldGetTextEvent(p_OnFieldGetText);
p.Report.CreateReport();

p.PdfCreator.PDFFile = "memory";
p.PdfCreator.FontMode = 0;
p.PdfCreator.CIDFontMode = 0;
p.PdfCreator.PrintSecond();

Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("Content-Disposition", "inline;filename=" + "htmlTest" + ".pdf");
Response.BinaryWrite(p.ResultBuffer);
}
}

private SqlCommand getQuoteHdr(SqlConnection dbConn)
{
SqlCommand sp = new SqlCommand("slpGetQuoteHdrP", dbConn);
sp.CommandType = CommandType.StoredProcedure;
sp.Parameters.Add(new SqlParameter("@pBookID",SqlDbType.Int,4,ParameterDirection.Input,true,0,0,"",DataRowVersion.Current,0));
sp.Parameters.Add(new SqlParameter("@pQuoteID",SqlDbType.Int,4,ParameterDirection.Input,true,0,0,"",DataRowVersion.Current,0));
sp.Parameters.Add(new SqlParameter("@pRevID",SqlDbType.Int,4,ParameterDirection.Input,true,0,0,"",DataRowVersion.Current,0));
sp.Parameters.Add(new SqlParameter("@RETURN_VALUE",SqlDbType.Int,4,ParameterDirection.ReturnValue,true,0,0,"",DataRowVersion.Current,0));
return sp;

}

private SqlCommand getQuoteDet(SqlConnection dbConn)
{
SqlCommand sp = new SqlCommand("slpGetQuoteHdrP", dbConn);
sp.CommandType = CommandType.StoredProcedure;
sp.Parameters.Add(new SqlParameter("@pBookID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, 0));
sp.Parameters.Add(new SqlParameter("@pQuoteID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, 0));
sp.Parameters.Add(new SqlParameter("@pRevID", SqlDbType.Int, 4, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, 0));
sp.Parameters.Add(new SqlParameter("@pFshowGroups", SqlDbType.Bit, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, 0));
sp.Parameters.Add(new SqlParameter("@pFshowMaterials", SqlDbType.Bit, 1, ParameterDirection.Input, true, 0, 0, "", DataRowVersion.Current, 0));
sp.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, true, 0, 0, "", DataRowVersion.Current, 0));
return sp;
}

private void p_OnReportState(object Sender, string Name,int State, WPDynamic.IWPReportBand Band,ref bool Abort)
{

switch (State)
{
case 0:
switch (Name)
{
case "quoteHdr":
qHdr = spQuoteHdr.ExecuteReader();
Abort = !qHdr.Read();
break;
case "quoteDet":
qDet = spQuoteDet.ExecuteReader();
Abort = !qDet.Read();
break;
}
break;
case 8:
switch (Name)
{
case "quoteHdr":
Abort = true;
break;
case "quoteDet":
Abort = !qDet.Read();
break;
}
break;
}

}


private void p_OnFieldGetText(object Sender, int Editor, string FieldName, WPDynamic.IWPFieldContents Contents)
{
string[] field = FieldName.Split('.');
SqlDataReader q = null;
switch (field[0])
{
case "quoteHdr": q = qHdr;break;
case "quoteDet": q = qDet;break;
}
int fieldIndex = q.GetOrdinal(field[1]);
if (fieldIndex >= 0)
{
if (Contents.FieldObject() != null && Contents.FieldObject().ObjType == TextObjTypes.wpobjImage)
{
string fn = FieldName;
}
else
switch (q.GetDataTypeName(fieldIndex))
{
case "System.Int32":
case "System.Decimal":Contents.FloatValue = q.GetDouble(fieldIndex);break;
default: Contents.StringValue = q.GetString(fieldIndex); break;
}
}


}


The following is the HTML file:


<body>
[[#quoteHdr "hdr"]]
[[:HEADER/]]
<p><img style="WIDTH: 276px; HEIGHT: 61px" alt="" src="file:///c:/projectsWeb/iQuotev3/logicware.jpg" width="392" height="112" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" border="1" cellspacing="0" bordercolor="#999999" cellpadding="5">
<tbody>
<tr>
<td style="TEXT-ALIGN: left; WIDTH: 50%; VERTICAL-ALIGN: top">
<p><strong><span style="FONT-FAMILY: Tahoma; FONT-SIZE: 8pt">Bill to:</span></strong></p>
<div style="MARGIN: 10px"><strong>[[quoteHdr.cLegalName]]</strong><br />[[quoteHdr.cAddress]]</div></td>
<td style="TEXT-ALIGN: left; WIDTH: 50%; VERTICAL-ALIGN: top">
<p><strong><span style="FONT-FAMILY: Tahoma; FONT-SIZE: 8pt">Ship to:</span></strong></p>
<div style="MARGIN: 10px"><strong>[[quoteHdr.sLegalName]]</strong><br />[[quoteHdr.sAddress]]</div></td></tr></tbody>
</table>
[[:DATA/]]
[[#quoteDet "det"]]
[[:HEADER/]]
<table style="BORDER-COLLAPSE: collapse; with: 700px" border="0" cellspacing="0" bordercolor="#000000" cellpadding="3">
<tbody>
<tr style="BACKGROUND-COLOR: #000000; COLOR: #ffffff; FONT-SIZE: 10pt">
<td style="WIDTH: 400px">Details</td>
<td style="TEXT-ALIGN: center; WIDTH: 100px">Qty</td>
<td style="TEXT-ALIGN: center; WIDTH: 100px">Unit Price</td>
<td style="TEXT-ALIGN: center; WIDTH: 100px">Total Extended</td>
</tr>
</tbody>
</table>
[[:DATA/]]
<table style="BORDER-COLLAPSE: collapse; width: 700px" border="0" cellspacing="0" bordercolor="#000000" cellpadding="3">
<tbody>
<tr>
<td style="WIDTH: 400px">
<div style="WIDTH: 400px; FONT-FAMILY: Tahoma; MARGIN-BOTTOM: 15px"><strong>[[quoteDet.itemName]] ([[quoteDet.itemID]])</strong></div>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="WIDTH: 120px; VERTICAL-ALIGN: top"><img style="FLOAT: left" alt="" src="file:///c:/projectsweb/iQuotev3/post.jpg" width="92" height="81" /> </td>
<td style="WIDTH: 250px; FONT-FAMILY: Tahoma; FONT-SIZE: 8pt; VERTICAL-ALIGN: top">[[quoteDet.specs]]</td>
</tr>
</tbody>
</table>
</td>
<td style="TEXT-ALIGN: center; WIDTH: 100px; VERTICAL-ALIGN: top">[[quoteDet.qty]]</td>
<td style="TEXT-ALIGN: right; WIDTH: 100px; VERTICAL-ALIGN: top">[[quoteDet.price]]</td>
<td style="TEXT-ALIGN: right; WIDTH: 100px; VERTICAL-ALIGN: top">[[quoteDet.totalExtended]]</td>
</tr>
</tbody>
</table>
[[/quoteDet]]
<div>&nbsp;</div>
<div><strong>Payment Terms:</strong></div>
<address>50% Cash in advance</address>
<address>50% against PO</address>
[[/quoteHdr]]
</body>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    wpcubed.com Forum Index -> wPDFControl/RTF2PDF All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group