ThinkGeo.com    |     Documentation    |     Premium Support

PdfGeoCanvas render issue with Textstyle with best placement

Hi,
I am applying Textstyle with best placement, displaying results fine. But while converting into PDF, the result of best placement not coming.

I am taking PdfGeoCanvas class and drawing all overlays. Is there any way to convert map to pdf with best placement.

Please suggest me some ideas for fix it.

Thanks,
Riyaz

Hi Riyaz,

How you convert the data to PDF now?

I think print to PDF(https://github.com/ThinkGeo/PrintPreviewSample-ForWpf) or export to image and save into PDF should works better.

Regards,

Ethan

Hi Ethan,

Thanks for your reply.

Please find attachment for your reference.
pdf.zip (5.2 KB)

Please observe bellow snapshots.
Map Snapshot :

PDF snapshot:

In the map textstyle having best placement true, but same thing not coming in Export to PDF using PdfGeoCanvas.

Please check and fix that bug.

Thanks,
Riyaz

Hi Riyaz,

Thanks for your code.

Just like the code shows, our pdfGeoCanvas draw the 2nd time for PDF, because the features for PDF and GDI are not totally the same, we can only make sure most of the map looks the same but cannot make sure everything is the same.

So I think you can try the other solution about it:

            System.Drawing.Bitmap screenShot = winformsMap1.GetBitmap(winformsMap1.Width, winformsMap1.Height);
            GeoImage img = new GeoImage(screenShot);

and

                pdfGeoCanvas.BeginDrawing(page, ExtentHelper.GetDrawingExtent(winformsMap1.CurrentExtent, (float)(page.Width.Point), (float)(page.Height.Point)), winformsMap1.MapUnit);
                pdfGeoCanvas.DrawWorldImage(img, winformsMap1.CurrentExtent.GetCenterPoint().X , winformsMap1.CurrentExtent.GetCenterPoint().Y, (float)(page.Width.Point), (float)(page.Height.Point), DrawingLevel.LabelLevel, 0, 0, 0);
                pdfGeoCanvas.EndDrawing();

It will get the image and draw the image on PDF instead of draw the shapes again.

Our developer will keep research about the PDF, if we find solution to make the label position render at the same location when set best place, we will enhancement it.

Regards,

Ethan

Hi Ethan,
I tried your code, but quality not good compared to previous one.
Can you please work on for my code with Best Placement.

Thanks,
Riyaz

Hi Riyaz,

We don’t have the other solution for this problem now, but I think our developer can did some research about it and see whether we can find a workaround about it.

Any update I will let you know.

Regards,

Ethan

Hi Riyaz,

Because some special features in PDF, we hadn’t solve this problem, our developer will try to solve that in future.

Here I have a workaround which get better result than before, wish that’s helpful.

  class customPdfGeoCanvas : PdfGeoCanvas
{
    public float Rate
    {
        get; set;
    }

    public customPdfGeoCanvas() : base()
    {
        Rate = 1f;
    }

    protected override DrawingRectangleF MeasureTextCore(string text, GeoFont font)
    {
        font = new GeoFont(font.FontName, font.Size * Rate, font.Style, font.Unit);

        return base.MeasureTextCore(text, font);
    }
}

And assign this value:

  foreach (LayerOverlay layeroverlay in winformsMap1.Overlays)
                {
                    foreach (Layer layer in layeroverlay.Layers)
                    {
                        if (layeroverlay.IsVisible == true)
                        {
                            pdfGeoCanvas.BeginDrawing(page, ExtentHelper.GetDrawingExtent(winformsMap1.CurrentExtent, (float)(page.Width.Point), (float)(page.Height.Point)), winformsMap1.MapUnit);
                            if (!layer.IsOpen)
                                layer.Open();

                           // Add this line, in fact the value should be the rate between pdfGeoCanvas.width and platformGeoCanvas.width, here we just use this value which looks almost the same
                            pdfGeoCanvas.Rate = (float)pdfGeoCanvas.Width / (float)page.Width.Point;

                            layer.Draw(pdfGeoCanvas, labelsInLayers);

                            pdfGeoCanvas.EndDrawing();

                        }
                    }

                    pdfGeoCanvas.Flush();
                }

This workaroud solve the labels overlap problem, if we get better result about the best placement we will let you know.

Regards,

Ethan

Hi Ethan,
I tired your code, but it’s not Best Placement.
The Text is forming in the Point. the text should automatically adjust basing on the Point.

Please check it.

Thanks,
Riyaz

Hi Riyaz,

Just like I mentioned, this workaround only solve the labels overlap problem.

Because the special feature of pdf API, we hadn’t solve the best placement now.

If we get better solution we will let you know, and for your scenario I think you can try to set offset for adjust the label position.

Regards,

Ethan