ThinkGeo.com    |     Documentation    |     Premium Support

Convert map div to pdf along with labels and save on server

Hi

I am new to this forum need ur help in doing my task
I need to export my map into pdf format … i looked into “use PDF Extenstion” but that is not what i want …
I want to add text box values as the heading of pdf file and save it on server further i wana send that folder link to my database to add it in archive

Can u please tell me how i can do that…

Hi Waha,

We have a sample named “Print Preview”, which is not based on WebAPI edition, but you can learn the APIs from it about export the map with label into PDF. You can find the sample here: http://wiki.thinkgeo.com/wiki/map_suite_services_edition_all_samples#print_preview

You can directly connect to your database in server side, and save that into it. We don’t have related API for that, so you can just call .net APIs for it.

And for the UI, because you are using WebAPI edition, so you should want to implement that by custom code with some JavaScript library.

Regards,

Don

Thanks for ur guidance sir
I saw this tutorial but this is not what i want using this i cant save my file on server with a single click but in this tutorial it is exporting pdf file…
My scenario is i wana convert map, labels, sources and some other divs into string using javascript and then call controller function along with html saved in string variable and send as parameter to that controller function which will send that html to pdf document and save the file in project folder
Here’s the sample code

    function sendhtml() {
        var savehtmlpage;
        var mapContents = $("#cMap1").html();
        var legenddiv = $("#legendDiv").html();
        var datasourcesdiv = $("#DataSources").html();
        var footer = $("#footer").html();
        savehtmlpage.append(mapcontent);
        savehtmlpage.append(legenddiv);
        savehtmlpage.append(datasourcesdiv);
        savehtmlpage.append(footer);
        alert(savehtmlpage);
       
        $.post("/Map/ConvertThisPageToPdf", { 'htmlpage': savehtmlpage }, function (response) {
            alert("function called")
        });

ConvertThisPageToPdf is the controller function.
Can u tell me whats wrong with this code

Hi Waha,

Thanks for your description, I think the problem is you cannot pass our Map back to server side by this way, if you get the map by Jquery API, the string won’t be valid.

So you cannot save what you seen into PDF, just can save the invalid string into it.

If you want to save the image, I think maybe have two ways:

  1. Use JavaScript get a image and sent it back.
  2. Directly get map image on server side and save that into PDF.

Regards,

Don

Hi

I am able to see my html to along with the map … i took screenshot of the map div and send it as html string to server side … i tried using a library to convert that html string to pdf
First i used hiqpdf…
and then i tried itextsharp … but what i see while debugging is my complete html what i want …but when it is saved in folder i see half image of the map
can u tell me where am i wrong
Here’s what im doing on server side using hiqpdf

[HttpPost]
[ValidateInput(false)]
public ActionResult ConvertThisPageToPdf(string htmlpage)
{
HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
htmlToPdfConverter.ConvertHtmlToFile(htmlpage, null, Server.MapPath("~/App_Data/SavedPDF/map.pdf"));
return fileResult;
}

Regards
Waha Ali

Hi Waha,

Have you tried to directly saved the sent back html to local disk, then open it in another machine?

If this page can be opened standalone and the map works well, I think it can be saved by the 3rd part library.

But if it cannot be opened standalone, that’s why you cannot export that as PDF.

What I suggest is export the map into image by our API in server side, you can view our sample project of Service Edition, which shows how to directly print data into an image layer by layer.

Wish that’s helpful.

Regards,

Don