I'm using crystal reports to build reports, everything is ok while development.
But after deployment of website, print functionality doesn't work.
I use _rptDocument.PrintToPrinter(1, false, 0, 0); to print report.
I've tried two methods to deploy website
Normal Publish option.
Web Deployment Project.
But I got the same output, print functionality doesn't work.
Also, I tried to set default printer, this also doesn't work.
Any ideas?
Printing on a web server isn`t a good idea. What should happen? A user prints on your servers printer? Use CR to create PDFs. Stream them to your clients. They can use their local printers.
try this :- Create PDF and open Browser Tab ...enter code here
string fname = "Report" + ".pdf";`enter code here`
//Create instance for crystal report Export option class
ExportOptions exprtopt = default(ExportOptions);
//create instance for destination option - This one is used to set path of your pdf file save
DiskFileDestinationOptions destiopt = new DiskFileDestinationOptions();
//Bind data in the crystal report first before export cystal report to PDF
ReportDocument RptDoc = new ReportDocument();
//Map your crystal report path
// RD.Load(Server.MapPath("~/CrystalReport2.rpt"));
//Set your crystal report datasource as dt
//Get path and assign into destination DiskFileName
destiopt.DiskFileName = Server.MapPath(fname);
exprtopt = RD.ExportOptions;
exprtopt.ExportDestinationType = ExportDestinationType.DiskFile;
//use PortableDocFormat for PDF data
exprtopt.ExportFormatType = ExportFormatType.PortableDocFormat;
exprtopt.DestinationOptions = destiopt;
//finally export your report document
RD.Export();
//To open your PDF after save it from crystal report
string Path = Server.MapPath(fname);
//create instance to client to open your pdf
WebClient client = new WebClient();
//Assign path to download pdf
Byte[] buffer = client.DownloadData(Path);
//metion content type as PDF and write
// Response.ContentType = "application/pdf";
//Response.AddHeader("content-length", buffer.Length.ToString());
//Response.BinaryWrite(buffer);
//======================================
Response.Write("<script>");
Response.Write("window.open('" + fname + "', '_newtab');");
Response.Write("</script>");
//===================================
IMTIYAZ
Related
Thank you in advanced for your help.
I am new in this site.
I need to create a procedure to export .rpt to pdf. I am using parameters in .rpt because i am using sql stored procedure to create the report.
I am developing in asp.net 2008 with vb.
Regards.
I resolved my question.
This is the code, because if you need it.
Regards.
Dim PathFile As String = "c:\Documents" & "\Reporte.pdf"
formatType = ExportFormatType.PortableDocFormat
Dim oConexInfo As New CrystalDecisions.Shared.TableLogOnInfo
oConexInfo.ConnectionInfo.ServerName = "SERVER"
oConexInfo.ConnectionInfo.DatabaseName = "DBNAME"
oConexInfo.ConnectionInfo.UserID = "USERID"
oConexInfo.ConnectionInfo.Password = "PASSWORD"
rpt.Load(Server.MapPath("~/Imprime.rpt"))
rpt.SetParameterValue(0, Val(txt_No_Quotation.Text)) ' I send a parameter value
rpt.Database.Tables(0).ApplyLogOnInfo(oConexInfo) ' Here I send the credentials for conection to SQL Server with crystal reports
CrystalReportViewer1.ReportSource = rpt
ConfigureCRTSTALREPORT()
rpt.ExportToDisk(formatType, PathFile) ' Here I export the pdf to disk (in server side)
How can i Print a Pdf document through programmatically?
i am using the follwing code to print a PDF file.but when i click on print icon directly it starts printing.but i dont want it.
<asp:ImageButton ID="PrintButton" runat="server" ImageUrl="~/images/print-icon.png"
OnClick="PrintButton_Click" ToolTip="Print Document" />
My Cs Code is
protected void PrintButton_Click(object sender, EventArgs e)
{
ProcessStartInfo infoPrint = new ProcessStartInfo();
infoPrint.FileName = Session["filename"].ToString();
infoPrint.Verb = "PrintTo";
infoPrint.CreateNoWindow = true;
infoPrint.WindowStyle = ProcessWindowStyle.Normal;
infoPrint.UseShellExecute = true;
Process printProcess = new Process();
printProcess = Process.Start(infoPrint);
}
i want to open a print dialog box when the user clicks on print icon.if the user clicks on Print Button in Print dialog box then i want to start printing the document. My PDF file is in a folder on the server i want it to be printed through programmatically in asp.net.
this code will run on the server not the client. while developing the server and client are the same machine, your local workstation. Once deployed, this would execute on the server, not the user's local work station.
you can open a print dialog box using javascript
window.print();
However that will print the entire webapge, not the document specifically.
If you would like to print only the PDF, you need to stream the file to browser (not an entire webform). The user can then take advantage of the native print options within the adobe reader. There are many examples online about how to stream documents to the client's browser.
Have a look at This posst
this code add javascript line to print the pdf
Public Shared Function PrintJStoPDF(thePDF As Byte(), direct As Boolean) As Byte()
Dim BB As Byte() = Nothing
Using ms As New MemoryStream
Using reader As New PdfReader(thePDF)
Dim stamper = New PdfStamper(reader, ms)
Dim jsText As String = "var res = app.setTimeOut('this.print({bUI: true, bSilent: " & direct.ToString.ToLower & ", bShrinkToFit: false});', 200);"
stamper.JavaScript = jsText
stamper.FormFlattening = True
stamper.Writer.CloseStream = False
stamper.Close()
ms.Position = 0
BB = ms.ToArray
End Using
End Using
Return BB
End Function
I have a page called OrderExport.aspx which creates a pdf file in a folder on the server.
In my page OrderSend.aspx I have a function which sends an e-mail with the pdf file attached, like this:
Dim atc As Net.Mail.Attachment = New Attachment(stm, fileNameOrder)
mail.Attachments.Add(atc)
How can I call OrderExport.aspx from this function before sending the e-mail without showing it for the user?
I need to make sure that the pdf file exists when sending the e-mail.
You probably want to create a class rather than an aspx page to handle the PDF creation. One way to do this is to use the PDFSharp library which can handle creating the PDF document and then saving it to a stream which can be attach to an email message. You could also save the stream to a file on the server at the same time.
' Create a new PDF document
Dim document As PdfDocument = New PdfDocument
document.Info.Title = "TITLE"
Dim securitySettings As Security.PdfSecuritySettings = document.SecuritySettings
' Restrict some rights.
securitySettings.PermitAccessibilityExtractContent = False
securitySettings.PermitAnnotations = False
securitySettings.PermitAssembleDocument = False
securitySettings.PermitExtractContent = False
securitySettings.PermitFullQualityPrint = True
securitySettings.PermitModifyDocument = False
securitySettings.PermitPrint = True
' Create an empty page
Dim page As PdfPage = document.AddPage
' Get an XGraphics object for drawing
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
Dim img As XImage = XImage.FromGdiPlusImage(imgPermit)
gfx.DrawImage(img, 20, 20)
Dim stream As New MemoryStream()
document.Save(stream, False)
Dim xStream As System.IO.Stream = stream
SendEmail(sEmail, xStream)
in your mail message it would be constructed similar to this
Dim xStream As New Attachment(pdf, "FILE" + Date.Now.ToString("MM.dd.yyyy") + ".pdf")
mm.Attachments.Add(xStream)
You need to separate the GUI from the actual logic.
You presumably have code in OrderExport.aspx that creates the PDF and saves it to disk. You should put that code into a separate class, so that you can call it from OrderExport.aspx, and from the page with the "Send e-mail" button. Similarly, extract the code for sending the email from OrderSend.aspx and call it from there, and from the "Send e-mail" button.
Separation of Concerns is the best solution, but if you need a quick solution -not a good one- make the class and the function public and call it like any other class
I am trying to load an (.rdl) report file into a web report viewer control (visual studio 2010 control):
//Get the data and
.
.
//Add it to report
ReportViewer.LocalReport.DataSources.Add(new ReportDataSource(element.Name, dt));
//Pass the report to the viewer
using (FileStream stream = new FileStream(ReportDocument.FileName, FileMode.Open))
{
this.ReportViewer.LocalReport.LoadReportDefinition(stream);
}
Am I missing a line of code somewhere? I used the equivalent for the winforms report viewer with the addition of RefreshReport() - however there is no equivalent method that I could find for web report viewers). The page remains blank - what am I missing?
There is a .Refresh() method, and that is what you are missing. Here's what I'm using (in VB):
ReportViewer1.Reset()
ReportViewer1.LocalReport.Dispose()
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath = Server.MapPath("/reports/" & ReportFile)
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource(<datasource>))
ReportViewer1.LocalReport.Refresh()
I want to make a report from ASP.Net, in Crystal Report. I want, when user click on print, it should simply show a browser dialog of Save,Open,Save as, and PDF should be saved, or Crystal Report print preview should appear, I don't want to display report first in Viewer then click on button to get print or PDF, I want simply from clicking on asp button, I have all the idea of parameters and know how to make report, my question is just to not to show viewer and take report from asp button in a form of PDF or print preview dialog to print. I have used the Export method of .Net for Crystal Report, but it does not work.
You can generate a PDF by Using a Crystal Report and piece of code....
First: Generate a Crystal Report as per your requirements.
Second: Use the below code to generate the PDF:
Place the following name spaces at the top of the code page
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Variable Declaration
Dim CrReport As New CrystalReport1() // Report Name
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()
Set the destination path and file name
CrDiskFileDestinationOptions.DiskFileName = "c:\RichText.pdf"
Specify a page range (optional)
crFormatTypeOptions.FirstPageNumber = 1 // Start Page in the Report
crFormatTypeOptions.LastPageNumber = 3 // End Page in the Report
crFormatTypeOptions.UsePageRange = True
Set export options
CrExportOptions = crReport.ExportOptions
With CrExportOptions
// Set the destination to a disk file
.ExportDestinationType = ExportDestinationType.DiskFile
// Set the format to PDF
.ExportFormatType = ExportFormatType.PortableDocFormat
// Set the destination options to DiskFileDestinationOptions object
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = crFormatTypeOptions
End With
Trap any errors that occur on export
Try
// Export the report
CrReport.Export()
Catch err As Exception
MessageBox.Show(err.ToString())
End Try
Thats it.... Now you are ready to create a PDF of the Report.
Here is the solution you are looking for:
http://www.c-sharpcorner.com/UploadFile/mahesh/ExportCRtoPDF10062006161918PM/ExportCRtoPDF.aspx
Here is the quote from the site:
The following steps will guide you to achieve the same:
Add crystal report (.cr) file to your ASP.NET application.
Add a report instance on the page level.
Dim report As MyReport = New MyReport
Populate reports data on Page_Init
Dim ds As DataSet = GetData()
report.SetDataSource(ds)
Export Report
report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "ExportedReport")
If you wish to format report to other formats, just change the ExportFormatType enumeration value to > your desired format.
If you wish to download the report, then you simply change the third parameter of >ExportToHttpResponse method in Step 4 to True.