hi i need some help in pdf generation in crystal reports.The Scenario is ,the user can select multiple values from the grid view for which pdf files are generated on clicking a print button.As of now if the user selects 2 details and click print button 2 pdf files are created .But I need to change the functionality in such a way that the report of records selected by user should be saved in a single pdf file irrespective of the number of records .
the code am currently using is
rprt.SetDataSource(rptDataSet);
rprt.ExportToDisk(ExportFormatType.PortableDocFormat, filePath);
DiskFileDestinationOptions dfdo = ExportOptions.CreateDiskFileDestinationOptions();
ExportOptions eo = new ExportOptions();
eo.ExportFormatType = ExportFormatType.PortableDocFormat;
eo.ExportDestinationType = ExportDestinationType.DiskFile;
dfdo.DiskFileName = filePath;
eo.ExportDestinationOptions = dfdo;
rprt.Export(eo);
I think you have two options (maybe more):
Modify the crystal report slightly by adding a new grouping on your "primary key". Then you can just pass the dataset for all highlighted records and one pdf will be created
Export each pdf separately then "stuff" them together
Systems I use take the first approach- i think it's more efficient.
EDIT As requested- i've attached a sample invoice report which is used for printing batches of invoices. Group 2 is on {LT_INVOICE.TRANSACTIONID} which will be unique for each invoice.
Related
I have created a MVC project to view my crystal report. What I want to do now is export my crystal report to some specific file formats (PDF, Word, CSV etc). Before exporting the file I want to open my file explorer and give a name to the file, select export type, select specific folder and export it.
How can I do this?
Not sure if this works the same while using ASP.NET.
private string SelectLocation(string fileName)
{
SaveFileDialog brwsr = new SaveFileDialog();
brwsr.FileName = fileName;
brwsr.Filter = "Pdf|*.pdf";
//Check to see if the user clicked the cancel button
if (brwsr.ShowDialog() == DialogResult.Cancel)
return "";
else
{
string newDirectoryPath = brwsr.FileName;
return newDirectoryPath;
}
}
This is a piece of code to find out which path they want to use to save the file.
If you use a Crystal Report Viewer to display the report on-screen, there are controls within the viewer that would allow a user to export the report and choose the export format and the folder and filename where it is saved. Some of your users may need some training to make effective use of some of the export parameters though. For example, when exporting to Excel there are a number of additional export parameters that can be used.
The nice thing about this method of exporting reports is the export feature is already fully implemented and all you have to code for is the creation and display of the report.
I am using PDFSharp to add a bookmark to page one of a PDF document for a client. The client is providing multiple PDF documents with varying pages and each PDF is a single bill for a person. The client asked me to put the account number in a bookmark on the first page so they can combine them together and process a single PDF with many bills using the bookmark as a means to identify the account number.
I successfully created the bookmark using the following code, but when the client combines the files together using Ghostscript, all bookmarks are assigned to page 1 on the combined PDF. When they combine other PDF's from another system that essentially does the same thing the bookmarks display as desired on the combined file. I am not sure what they are doing differently to make this work.
How can I get the bookmark to be set correctly so it is maintained when combined?
string file = "c:/test.pdf";
string accountNumber = "001234";
using (PdfDocument doc = PdfReader.Open(file, PdfDocumentOpenMode.Modify))
{
PdfPage page = doc.Pages[0];
doc.Outlines.Add(accountNumber, page);
doc.Save(file);
}
I figured it out. Although redundant since the second parameter in Outlines.Add() is setting the destination page, I just needed the following line:
outline.DestinationPage = page;
I currently have a program that merges a folder consisting of word docs into one combined file via user input with a FileBrowserDialog. Once files are selected, a 'combine' button applies the code shown below which sources the folder containing the documents, output location and name of the file created.
string fileDate = DateTime.Now.ToString("dd-MM-yy");
string fileTime = DateTime.Now.ToString("HH.mm.ss");
string outcomeFolder = outputFolder;
string outputFileType = ".docx";
string outputFile = "Combined Folder " + fileDate + " # " + fileTime + outputFileType;
string outputFileName = Path.Combine(outcomeFolder, outputFile);
// Combines the file name, output path selected and the yes / no for pagebreaks.
MsWord.Merge(sourceFiles, outputFileName, pageBreaker);
// Message displaying how many files are combined.
MessageBox.Show("A total of " + sourceFiles.Length.ToString() + " documents have been merged", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);}
The MsWord referenced calls a separate .CS file which combines the folder components, output name and a boolean to enable page-breaks. The MsWord also automatically saves the word .doc to the user specified location once the contents of the folder are successfully combined. MsWord.Merge(sourceFiles, outputFileName, pageBreaker);
The issue i'm wanting to address is, when I enable this check box:
if (convert2PDFBox.Checked)
Microsoft.Office.Interop.Word.Application officeApp = new Microsoft.Office.Interop.Word.Application();
officeApp.Documents.Open(outputFileName);
outputFileType = ".pdf";
officeApp.ActiveDocument.SaveAs(outputFileName + outputFileType, WdSaveFormat.wdFormatPDF);
officeApp.Quit();
I want the program to solely create a PDF of the combined folder and not 2 seperate .doc and .PDF files, which it currently does. Since the MsWord.save function is called separately and is essential to the overall function of my program, I was wondering is there a possibility of deleting the initially combined file once conversion of the PDF takes place? e.g. "combinedDocument".Delete - Essentially allowing the copy to take place however not presenting the user with the initial .doc - only the .PDF
Though the issue is small, I would love to get it addressed and welcome any suggestions or advice with this manner. I can also provide any additional information if needed, thank you.
tl;dr - merging program creates an amalgamated Word .doc, which i want to change solely to a PDF when a checkbox is enabled instead of creating a .doc and PDF.
I finally resolved my issue - What I decided to do was manipulate my existing MsWord.cs and create a separate PDF.cs call for my main form:
Rather than save the Word .doc when being merged, I instead used: wordApplication.ActiveDocument.SaveAs(outputFile, Word.WdSaveFormat.wdFormatPDF);
which saved the merged content thus far as a .pdf
This however presented errors with Microsoft Word as I was then prompted to 'Save File As' due to the merged file never actually being saved in a .Doc / .Docx format
I then altered the closing statement of the call,
// Close Word application
wordApplication.Quit(
false, // save changes
By setting the 'Save Changes' setting to False, it removed the 'Save As' prompt which allowed the Word doc. to be dismissed without needing to be saved, thus leaving only the initial PDF created. I then applied the two separate File type calls to each checkbox presented, which allowed the user to enable the outcome format of the merged files.
Thank you for the suggestions regarding the issue.
I'm trying to break a multi page crystal report into multiple files by page and name according from their respective fields. I've been fooling around with the code from this question however I run into all type of SAP error's. Is there not a simple way to iterate say like:
foreach(var page in CrystalReport)
{
report.ExportTiDisk(ExportFormatType.WordForWindows, page.[NameField]);
}
Worst case I could do this with the Word API but that another can of worms I'd rather not open.
Thank you in advance
Dear please check the code.
Why you need to export in multiple files, it is bad as suppose you have a report with 300 pages result, then are you think to make 300 files to export and customer to check each & every files. Think again.
Still here is solution, Please refer to the following VB.Net code for exporting to seperate pdf files.
Dim rdoc As New ReportDocument
'------------------------------------
'Add your code to set rdoc object
'--------------------------------------
Dim exportOpts As ExportOptions = New ExportOptions()
Dim pdfRtfWordOpts As PdfRtfWordFormatOptions = ExportOptions.CreatePdfRtfWordFormatOptions()
Dim destinationOpts As DiskFileDestinationOptions = ExportOptions.CreateDiskFileDestinationOptions()
For li_count As Integer = 1 To pagecount
pdfRtfWordOpts.FirstPageNumber = li_count
pdfRtfWordOpts.LastPageNumber = li_count
pdfRtfWordOpts.UsePageRange = True
exportOpts.ExportFormatOptions = pdfRtfWordOpts
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat
destinationOpts.DiskFileName = "D:\report File" & li_count & ".pdf"
exportOpts.ExportDestinationOptions = destinationOpts
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
rdoc.Export(exportOpts)
Next
refer link export in multiple file
You have not written your CR-version, So please refer to this link also which says, not able to export in multiple files in cr-2008.
http://social.msdn.microsoft.com/Forums/en-US/f85e167d-edb3-44d0-82fc-2d2b6f92f57b/how-do-i-export-multiple-pdf-files-from-a-single-crystal-report-ie-a-pdf-file-for-each?forum=vscrystalreports
http://scn.sap.com/thread/1132776
The process of splitting a report in multiple files is known as bursting. You can split by group , not by page. However splitting by group will allow you to split based on the data , not by mechanical reason like page number. As a result if you have a customer with more data which is printed on 2 pages the report will be spitted correctly and the generated file for this customer will be 2 pages too. Bursting is a little bit complicate to develop but there are few tools on the market that can do it. Check this video :
http://www.r-tag.com/Pages/Preview_Bursting.aspx
I believe the tool in this video is free.
I am making one application where user will print invoices which I am displaying using Crystal Report.
The user showed me his current application made using ForPro. In that application, under Printer Options form, one can see all the printers currently installed and the user could select default printer. When the invoice is made, the user presses the print button, then there is one dialog asking for no. of copies. When it's entered, the invoice gets printed directly, without any Print Dialog Box. If the user wants to change the printer again he/she will change it in the Printer Option form.
I want to know if similar thing is possible in Crystal Report and need guidance on how to approach for it.
Take a look at the ReportDocument.PrintToPrinter SAP Docs or MSDN Docs for how to specify the PrinterName and then Print using the ReportDocument object.
If you can try and get away from how the FoxPro app UI for printer selection. Instead use the standard print dialog box to select the printer.
You should note that if you don't set the PrinterName before sending the report to the printer it will use the default on the crystal file. Not to be confused with the user's OS default printer.
Here's an example of showing the PrintDialog settings some parameters using the SetParameterValue method and then sending the report document to a printer
// Note: untested
var dialog = new PrintDialog();
Nullable<bool> print = dialog.ShowDialog();
if (print.HasValue && print.Value)
{
var rd = new ReportDocument();
rd.Load("ReportFile.rpt");
rd.SetParameter("Parameter1", "abc");
rd.SetParameter("Parameter2", "foo");
rd.PrintOptions.PrinterName = dialog.PrinterSettings.PrinterName;
rd.PrintToPrinter(1, false, 0, 0);
}
The code above no longer works as advertised which has been admitted by SAP
You need to set the report document to an ISCDReportClientDocument and then print it. This is a more robust way of making sure the print job doesn't go to the default printer. The last two lines can be replaced with this code.
CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions printReportOptions = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
CrystalDecisions.ReportAppServer.Controllers.PrintOutputController printOutputController = new CrystalDecisions.ReportAppServer.Controllers.PrintOutputController();
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
rptClientDoc = cryRtp.ReportClientDocument;
printReportOptions.PrinterName = pDialog.PrinterSettings.PrinterName;
rptClientDoc.PrintOutputController.PrintReport(printReportOptions);
Here is another good link
http://mattruma.azurewebsites.net/?p=258