Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating PDF on the fly

Posted on 2006-11-01
6
Medium Priority
?
427 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 Ageil
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

877 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