PrintDialogX 2.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package PrintDialogX --version 2.1.1                
NuGet\Install-Package PrintDialogX -Version 2.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PrintDialogX" Version="2.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PrintDialogX --version 2.1.1                
#r "nuget: PrintDialogX, 2.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PrintDialogX as a Cake Addin
#addin nuget:?package=PrintDialogX&version=2.1.1

// Install PrintDialogX as a Cake Tool
#tool nuget:?package=PrintDialogX&version=2.1.1                

PrintDialogX

C# Subsystem Nuget Lincense

A custom PrintDialog for WPF with preview in realtime. Full options with printer settings, include copies, custom pages, orientation, color, quality, scale, pages-per-sheet, double-sided, paper size, paper type, paper source, etc. Support realtime updates to the content according to the changes in settings. Fast and elegant user interface.

Preview

Screenshot

Features

PrintDialogX is a powerful and beautiful customized print dialog. It basically supports all functions with the default Windows print dialog, but also provides extra functions and realtime previews. The printer settings only use the given printer's allowed options. The document being printed is also flexible and available for changes in content according to the adjusted settings by the user. The show-while-generate-document feature also allows a fast and user-friendly experience, where the document is generated dynamically while the print dialog is preparing itself.

  • Printer list
    • Printer icons & status
    • "Add New Printer" button
    • Tooltip on printer options for detailed information
  • Printer settings
    • Copies and collate
    • Pages (all, current, or custom)
    • Orientation
    • Color and quality
    • Pages per sheet and page order
    • Scale and margin
    • Doubled-sided and flipping
    • Paper size, type, and source
  • Interactable realtime preview
    • Zooming and text selection
    • Page position and navigation
  • Updatable document
    • Document reloading callback for specfic printer settings
    • Realtime update on the content
  • Result callback
    • Whether the "Print" button is clicked or the "Cancel" button
    • The number of papers used
  • Beautiful user interface
    • Uses Wpf.Ui
    • Customizable disabling of certain settings

Dependencies

  • .Net Framework >= 4.8
  • Wpf.Ui = 3.0.0

How to Use

The example project is included on GitHub in the PrintDialogX.Test subfolder, with both examples of the show-while-generate-document feature, where the document is generated while the print dialog is showing, and the old method of generating the document beforehand and showing the print dialog after.

Initialize a PrintDialog instance.

//Initialize a PrintDialog and set its properties
PrintDialogX.PrintDialog.PrintDialog printDialog = new PrintDialogX.PrintDialog.PrintDialog()
{
    Owner = this, //Set PrintDialog's owner
    Title = "Test Print", //Set PrintDialog's title
};

The show-while-generate-document feature allows the document to be generated while the PrintDialog is loading. GeneratingDocument is a function that will be called to generate the document.

//Show PrintDialog with document generation function
//The document will be generated while the dialog loads
if (printDialog.ShowDialog(GeneratingDocument) == true)
{
    //When the Print button is clicked, the document is printed, and the window is closed
    MessageBox.Show("Document printed.\nIt uses " + printDialog.TotalPapers + " sheet(s) of paper.", "PrintDialog", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
}
else
{
    //When the Cancel button is clicked and the window is closed
    MessageBox.Show("Print job canceled.", "PrintDialog", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
}

Example of the GeneratingDocument function, where the document is created.

private void GeneratingDocument()
{
    //Create a new document
    //PrintDialogX requires a PrintDocument instance as the document
    PrintDialogX.PrintDocument document = new PrintDialogX.PrintDocument();
    document.DocumentSize = new Size(96 * 8.25, 96 * 11.75); //A4 paper size, 8.25 inch x 11.75 inch
    document.DocumentMargin = 60; //Default margin

    //Loop 5 times to add 5 pages
    for (int i = 0; i < 5; i++)
    {
        //Create a new page and add content to it
        PrintDialogX.PrintPage page = new PrintDialogX.PrintPage();
        page.Content = CreateContent(); //Create any content as you wish

        //Add the page into the document
        document.Pages.Add(page);
    }

    //Set the PrintDialog's document
    printDialog.Document = document;
}

If the document is already created, PrintDialog.ShowDialog() can be called to skip the loading part.

//Generate the document before showing the dialog
printDialog.Document = document;

//Show PrintDialog with the document already generated
if (printDialog.ShowDialog() == true)
{
    //When the Print button clicked, the document is printed, and the window is closed
    MessageBox.Show("Document printed.\nIt uses " + printDialog.TotalPapers + " sheet(s) of paper.", "PrintDialog", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
}
else
{
    //When the Cancel button is clicked and the window is closed
    MessageBox.Show("Print job canceled.", "PrintDialog", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
}

Default print settings of the PrintDialog can be set as well.

//Set default print settings
printDialog.DefaultSettings = new PrintDialogX.PrintDialog.PrintDialogSettings()
{
    Layout = PrintDialogX.PrintSettings.PageOrientation.Portrait,
    Color = PrintDialogX.PrintSettings.PageColor.Color,
    Quality = PrintDialogX.PrintSettings.PageQuality.Normal,
    PageSize = PrintDialogX.PrintSettings.PageSize.ISOA4,
    PageType = PrintDialogX.PrintSettings.PageType.Plain,
    DoubleSided = PrintDialogX.PrintSettings.DoubleSided.DoubleSidedLongEdge,
    PagesPerSheet = PrintDialogX.PrintSettings.PagesPerSheet.One,
    PageOrder = PrintDialogX.PrintSettings.PageOrder.Horizontal
};
//PrinterDefaultSettings() can also be used to use default settings of the printer
//printDialog.DefaultSettings = PrintDialog.PrintDialogSettings.PrinterDefaultSettings()

The interface of the PrintDialog can be customized and certain settings can be disabled.

printDialog.AllowScaleOption = true; //Allow scale option
printDialog.AllowPagesOption = true; //Allow pages option (contains "All Pages", "Current Page", and "Custom Pages")
printDialog.AllowDoubleSidedOption = true; //Allow double-sided option
printDialog.AllowPagesPerSheetOption = true; //Allow pages per sheet option
printDialog.AllowPageOrderOption = true; //Allow page order option
printDialog.AllowAddNewPrinterButton = true; //Allow add new printer button in the printer list
printDialog.AllowMoreSettingsExpander = true; //Allow more settings expander
printDialog.AllowPrinterPreferencesButton = true; //Allow printer preferences button

PrintDialog.ReloadDocumentCallback can be set for updatable documents, where the content of the document can be updated based on print settings. The callback function needs to receive a PrintDialog.DocumentInfo as the parameter and needs to return a list of PrintPage.

//Set the function that will use to recreate the document when the print settings changed
printDialog.ReloadDocumentCallback = ReloadDocumentCallback;
private List<PrintDialogX.PrintPage> ReloadDocumentCallback(PrintDialogX.PrintDialog.DocumentInfo documentInfo)
{
    //Optinal callback function to recreate the page contents with the specific settings
    List<PrintDialogX.PrintPage> pages = new List<PrintDialogX.PrintPage>();

    //All pages should be recreated
    //PrintDialog will take care of the pages setting regarding of which pages need to be printed
    //The DocumentInfo.Pages info can still be used such as to adjust pages that will be printed
    for (int i = 0; i < 5; i++)
    {
        //Create the new page and recreate the content with the specific margin
        PrintPage page = new PrintPage();
        page.Content = CreateContent(); //Things like documentInfo.Size and documentInfo.Margin can be used
        pages.Add(page);
    }

    //Passed the recreated document back to the PrintDialog
    return pages;
}

License

This project is under the MIT License.

Product Compatible and additional computed target framework versions.
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.4 106 9/30/2024
2.1.2 238 3/10/2024
2.1.1 133 3/3/2024
2.0.2 133 2/25/2024