ThinkGeo.com    |     Documentation    |     Premium Support

Printing Clarity

I use the following to do my printing, and when I print directly to a printer it comes through sharp and clear. When I print to PDF I am getting fuzzy lettering and faded colors. I assume it is my printing setting through PDF Printer, but changing them to highest quality and DPI doesn’t appear to make any difference. Has anyone had similar experience when printing to PDF vs printing to printer? Or is there a better method I should use when printing maps?

                            foreach (var nme in printerInteractiveOverlay.PrinterLayers)
                            {
                                var pagePrinterLayer = nme as PagePrinterLayer;
                                if (pagePrinterLayer == null)
                                    continue;

                                var printDocument = new System.Drawing.Printing.PrintDocument();
                                printDocument.DefaultPageSettings.Landscape = true;
    
                                printDocument.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer);
                                System.Drawing.Bitmap bitmap = null;
                                    bitmap = new System.Drawing.Bitmap((int)pagePrinterLayer.GetBoundingBox().Width, (int)pagePrinterLayer.GetBoundingBox().Height);
                                    PlatformGeoCanvas gdiPlusGeoCanvas = new PlatformGeoCanvas();
                                    gdiPlusGeoCanvas.BeginDrawing(bitmap, pagePrinterLayer.GetBoundingBox(), _sheetMapkitMap.MapUnit);

                                    // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
                                    // except for the PagePrinterLayer                
                                    Collection<SimpleCandidate> labelsInAllLayers1 = new Collection<SimpleCandidate>();
                                    foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)
                                    {
                                        printerLayer.IsDrawing = true;
                                        if (!(printerLayer is PagePrinterLayer))
                                        {
                                            printerLayer.Open();
                                            printerLayer.Draw(gdiPlusGeoCanvas, labelsInAllLayers1);
                                        }
                                        printerLayer.IsDrawing = false;
                                    }

                                    // End the drawing
                                    gdiPlusGeoCanvas.EndDrawing();


                                    prntDialog.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;
                                    using (MemoryStream memory = new MemoryStream())
                                    {
                                        bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
                                        memory.Position = 0;
                                        BitmapImage bitmapImage = new BitmapImage();
                                        bitmapImage.BeginInit();
                                        bitmapImage.StreamSource = memory;
                                        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                                        bitmapImage.EndInit();

                                        StackPanel myPanel = new StackPanel();
                                        //myPanel.Margin = new Thickness(15);
                                        Image myImage = new Image();
                                        myImage.Width = useThisSize.Height.Value;
                                        myImage.Stretch = System.Windows.Media.Stretch.Uniform;
                                        myImage.Source = bitmapImage;
                                        myPanel.Children.Add(myImage);
                                        myPanel.Measure(new Size(useThisSize.Height.Value,
                                            useThisSize.Width.Value));
                                        myPanel.Arrange(new Rect(new Point(0, -50),
                                        myPanel.DesiredSize));

                                        var pageSize = new Size(useThisSize.Height.Value, useThisSize.Width.Value);
                                        var fixedPage = new System.Windows.Documents.FixedPage();
                                        fixedPage.Width = pageSize.Width;
                                        fixedPage.Height = pageSize.Height;
                                        // Add visual, measure/arrange page.
                                        fixedPage.Children.Add(myPanel);
                                        fixedPage.Measure(pageSize);
                                        fixedPage.Arrange(new Rect(new Point(), pageSize));
                                        fixedPage.UpdateLayout();

                                        var pageContent = new System.Windows.Documents.PageContent();
                                        ((IAddChild)pageContent).AddChild(fixedPage);
                                        document.Pages.Add(pageContent);
                                        break;
                                    }
                            }
                           prntDialog.PrintDocument(document.DocumentPaginator, "My Document");

Hi Jake,

I tested our print sample here: https://github.com/ThinkGeo/PrintPreviewSample-ForWpf

It looks the PDF result looks well.

I compare the code, and found our sample draw the features into PdfPage and your code draw into BitMap. I think your fuzzy shape maybe because the stretching, that’s maybe because the map size is not suitable your PDF page size.

Please try our sample and see whether you can print your layer well by our sample code. if it still have problem please upload a simple sample so we can see how to help you.

Regards,

Ethan