Solved

Creating PDF on the fly

Posted on 2006-11-01
6
409 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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