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

Is it possible to print user controls with ghostscript? #100

Open
ComptonAlvaro opened this issue Apr 25, 2022 · 0 comments
Open

Is it possible to print user controls with ghostscript? #100

ComptonAlvaro opened this issue Apr 25, 2022 · 0 comments

Comments

@ComptonAlvaro
Copy link

Until now, to print a user control to PDF I create a fixed document, a fixed page and I add the user control to the page. Then I call the print dialog to select the printer.

The problem is that if the use control has an image as backgruound, the Microsoft to PDF printer doesn't work, I get an empty page. So I was wondering if it is possible to use GhostScript to print user controls.

I look the examples, but I am not sure how I could print a user control.

The code that I am using until now is the following:

private void Imprimir()
{
ControlUsuarioParaImprimir miControlUsuarioParaImprimir = new ControlUsuarioParaImprimir();

        FixedDocument miDocumento = new FixedDocument();


        miControlUsuarioParaImprimir.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
        miControlUsuarioParaImprimir.Arrange(new Rect(miControlUsuarioParaImprimir.DesiredSize));
        miControlUsuarioParaImprimir.UpdateLayout();

        Size miTamañoPagina = new Size(miControlUsuarioParaImprimir.ActualWidth, miControlUsuarioParaImprimir.ActualHeight);


        FixedPage miPagina1 = new FixedPage();
        miPagina1.Width = miTamañoPagina.Width;
        miPagina1.Height = miTamañoPagina.Height;
        miPagina1.Children.Add(miControlUsuarioParaImprimir);


        PageContent miContenido1 = new PageContent();
        ((IAddChild)miContenido1).AddChild(miPagina1);

        miDocumento.Pages.Add(miContenido1);


      //From here, coud I use GhostScript to print my fixed document???

        System.Windows.Controls.PrintDialog myDialog = new System.Windows.Controls.PrintDialog();

        if (myDialog.ShowDialog() == true)
        {
            try
            {
                //Print the image.
                myDialog.PrintDocument(miDocumento.DocumentPaginator, string.Empty);
            }
            catch
            {
                //@#MEJORAR: realmente una librería nunca debería tener un messagebox. Se tiene que lanzar una excepción.
                MessageBox.Show("El documento no se ha podido crear.\r\n\r\n"
                    + "Si está abierto y se está intentando sobreescribir, se recomienda cerrar el documento antes"
                    + " de imprimirlo.");
            }
        }
    }

Thanks.

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

1 participant