PrintDialogX 2.1.2
See the version list below for details.
dotnet add package PrintDialogX --version 2.1.2
NuGet\Install-Package PrintDialogX -Version 2.1.2
<PackageReference Include="PrintDialogX" Version="2.1.2" />
paket add PrintDialogX --version 2.1.2
#r "nuget: PrintDialogX, 2.1.2"
// Install PrintDialogX as a Cake Addin #addin nuget:?package=PrintDialogX&version=2.1.2 // Install PrintDialogX as a Cake Tool #tool nuget:?package=PrintDialogX&version=2.1.2
PrintDialogX v2.1.2
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
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
};
Synchronized Document Generation
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;
}
Pre-Generated 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);
}
PrintDialog Configurations
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
Dynamic Updatable Document
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- WPF-UI (>= 3.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.