Solved

Creating PDF on the fly

Posted on 2006-11-01
6
378 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now