C# winforms RDLC report direct print to printer - c#

I created an app with VS2017 C# WinForms, created a report for a table inside with RDLC reportviewer, the report is working well, I want to print this report directly and send it to the printer without popping up print preview dialog.
Please be informed that I googled this issue and searched this site as well and I couldn't find a solution.
Tried to use the MSDN topic (Walkthrough: Printing a Local Report without Preview) but still no luck.
Here is my button which runs several queries including opening a form (voucher) containing an rdlc reportviewer which loads data to show up in the report:
private void button12_Click(object sender, EventArgs e)
{
SoundPlayer player = new SoundPlayer(Properties.Resources.switch_8);
player.Play();
if (string.IsNullOrWhiteSpace(textBox1.Text) || textBox1.Text == "0")
{
MessageBox.Show("Please select an item!");
}
else
{
MOVE_TO_SOLD();
UPDATE_RECEIPT();
LOAD_DATA();
CLEAR_TEMP();
CHECK_FOR_REC_ID();
GET_NEW_REC_ID();
LOAD_DATA();
txtdiscount.Text = "0";
textBox5.Text = "0";
recowner.Text = recnum.Text;
voucher vr = new voucher();
vr.ShowDialog();
}
}
Thank You!

This Walkthrough will be very helpful for your problem. Please check it out, and if this answer was helpful, mark it as an answer.

Related

Inconsistent behaviour axAcroPDF

I have a pdf viewer which for the sake of the example, displays selected filename from a listbox.
It is a simple form with a listbox an axAcroPDF and textbox to confirm correct filepath.
The code is as follows and the files have been placed in a folder pdfs in the Debug folder:
using System;
using System.Windows.Forms;
namespace pdf_viewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "pdfs\\" + listBox1.SelectedItem.ToString();
textBox1.Text = path;
InitializeAdobe(path);
}
private void InitializeAdobe(string filePath)
{
axAcroPDF1.LoadFile(filePath);
axAcroPDF1.src = filePath;
axAcroPDF1.setShowToolbar(false);
axAcroPDF1.setView("Fit");
axAcroPDF1.setLayoutMode("SinglePage");
axAcroPDF1.Show();
}
}
}
It all works correctly with a few issues:
the first time you cycle through the files it displays correctly in the window but if you go back to an entry, the second time it shows the toolbar at the right despite this being disabled in the code. The toolbar takes up the bulk of the window.
When you close the window, it takes and inordinately long time to close, indicating to me there is a lot of housekeeping going on. Any clues on why this would be happening.
In addition to this:
do I need both .LoadFile and .src statements in the code as both work in isolation but is one preferable to the other. Doesn't seem to change the above issues. This method was lifted from another Stack Overflow question.
Thanks
PS Since originally posting, I have tried to display in a webBrowser window but exactly the same thing happens with the toolbar panel displaying the second time you select an entry.
The code is as follows:
webBrowser1.Url = new Uri(path);
Revisited this problem after a very long time and found the answer here
Disable Adobe Reader toolbar from my ActiveX
It appears to work in an axAcroPDF and webbrowser window.
For the axAcropdf the code to display pdf without displaying the toolbar is (using question example):
this.axAcroPDF1.src = filePath + "#toolbar=0";
this.axAcroPDF1.setView("Fit");
this.axAcroPDF1.setLayoutMode("SinglePage");
this.axAcroPDF1.Show();
For webbrowser window
InitializeAdobe(path);
webBrowser1.Url = new Uri(path + "#toolbar=0");

Customize Report Viewer

I used Report Viewer in my winforms applications to generate my reports.
I need to customize it to limit the target export type to Excel and Word type ie avoid the PDF export.
How can I accomplish this task?Any suggestions?
I added this snippet in the ReportExport event
private void reportViewer1_ReportExport(object sender, ReportExportEventArgs e)
{
if (e.Extension.Name.ToLower() == "pdf")
{
reportViewer1.LocalReport.Refresh();
reportViewer1.RefreshReport();
}
}
It works fine

How to load the telerik report in reportviewer?

I am trying to load the telerik report on win form where i have a report viewer to show it ... But I am not successfull to load it. I am not getting its code working write. I want to make it on form load .
private void Form1_Load(object sender, EventArgs e)
{
//Code here to load telerik
}
Any way to load it like crystal report can load
{
crystalReportViewer1.ReportSource = (#"C:\Users\CrystalReport1.rpt");
}
errors I am getting when I am do this
{
Telerik.Reporting.TypeReportSource typeReportSource = new Telerik.Reporting.TypeReportSource();
typeReportSource.TypeName = "Telerik.Reporting.Examples.CSharp.ListBoundReport, CSharp.ReportLibrary";
this.reportViewer1.ReportSource = typeReportSource;
reportViewer1.RefreshReport();
}
What I normally do is to deign the report inside VS in a class library. I then reference the class library in the application, ASP or Winforms. In your case, Winforms, once you have added your class library to the bin, select the "Report Source" from the report viewer properties and add the report from a path or selecting your class library. Thats it.
For more reference, have a look here.

PowerPoint Open "Record Slide Show" Dialog and detect if Presentation has a recording c# addin

I am developing a PowerPoint AddIn and have been asked to add a reminder to the user to "Record Slide Show".
Can anyone help me find out how to programmatically open the "Record Slide Show" dialog box and also how to detect if the user has already added a recording to the slide show please?
Many thanks
Trevor
Finally got this to work.
In the ribbon I have added the following:
public static void callRecordDialog()
{
Globals.ThisAddIn.Application.CommandBars.ExecuteMso("RecordNarration");
}
then in the form I have called it like this...
private void btnVoiceOverYes_Click(object sender, EventArgs e)
{
vCreateRibbon.callRecordDialog();
this.Close();
}
took ages to find that!
hope it helps someone else
Trev

Printing a dwf/dwfx file from WPF

I'm currently attempting to print a document from WPF. I'm using the web browser because it contains an active x control which has the autodesk plugin which I need to view the document.
I'm aware that WPF doesn't directly support web browser but I've just integrated the Windows Forms library for this. I've managed to get the code running and even printing, however the document that prints is blank.
I'm not sure if it could possibly be a conflict between the Windows Forms library and WPF; I'm navigating to the document and only printing once it's loaded with no errors thrown.
Here's the code I'm using:
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.WebBrowser w = new System.Windows.Forms.WebBrowser();
Uri uri = new Uri("C:\\BOS-BD-4518-000.dwg.dwf");
w.Navigate(uri);
w.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(w_DocumentCompleted);
}
void w_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
System.Windows.Forms.WebBrowser w = (System.Windows.Forms.WebBrowser)sender;
w.Print();
}
One possible hitch could be that the active x control is not being allowed to be load, does anyone know how to force the control to be initialised.
Does anyone have any ideas about how to solve this or another method of printing an autodesk (.dwf) document
Thanks in advance,
SumGuy
Not really an answer of sorts but a solution if anyone out does want to print a .dwf file. Don't, use the new form .dwfx. This is the new file type Autodesk are switching too and its actually a form of XPS which makes things quite easy. You can load it into a web browser without needing active x OR (this is the better way) use the XPS libraries in visual studio because it can be loaded very simply into an XPS viewer.
The code I eventually used to print the dreaded file is below:
private PrintQueue printQueue;
PrintDialog pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
if (pDialog.ShowDialog() == true)
PrintSystemJobInfo xpsPrintJob = printQueue.AddJob(v.FileName, v.FilePath, false);
How easy's that??? There are loads of other ways of doing it using XPS. You can basically just use the dwfx file as an XPS document

Categories