Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom print action support #207

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions RdlGtkViewer/RdlGtkViewer/ReportViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public partial class ReportViewer : Gtk.Bin
private string connectionString;
private bool overwriteSubreportConnection;
private OutputPresentationType[] restrictedOutputPresentationTypes;
private Action<Pages> customPrintAction;

public event EventHandler ReportPrinted;

Expand Down Expand Up @@ -112,12 +113,14 @@ public ReportViewer()
/// <param name="connectionString">Relace all Connection string in report.</param>
/// <param name="overwriteSubreportConnection">If true connection string in subreport also will be overwrite</param>
/// <param name="restrictedOutputPresentationTypes">Restricts <see cref="OutputPresentationType"/> to chose from in export dialog</param>
public void LoadReport (Uri filename, string parameters, string connectionString, bool overwriteSubreportConnection = false, OutputPresentationType[] restrictedOutputPresentationTypes = null)
/// <param name="customPrintAction">>For use a custom print action</param>
public void LoadReport (Uri filename, string parameters, string connectionString, bool overwriteSubreportConnection = false, OutputPresentationType[] restrictedOutputPresentationTypes = null, Action<Pages> customPrintAction = null)
{
SourceFile = filename;

this.connectionString = connectionString;
this.overwriteSubreportConnection = overwriteSubreportConnection;
this.customPrintAction = customPrintAction;

LoadReport (filename, parameters, restrictedOutputPresentationTypes);
}
Expand Down Expand Up @@ -637,18 +640,25 @@ protected void OnPrintActionActivated(object sender, System.EventArgs e)
{
using (PrintContext context = new PrintContext(GdkWindow.Handle))
{
printing = new PrintOperation();
printing.Unit = Unit.Points;
printing.UseFullPage = true;
printing.DefaultPageSetup = new PageSetup();
printing.DefaultPageSetup.Orientation =
report.PageHeightPoints > report.PageWidthPoints ? PageOrientation.Portrait : PageOrientation.Landscape;

printing.BeginPrint += HandlePrintBeginPrint;
printing.DrawPage += HandlePrintDrawPage;
printing.EndPrint += HandlePrintEndPrint;

printing.Run(PrintOperationAction.PrintDialog, null);
if (customPrintAction == null)
{
printing = new PrintOperation();
printing.Unit = Unit.Points;
printing.UseFullPage = true;
printing.DefaultPageSetup = new PageSetup();
printing.DefaultPageSetup.Orientation =
report.PageHeightPoints > report.PageWidthPoints ? PageOrientation.Portrait : PageOrientation.Landscape;

printing.BeginPrint += HandlePrintBeginPrint;
printing.DrawPage += HandlePrintDrawPage;
printing.EndPrint += HandlePrintEndPrint;

printing.Run(PrintOperationAction.PrintDialog, null);
}
else
{
customPrintAction.Invoke(pages);
}
}
}

Expand Down