|
Rank: Newbie Groups: Member
Joined: 10/6/2011 Posts: 7
|
We have the ASPXToPDF1.RenderPDF() working great on our site. It converts the page to PDF when the user clicks the Conver to PDF button. Now, what we would like to do is instead of having it convert the entire page, we would like to have it only convert the Content portion of the page. This page pulls information from an SQL database and generates the page from that information. There is a dropdown box that allows us to choose the month for the statement we wish to look at, which refreshes the page. We only want to convert the Monthly Statement portion of the page - not all the navigation portions, etc. I am NEW to this, and am not sure how we can make this happen. If necessary, I can post the code for the page, etc. Please advise.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, This feature has just been added: http://doc.essentialobjects.com/library/4/htmltopdf/partial_page.aspxMake sure you download the latest build from our download page first since it did not exist in early versions. Please feel free to let us know if you still have any questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 10/6/2011 Posts: 7
|
Ok, I am confused. I have set VisualElementsIds = "PrintContents" in my code, and then in the ASPX page, I setup a <DIV ID="PrintContents"> around the area I wanted to be printed. But it is still converting the entire page. I am using ASPXToPDF1, not HTMLToPDF.
|
|
Rank: Newbie Groups: Member
Joined: 10/6/2011 Posts: 7
|
Here is the code for Monthlystatement.aspx.cs
Code: C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;
using EO.Pdf;
using EO.Pdf.Drawing;
using EO.Pdf.Acm;
using EO.Pdf.Contents;
using EO.Web;
using EO.Web.Internal;
public partial class Monthlystatement : BaseForm
{
public string VisualElementsIds;
protected void Page_Load(object sender, EventArgs e)
{
VisualElementsIds = "caption";
if (! IsPostBack)
{
Repeater1.DataSourceID = "objsourceheader";
Repeater1.DataBind();
if (Repeater1.Items.Count == 0)
{
Response.Redirect("accessdenied.aspx");
}
else
{
((DropDownList)frmviewHeader.Row.FindControl("ddldate")).SelectedIndex = 0;
hdnstatement.Value = ((DropDownList)frmviewHeader.Row.FindControl("ddldate")).SelectedValue;
}
}
}
protected void btnPDF_Click(object sender, EventArgs e)
{
//Export the current page as PDF
ASPXToPDF1.RenderAsPDF();
}
protected void ddldate_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
StatementBL objStatement = new StatementBL();
hdnstatement.Value = ((DropDownList)frmviewHeader.Row.FindControl("ddldate")).SelectedValue;
objsourceheader.SelectMethod = "GetStatementHeader";
frmviewHeader.DataSourceID = "objsourceheader";
frmviewHeader.DataBind();
//int statvalue = ((DropDownList)frmviewHeader.Row.FindControl("ddldate_SelectedIndexChanged")).SelectedIndex;
//DataTable dt ;
//dt = objStatement.GetStatementHeader(Convert.ToInt32(Session["Username"]),statvalue);
//((Label)frmviewHeader.Row.FindControl("lblpurchase")).Text = "$" + dt.Rows[0]["purchase"].ToString();
grdviewstatement.DataSourceID = "objsourcedetail";
grdviewstatement.DataBind();
grdviewtrail1.DataSourceID = "objsourcetrailor";
grdviewtrail1.DataBind();
//grdviewtrailor.DataSourceID = "objsourcetrailor";
//grdviewtrailor.DataBind();
}
catch (Exception ex)
{ }
}
protected void grdtrail_DataBound(object sender, EventArgs e)
{
// grdviewtrailor.Rows[0].Cells[4].Text = "$" + grdviewtrailor.Rows[0].Cells[4].Text;
}
}
|
|
Rank: Newbie Groups: Member
Joined: 10/6/2011 Posts: 7
|
Here is the code for Monthlystatement.aspx
Code: HTML/ASPX
<%@ Page Language="C#" MasterPageFile="MTA.master" AutoEventWireup="true" CodeFile="Monthlystatement.aspx.cs"
Inherits="Monthlystatement" Title="Monthly Statement" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="mainContent" runat="Server"><div id="PrintContents">
<asp:Repeater id="Repeater1" runat="server" >
</asp:Repeater>
<eo:ASPXToPDF ID="ASPXToPDF1" runat="server">
</eo:ASPXToPDF>
<asp:ObjectDataSource ID="objsourcedate" TypeName="StatementBL" runat="server" SelectMethod="GetStatementDate">
<SelectParameters>
<asp:SessionParameter SessionField="Username" Type="int32" Name="username" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="objsourceheader" TypeName="StatementBL" runat="server"
SelectMethod="GetStatementHeader">
<SelectParameters>
<asp:SessionParameter SessionField="Username" Type="int32" Name="username" />
<asp:ControlParameter ControlID="hdnstatement" Name="statement" Type="int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="objsourcedetail" TypeName="StatementBL" runat="server"
SelectMethod="GetStatementDetail">
<SelectParameters>
<asp:SessionParameter SessionField="Username" Type="int32" Name="username" />
<asp:ControlParameter ControlID="hdnstatement" Name="statement" Type="int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="objsourcetrailor" TypeName="StatementBL" runat="server"
SelectMethod="GetStatementTrailor">
<SelectParameters>
<asp:SessionParameter SessionField="Username" Type="int32" Name="username" />
<asp:ControlParameter ControlID="hdnstatement" Name="statement" Type="int32" />
</SelectParameters>
</asp:ObjectDataSource>
<%-- <div>--%>
<div id="caption">
Monthly Statement
<hr />
</div>
<asp:HiddenField ID="hdnstatement" runat="server" Value="0" />
<asp:ValidationSummary ID="ValidationClientSummary" HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList" EnableClientScript="true" ShowMessageBox="true" ShowSummary="false"
runat="server" ValidationGroup="contactgroup" />
<%-- <asp:Panel ID="Panel2" runat="server" CssClass="midpnl" Height="40">
--%>
<asp:FormView ID="frmviewHeader" runat="server" DataSourceID="objsourceheader" DefaultMode="Edit">
<EditItemTemplate>
<asp:Label ID="lblmonth" runat="server" CssClass="formlblbold">Select a month:</asp:Label>
<asp:DropDownList ID="ddlDate" runat="server" DataSourceID="objsourcedate" DataTextField="datestr"
DataValueField="statement" SelectedValue='<%# Eval("statement")%>' AppendDataBoundItems="true"
OnSelectedIndexChanged="ddldate_SelectedIndexChanged" AutoPostBack="true" Width="206">
</asp:DropDownList>
<asp:Panel ID="Panel2" runat="server" CssClass="midpnl" Width="570" Height="85px">
<asp:Panel ID="Panel3" runat="server" CssClass="leftpnl" Width="220" Height="80px">
<asp:Panel ID="Panel4" runat="server" CssClass="datapnl" Width="220">
<asp:Label ID="Label1" runat="server" CssClass="statementlabelleft">Member Name:</asp:Label>
<asp:Label ID="Label2" runat="server" CssClass="formlabelleftdisplay1" Text='<%# bind("account") %>'></asp:Label><br />
<asp:Label ID="Label3" runat="server" CssClass="statementlabelleft">Statement Date:</asp:Label>
<asp:Label ID="Label4" runat="server" CssClass="formlabelleftdisplay1" Text='<%# bind("statement_date") %>'></asp:Label><br />
<asp:Label ID="Label5" runat="server" CssClass="statementlabelleft">Total Purchase:</asp:Label>
<asp:Label ID="Label13" runat="server" CssClass="formlabelleftdisplay1" Text='<%# bind("hpurchase")%>' ></asp:Label>
<%-- "lblpurchase" runat="server" CssClass="formlabelleftdisplay1" Text=<%# "dollarfile('" + Eval("purchase") + "');return false;" %> ></asp:Label>
--%> </asp:Panel>
</asp:Panel>
<asp:Panel ID="Panel6" runat="server" CssClass="rightpnl" Width="310" Height="80px">
<asp:Panel ID="Panel7" runat="server" CssClass="datapnl" Width="310">
<asp:Label ID="Label7" runat="server" CssClass="statementlabelright">Company:</asp:Label>
<asp:Label ID="Label8" runat="server" CssClass="formlabelleftdisplay2" Text='<%# bind("company") %>'></asp:Label><br />
<asp:Label ID="Label9" runat="server" CssClass="statementlabelright">Cash Fees Due:</asp:Label>
<asp:Label ID="Label10" runat="server" Text='<%# bind("hcashfee") %>' CssClass="formlabelleftdisplay2"></asp:Label><br />
<asp:Label ID="Label11" runat="server" CssClass="statementlabelright">Total Sales:</asp:Label>
<asp:Label ID="Label12" runat="server" Text='<%# bind("hsales") %>' CssClass="formlabelleftdisplay2"></asp:Label>
</asp:Panel>
</asp:Panel>
</asp:Panel>
<%--
"Panel1" runat="server" CssClass="midpnl" Width="570">
<asp:Label ID="lblmembername" runat="server" CssClass="statementlabelleft" Font-Bold="true">MemberName:</asp:Label>
<asp:Label ID="lbltmembername" runat="server" CssClass="formlabelleftdisplay" Text='<%# bind("account") %>'></asp:Label><br />
<asp:Label ID="lblCompany" runat="server" CssClass="statementlabelright" Font-Bold="true">Company:</asp:Label>
<asp:Label ID="lbltCompany" runat="server" CssClass="formlabelleftdisplay" Text='<%# bind("company") %>'></asp:Label><br />
<asp:Label ID="lblStatementDate" runat="server" CssClass="statementlabelleft" Font-Bold="true">StatementDate:</asp:Label>
<asp:Label ID="lbltStatementDate" runat="server" CssClass="formlabelleftdisplay"
Text='<%# bind("statement_date") %>'></asp:Label><br />
<asp:Label ID="lblCashfee" runat="server" CssClass="statementlabelright" Font-Bold="true">Cash Fee Due:</asp:Label>
<asp:Label ID="lbltCashfee" runat="server" Text='<%# bind("cashfee") %>' CssClass="formlabelleftdisplay"></asp:Label><br />
<asp:Label ID="lblTotalPurchase" runat="server" CssClass="statementlabelleft" Font-Bold="true">Total Purchase:</asp:Label>
<asp:Label ID="lbltTotalPurchase" runat="server" CssClass="formlabelleftdisplay"
Text='<%# bind("purchase") %>'></asp:Label>
<asp:Label ID="lblsales" runat="server" CssClass="statementlabelright" Font-Bold="true">Total Sales:</asp:Label>
<asp:Label ID="lbltsales" runat="server" Text='<%# bind("sales") %>' CssClass="formlabelleftdisplay"></asp:Label>
</asp:Panel>--%>
<%-- "lblmembername" runat="server" CssClass="memberinfolabelleft" Font-Bold="true">MemberName:</asp:Label>
<asp:Label ID="lbltmembername" runat="server" CssClass="formlabeldisplay" Text='<%# bind("account") %>'></asp:Label><br />
<asp:Label ID="lblStatementDate" runat="server" CssClass="memberinfolabelleft">Statement Date:</asp:Label>
<asp:Label ID="lbltStatementDate" runat="server" CssClass="formlabeldisplay" Text='<%# bind("statement_date") %>'></asp:Label><br />
<asp:Label ID="lblTotalPurchase" runat="server" CssClass="memberinfolabelleft">Total Purchase:</asp:Label>
<asp:Label ID="lbltTotalPurchase" runat="server" CssClass="formlabeldisplay" Text='<%# bind("purchase") %>'></asp:Label>
<asp:Label ID="lblCompany" runat="server" CssClass="memberinfolabelright">Company</asp:Label>
<asp:Label ID="lbltCompany" runat="server" CssClass="formlabeldisplay" Text='<%# bind("company") %>'></asp:Label><br />
<asp:Label ID="lblCashfee" runat="server" CssClass="memberinfolabelright">Cash Fee Due:</asp:Label>
<asp:Label ID="lbltCashfee" runat="server" Text='<%# bind("cashfee") %>' CssClass="formlabeldisplay"></asp:Label><br />
<asp:Label ID="lblsales" runat="server" CssClass="memberinfolabelright">Total Sales:</asp:Label>
<asp:Label ID="lbltsales" runat="server" Text='<%# bind("sales") %>' CssClass="formlabeldisplay"></asp:Label>
--%>
</EditItemTemplate>
</asp:FormView></div>
<%--</asp:Panel>
--%>
<%-- class="formlabelbold">
Quick Contact Form :
<asp:Label ID="lblResult" runat="server" ForeColor="red"></asp:Label>
<%-- </div>--%>
<asp:GridView ID="grdviewstatement" runat="server" DataSourceID="objsourcedetail"
CssClass="grid" SkinID="afterloginGrid" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Date" DataField="date" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Description" HeaderStyle-Width ="200" DataField="description" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Card No." DataField="card_number" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Auth#" DataField="authorization" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Purchases" DataField="purchase_amount" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Sales" DataField="sales_amount" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Cash" DataField="cash_fee" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Fees Paid" DataField="payment" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
</Columns>
</asp:GridView>
<br />
<asp:GridView ID="grdviewtrail1" runat="server" DataSourceID="objsourcetrailor" CssClass="grid"
SkinID="afterloginGrid" AutoGenerateColumns="false" Width="575">
<Columns>
<asp:TemplateField HeaderText="Previous Balance" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="100" />
<ItemTemplate>
<asp:Label ID="lbltsale" runat="server" Text='<%#Eval("previous_balance")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Sales" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="100" />
<ItemTemplate>
<asp:Label ID="lbltsale" runat="server" Text='<%#Eval("tsales")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Purchase" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="100" />
<ItemTemplate>
<asp:Label ID="lbltpurchase" runat="server" Text='<%#Eval("tpurchases")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Balance" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="100" />
<ItemTemplate>
<asp:Label ID="lbltcbal" runat="server" Text='<%#Eval("tcurrent_balance")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Credit Line" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="100" />
<ItemTemplate>
<asp:Label ID="lblcreditline" runat="server" Text='<%#Eval("tcredit_line")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Available" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="100" />
<ItemTemplate>
<asp:Label ID="lbltavailable" runat="server" Text='<%#Eval("ttotal_available")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- <asp:BoundField HeaderText="Total Sales" DataField="sales" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>--%>
<%--<asp:BoundField HeaderText="Total Purchase" DataField="purchases" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>--%>
<%--<asp:BoundField HeaderText="CurrentBalance" DataField="current_balance" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>--%>
<%-- <asp:BoundField HeaderText="Credit Line" DataField="credit_line" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>--%>
<%--<asp:BoundField HeaderText="Total Available" DataField="total_available" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>--%>
</Columns>
</asp:GridView>
<br />
<asp:GridView ID="grdviewtrailor" runat="server" DataSourceID="objsourcetrailor"
CssClass="grid" SkinID="afterloginGrid" AutoGenerateColumns="false" Width="575">
<Columns>
<%-- <asp:BoundField HeaderText="Previous Cash Fees" DataField="previous_fees" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Currenct Cash Fees" DataField="current_fees" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Fees Paid" DataField="fees_paid" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>
<asp:BoundField HeaderText="Cash Fee Due Upon Receipt" DataField="fees_due" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="right" />
</asp:BoundField>--%>
<asp:TemplateField HeaderText="Previous Cash Fees" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="150" />
<ItemTemplate>
<asp:Label ID="lbltpfees" runat="server" Text='<%#Eval("tprevious_fees")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Current Cash Fees" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="150"/>
<ItemTemplate>
<asp:Label ID="lblcfees" runat="server" Text='<%#Eval("tcurrent_fees")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fees Paid" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="150"/>
<ItemTemplate>
<asp:Label ID="lbltfeespaid" runat="server" Text='<%#Eval("tfees_paid")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cash Fee Due Upon Receipt" HeaderStyle-HorizontalAlign="center">
<ItemStyle HorizontalAlign="Center" Width="150"/>
<ItemTemplate>
<asp:Label ID="lblfeesdue" runat="server" Text='<%#Eval("fees")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<br />
<%--</div>--%>
<script type="text/javascript" language="javascript">
//document.forms[0].ctl00$mainContent$frmviewHeader$Label13.value='$5555';
//document.getElementById("lblfeesdue").value='$44.34';
// document.forms[0].ctl00$mainContent$grdviewtrailor$lblfeesdue.value='$5555';
// function dollarfile(args)
// {
// document.forms[0].ctl00$ContentPlaceHolder1$frmviewHeader$lblpurchase.value='$'+args;
// }
</script>
<asp:Button ID="btnPDF" runat="server"
Text="Convert to PDF"
OnClick="btnPDF_Click" />
</asp:Content>
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, VisualElementsIds is a property on OUR HtmlToPdfOptions object. It's not a variable that you define in your code. Whatever variable you define in your code are your variables, they have nothing to do with us. You will need to do something like this BEOFRE calling RenderAsPDF:
Code: C#
EO.Pdf.HtmlToPdf.Options.VisibleElementIds = "your_id";
You also need to refernece EO.Pdf.dll in order for the above code to compile. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 10/6/2011 Posts: 7
|
Thank you. That fixed it.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
You are very welcome. Please feel free to let us know if there is anything else.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 10/6/2011 Posts: 7
|
Ok, well there is something else. Actually, two things. 1. Add the option to save the file to a different name than the name of the web page (currently Monthlystatement) - if possible, save it to the something like MTA_August2011_Statement.pdf, where the month/year would come from a value in the drop down box in our code. 2. Insert a banner at the top of the page stating the customer name (pulled from the information on the statement), the month/year of the statement (i.e. August 2011), and Monthly MTA Statement in bold letters.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, As to your question: 1. You call this function: http://doc.essentialobjects.com/library/1/eo.web.aspxtopdf.renderaspdf_overload_1.aspx2. You set this property: http://doc.essentialobjects.com/library/4/eo.pdf.htmltopdfoptions.headerhtmlformat.aspxYou can also take a look of Demos -> HtmlToPdf -> Basic -> HeaderFooter sample in the demo application for more details. That sample demonstrates this feature. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 10/6/2011 Posts: 7
|
Again, many thanks to you. I will look at the samples, as well as the links you have posted here. Being new to all of this .NET stuff, it helps to have people like you willing to point us in the right direction.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
You are very welcome. It's our pleasure to be able to help.
|
|