Skip to content

Commit

Permalink
Merge pull request #207 from Art8m/feature/CustomPrintAction
Browse files Browse the repository at this point in the history
Adding custom print action support
  • Loading branch information
Gankov authored Oct 20, 2021
2 parents a445314 + 241f008 commit 1651b8b
Showing 1 changed file with 23 additions and 13 deletions.
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

0 comments on commit 1651b8b

Please sign in to comment.