Solved

Creating PDF on the fly

Posted on 2006-11-01
6
397 Views
Last Modified: 2011-04-14
I have an webform and I want to grab the information and create a pdf file without displaying crystal report and export.
In other words, creating pdf on the fly without loading crystal report.

Please forward me any solution


0
Comment
Question by:Hollie18502
6 Comments
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 17855629
hi,

u can use a freely available dll called itextsharp for this
follow this link
http://itextsharp.sourceforge.net/

b u d d h a
0
 
LVL 27

Expert Comment

by:Sammy
ID: 17856021
0
 
LVL 2

Expert Comment

by:grsekar
ID: 17856517
You still can design your report in crystal report and use the following code to display the output as pdf.
CrystalReportSource1 is the CrystalReportSource control.

        MemoryStream oStream;
        oStream = (MemoryStream)CrystalReportSource1.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(oStream.ToArray());
        Response.End();

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:Hollie18502
ID: 17858132
Grsekar... this sould doable, however, is there a way to save the pdf automatically, without the user have to do it.
0
 
LVL 2

Accepted Solution

by:
grsekar earned 500 total points
ID: 17866591
Hi
  User don't have to click export to save it . the above code will  create it for you.. i will give the complete sample for you. When the user navigate to this page itself they can see the pdf file. thery will never the crystal report.

Hope this helps you
---------------------------------------------
This following code is for aspx page
---------------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EmployeePDF.aspx.cs" Inherits="Purchase_EmployeePDF" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
 Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>eHRMS</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <CR:CrystalReportSource ID="crptDivision" runat="server">
      <Report FileName="..\Reports\EmployeeReport.rpt">
      </Report>
     </CR:CrystalReportSource>
   
    </div>
    </form>
</body>
</html>

-----------------------------------------------
Following code is for code behind file
-----------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
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 CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class Purchase_EmployeePDF : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        NameValueCollection ConnStrList = WebUtility.GetConnectionStingValueList();
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in crptDivision.ReportDocument.Database.Tables)
        {
            TableLogOnInfo logonInfo = table.LogOnInfo;
            logonInfo.ConnectionInfo.ServerName = ConnStrList["Data Source"];
            logonInfo.ConnectionInfo.DatabaseName = ConnStrList["Initial Catalog"];
            logonInfo.ConnectionInfo.Password = ConnStrList["Password"];
            logonInfo.ConnectionInfo.UserID = ConnStrList["User ID"];
            table.ApplyLogOnInfo(logonInfo);
        }
        MemoryStream oStream;
        crptDivision.ReportDocument.ParameterFields[0].CurrentValues.AddValue(int.Parse(Request.QueryString["period"]));
        oStream = (MemoryStream)crptDivision.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        Response.Clear();
        Response.Buffer = true;
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(oStream.ToArray());
        Response.End();
    }
}
0
 
LVL 2

Expert Comment

by:grsekar
ID: 17866613
hi code for WebUtility.GetConnectionStingValueList() function

public static NameValueCollection GetConnectionStingValueList()
    {
        string ConnStr = ConfigurationManager.ConnectionStrings["HRMS"].ToString();
        string[] constrArray = ConnStr.Split(';');
        NameValueCollection ConnStrList = new NameValueCollection();
        foreach (string strValue in constrArray)
        {
            if (!string.IsNullOrEmpty(strValue))
            {
            string[] tmp = strValue.Split('=');
            ConnStrList.Add(tmp[0], tmp[1]);
            }
        }
        return ConnStrList;
    }
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question