locked
Silverlight pages printing, issue with size and quality RRS feed

  • Question

  • We are working on a Silverlight 4.0 application which requires printing of XAML Forms (Pages). These are standard Tax Forms that include the text, lines and other controls in addition to 1D and 2D barcodes. The print quality (position and resolution) is important as they have to conform to IRS specifications. We are using SilverPDF library to print at client side. We are facing series performance and quality issues as SilverPDF converts the forms to Bitmap and then sends to printer. For 10 pages, we see almost close to 1GB is getting sent to printer. Here is the code for printing…

    Any help on this is highly appreciated.

      private void PrintPDF(List<FrameworkElement> printPages)
            {
                var output = new SaveFileDialog { Filter = "PDF Files | *.pdf" };
                if (output.ShowDialog() == true)
                {
                    PdfDocument document = new PdfDocument();
                    foreach (var view in printPages)
                    {
                        //var width = double.IsNaN(view.Width) ? 816 : view.Width;
                        //var height = double.IsNaN(view.Height) ? 1056 : view.Height;
                        PdfSharp.Pdf.PdfPage page = document.AddPage();
                        XImage pdfImage = DrawTaxPageUI(view);
                        XGraphics gfx = XGraphics.FromPdfPage(page);
                        gfx.SmoothingMode = PdfSharp.Drawing.XSmoothingMode.AntiAlias;
                        gfx.DrawImage(pdfImage, 10, 10);
                    }
                    document.Save(output.OpenFile());
                }
            }
    
            private XImage DrawTaxPageUI(FrameworkElement oControl)
            {
                oControl.Opacity = 1;
                ImageTools.ExtendedImage img = ImageExtensions.ToImage(oControl);
                var mstream = new MemoryStream();
                //ImageTools.IO.Bmp.BmpEncoder encoder = new ImageTools.IO.Bmp.BmpEncoder();
                //ImageTools.IO.Png.PngEncoder encoder = new ImageTools.IO.Png.PngEncoder();
                var encoder = new JpegEncoder();
                encoder.Quality = 100;  //0 for lowest quality
                encoder.Encode(img, mstream);
                mstream.Seek(0, SeekOrigin.Begin);
                var pdfImg = XImage.FromStream(mstream);
                return pdfImg;
            }

    Saturday, April 7, 2012 8:45 PM

Answers

  • You can try with

    http://silverlightpdf.codeplex.com/discussions/241386

    It uses FJCore Library to convert png to jpg to decrease image size.

    Monday, April 9, 2012 10:17 PM

All replies

  • Hi hnarisetty,

    I advised you to use Crystal Report with Silverlight 4.

    http://www.global-webnet.net/blogengine/post/2009/01/06/Running-Crystal-Reports-from-Silverlight.aspx  

    We are using Silverlight with Crystal Report with no Problem. 

    Regards

    Jack

    Sunday, April 8, 2012 11:55 AM
  • You can try with

    http://silverlightpdf.codeplex.com/discussions/241386

    It uses FJCore Library to convert png to jpg to decrease image size.

    Monday, April 9, 2012 10:17 PM
  • We have a Silverlight 4.0 business application that needs to support printing of generate XAML-based Forms (Silverlight Pages). These business forms can include the text, lines and other silverlight controls in addition to 1D and 2D barcodes. The print quality (position and resolution) is important as they have to conform to certain specifications.

     
    The Silverlight-4 native printing capability is currently used to print the forms. We are facing an issue with the amout of time it takes to print a document with typically 10+ pages. We traced it to the document print job  size which is significantly large (around 1GB for 10 pages).   This is because the Silverlight-4 uses bitmap based printing. When print function is invoked from the application, Silverlight-4 sends the output to the printer as bitmap rather than using vector based output, resulting larger files being sent to the printer. The recently released Silverlight-5 framework has resolved this issue by providing support for vector printing.

    We did a proof-of-concept using Silverlight 5 as we understand it uses vector printing (as opposed to Silverlight 4 that uses bitmap based printing) that significantly reduces the size of the print job. Our research shows that the Print method of the

    However, Silverlight-5 PrintDocument class uses the vector printing mode only when the printer is PostScript-enabled. Since the printing is executed at the customer-end we cannot obviously prescribe a Postscript printer. We need a solution for this situation as well.

    In summary, we are looking for a solution that

    minimizes the print document size

    minimizes the time to complete the print job and

    supports both postscript and non-postscript printers

    This is a critical business problem that we need to solve quickly. Any ideas or feedback will be very hepful.

    Monday, April 9, 2012 11:57 PM
  • Have you received an answer to this problem?

    We have a large project over SL5 and we have the same problem.

    The only way to solve (temporaly) this issue was using Poscript printers and deleting all images from our forms...

    Today I realize that it's a new SL version (5.1.10411.0 - Release date May 11, 2012) but it doesn't include any fix  for printing issues.

    Tuesday, July 10, 2012 12:40 PM