ThinkGeo.com    |     Documentation    |     Premium Support

Raster stretch using PrinterGeoCanvas

Hi there,

I’m using the printerGeoCanvas to print out a specific area of the map (see below)

As you can see, the polygons align with the raster image behind it, but on actual print, the vector features are in the correct position, but the raster seems stretched from the top left corner of the MapPrinterLayer and then gives this result:

This only seems to be an issue for printerGeoCanvas, PDFGeoCanvas and PlatformGeoCanvas show the expected results.

The attached code is what is used to send to printer:

// Handle sending the page to the printer
private void ubtnPrint_Click(object sender, EventArgs e)
{

        //PrintDialog settings
        PrintDialog printDlg = new PrintDialog();
        // (a)(1) Set up the print document
        PrintDocument printDocument = new PrintDocument();
        printDlg.Document = printDocument;
        printDlg.AllowSelection = false;
        printDlg.AllowSomePages = false;
        printDlg.Document.DefaultPageSettings.Landscape = pagePrinterLayer.Orientation == PrinterOrientation.Landscape;
        printDlg.Document.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer);
        printDlg.Document.DefaultPageSettings.Margins = new Margins(GetMarginInHInch(),
            GetMarginInHInch(), GetMarginInHInch(), GetMarginInHInch());
        printDlg.Document.OriginAtMargins = false;
        if (printDlg.ShowDialog() == DialogResult.OK)
        {
            // (b) Set up PrinterGeoCanvas
            PrinterGeoCanvas printerGeoCanvas = new PrinterGeoCanvas();
            printerGeoCanvas.DrawingArea = printDlg.Document.DefaultPageSettings.Bounds;
            printerGeoCanvas.DrawingQuality = DrawingQuality.HighQuality;
            printerGeoCanvas.ClippingArea = pagePrinterLayer.GetBoundingBox();
            var simpleCandidates = new Collection<SimpleCandidate>();
            printerGeoCanvas.BeginDrawing(printDlg.Document, pagePrinterLayer.GetBoundingBox(), mapPrinterLayer.MapUnit);
            foreach (PrinterLayer layer in printerOverlay.PrinterLayers)
            {
                layer.Draw(printerGeoCanvas, simpleCandidates);
            }
            printerGeoCanvas.EndDrawing();
        }
    }

On another less pressing issue, the scalebar printer layer appears to be slightly misaligned, as the black bar parts of the scale bar appear to float up and left ever so slightly. (I’m unable to show an example of this).

I hope to hear from you soon,

Regards,

Zak

Hi Zak,

It’s not a known issue for us, and because we don’t have a group vector and raster data to reproduce that, only read logic is hard to find the problem. So could you please built a simple sample with small data? You can build that quickly follow this guide: http://wiki.thinkgeo.com/wiki/map_suite_project_template_guide

Please make sure upgrade all the packages to latest version in sample project.

Regards,

Ethan

Hi Ethan,

Please find the example attached, which shows the raster issue.

The file was too large to upload here, so I’ve uploaded it to my google drive, which you can access here:

https://drive.google.com/file/d/1P0F46RXEOHrS3ZyxwwaBwOoH274oev_C/view?usp=sharing

Regards,

Zak

Hi Zak,

In fact we don’t allowed to download data from 3rd part network disk, and it looks your share file cannot be visit without permission.

So could you please upload the data to our FTP? You can get your account via your sales.

Regards,

Ethan

Hi Ethan,

I have now sent a copy of the example to the FTP.

I have removed the packages from the project to reduce the upload size.

Regards,

Zak

Hi Zak,

Thanks for your update, our developer will look into it when he back to work, any question or update I will let you know.

Regards,

Ethan

Hi Zak,

We get your data and reproduce that, the solution is add this line:

printerGeoCanvas.Dpi = 100;

That’s because the default value of printer geocanvas is 96 but printer document is 100, reset the value can solve that.

PrinterGeoCanvas_dpi_100.pdf (574.1 KB)

Regards,

Ethan

Hi Ethan,

Thank you, that has fixed the issue.

Were you able to recreate the problem of the black parts of the scale bar being misaligned with the rest of the scale bar?

Regards,

Zak

Hi Zak,

We cannot reproduce that, if you found how to reproduce it please show us the screen shots or the steps so we can look into it.

Regards,

Ethan

Hi Ethan,

It is noticeable on the example I have shared if you zoom in on the scale bar. It might be marginal, but it shows up worse once it’s printed off.

Regards,

Zak

Hi Zak,

That’s strange because when I tested that, the scale bar works well, could you please let us know how to reproduce that, for example some special extent?

Regards,

Ethan

Hi Ethan,

It was done using my example. When printing, the extent is programmed to stay the same in this example.

I’ve tried loads of different extents and scales and they all show the same results for the scale bar.

Is the one you’re showing me in the print preview screen? Or is it on a printed version?

Zak

Hi Zak,

Our developer had fixed that.

Please try the sample, and the package in sample is the fixed version.

8947.zip (2.1 MB)

Regards,

Ethan

Hi Ethan,

Sorry for the long reply but I’ve been away.

The solution works and the scale bar is now showing up fine.

Thank you for all your help.

Regards,

Zak

Hi Zak,

I am glad to hear that works.

Any question please let us know.

Regards,

Ethan

Hi, sorry for reviving an old topic but I’m working in this area and picking up on some of what Zak had done. The fix to set printerGeoCanvas.Dpi = 100 worked fine, however people are pushing us to print at significantly higher resolutions as the printed raster quality is considerably below what it could be.

I tried printerGeoCanvas.Dpi = 300 but that, not too surprisingly, exaggerates the original problems. I thought I could get there by setting the printer document to the same value, but have not been able to work out how to do that. I tried a few things, such as:

        PrintDocument printDocument = new PrintDocument();

        PrinterResolution printerResolution = new PrinterResolution();
        printerResolution.Kind = PrinterResolutionKind.Custom;
        printerResolution.X = 300;
        printerResolution.Y = 300;

        printDocument.PrinterSettings.DefaultPageSettings.PrinterResolution = printerResolution;

        printDlg.Document = printDocument;

But with no success.

Do you have any suggestions for setting higher resolutions when printing, bearing in mind that we are likely to have a mixture of raster and vector data.

Thanks,
Jonathan

Hi Jonathan,

For vector, whenever how you print it, the quality is well. But for raster, if you expand the shape, the render quality will reduce, we cannot modify it exception the source data have better precision. They follow different render logic.

We set the dpi to 100 is because in the scenario the device dpi is 100, so that means, you need to set the dpi equal the device default dpi, if you modify it but not modify the device dpi, the problem will appear. Modify the dpi is not helpful for get high quality image.

Wish that’s helpful.

If I misunderstand your scenario please let me know.

Regards,

Ethan

Hi Ethan,

For vector, whenever how you print it, the quality is well. But for raster, if you expand the shape, the render quality will reduce, we cannot modify it exception the source data have better precision. They follow different render logic.

That is a good point. We have a number of different image source types but they are most often the source data is higher quality (better the 100 dpi)…

We set the dpi to 100 is because in the scenario the device dpi is 100, so that means, you need to set the dpi equal the device default dpi

It would be difficult to know what printers customers are likely to use but I have a very standard HP printer but even the Draft quality is 300x300 DPI and Normal is 600x300 DPI (there are higher modes). Setting the printer to draft and printerGeoCanvas.Dpi to 300 results in the raster being re-scaled to a third of it’s size and vector features no longer sitting correctly on top - like in Zak’s original message - but greatly exaggerated,

if you modify it but not modify the device dpi, the problem will appear. Modify the dpi is not helpful for get high quality image.

Not sure I understand this bit? How would I modify the device dpi? I notice there is a PrinterResolutions class that list the available modes. But then how would I respond to the devices dpi to get printing to work correctly?

Thanks,
Jonathan

Hi Jonathan,

Thanks for your further information.

Our developers discuss about it today, it looks it’s a complex if you want to make the DPI to higher and keep raster and vector layers keep match, that’s related with how our classes implement the print logic.

So it maybe cannot get a result quickly, but any update I will let you know.

Regards,

Ethan

Hi Ethan,

Thanks for the information and look forward to some positive developments soon.

Regards,
Jonathan