Skip to content
This repository was archived by the owner on Apr 22, 2026. It is now read-only.
This repository was archived by the owner on Apr 22, 2026. It is now read-only.

Print button #5

@arsoftinformatica

Description

@arsoftinformatica

Hello, I'm sending a code that I found in the stackoverflow to print the document in pdf, if you can implement this option, thank you.

public bool PrintPDF(PdfDocument document , string printer, string paperName, string filename, int copies)
{
try
{
// Create the printer settings for our printer
var printerSettings = new PrinterSettings
{
PrinterName = printer,
Copies = (short)copies,
};

            // Create our page settings for the paper size selected
            var pageSettings = new PageSettings(printerSettings)
            {
                Margins = new Margins(0, 0, 0, 0),
            };
            foreach (PaperSize paperSize in printerSettings.PaperSizes)
            {
                if (paperSize.PaperName == paperName)
                {
                    pageSettings.PaperSize = paperSize;
                    break;
                }
            }

            // Now print the PDF document

                using (var printDocument = document.CreatePrintDocument())
                {
                    printDocument.PrinterSettings = printerSettings;
                    printDocument.DefaultPageSettings = pageSettings;
                    printDocument.PrintController = new StandardPrintController();
                    printDocument.Print();
                }
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

var ret = PrintPDF(Renderer.Document,"Microsoft Print to PDF", "A4", dialog.FileName, 1);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions