Solved

Creating PDF on the fly

Posted on 2006-11-01
6
413 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 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