Skip to content

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

Description

@ComptonAlvaro

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions