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

Print button #5

Open
arsoftinformatica opened this issue Dec 22, 2020 · 1 comment
Open

Print button #5

arsoftinformatica opened this issue Dec 22, 2020 · 1 comment

Comments

@arsoftinformatica
Copy link

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);

@q2a3z
Copy link

q2a3z commented Jun 10, 2024

Hi arsoftinformatica.
I have fixed some bug and added the print function based on the origal PdfiumViewer project.
If you want to ues it in your project, that will be help.
#20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants