[OpenLayers-Users] loadURL returns a pdf
Eric Lemoine
eric.c2c at gmail.com
Sun Feb 8 03:25:15 EST 2009
Alexandre,
Have you looked at the MapFish print widgets? I'd recommend doing so :-)
Eric
2009/2/6, Alexandre Dube <adube at mapgears.com>:
> Thanks Bart,
>
> This looks great. I'll take some time today to look at all this.
>
> Alexandre
>
> bartvde at osgis.nl wrote:
>> Hi Alexandre,
>>
>> I've got a PHP script which will return in JSON the url of the pdf,
>> something like:
>>
>> {success: true,
>> 'url':'http://test.intranet.rijkswaterstaat.nl/apps/geoservices/ms_tmp/layout_498c466c_441e_1.pdf'}
>>
>> then my download function will set it to the src of an iframe making use
>> of a download.php script (which sets the correct http headers for starting
>> a download dialog in the browser):
>>
>> download: function(response) {
>> var res = eval( "(" + response.responseText + ")" );
>> this.iframe.dom.src = GeoServices.ScriptsUrl +
>> '/download.php?url='+res.url;
>> GeoServices.getApplication().hideWaitScreen();
>> },
>>
>> The iframe was created like:
>>
>> this.iframe = Ext.get(Ext.DomHelper.append(document.body,
>> Ext.apply({tag:'iframe', style: 'display:none',
>> src:(Ext.isIE&&Ext.isSecure)?Ext.SSL_SECURE_URL:''},true)));
>>
>> So actually I am using an iframe and not a form (the form was from the top
>> of my head).
>>
>> download.php is something like:
>>
>> <?php
>>
>> header("Cache-Control: cache, must-revalidate");
>> header("Pragma: public");
>>
>> function getContentType($filename) {
>> $path_info = pathinfo($filename);
>> $extension = strtolower($path_info['extension']);
>> if ($extension == 'pdf') {
>> return 'application/pdf';
>> } else if ($extension == 'xml') {
>> return 'text/xml';
>> } else {
>> return 'application/octet-stream';
>> }
>> }
>>
>> if (isset($_GET['url'])) {
>>
>> include_once(dirname(__FILE__)."/../../chameleon/htdocs/common/http/HTTPClient.php");
>> $oHTTPClient = new HTTPClient("", 30);
>> header( "Content-type: application/pdf" );
>> header( "Content-Disposition: attachment; filename=kaart.pdf" );
>> echo $oHTTPClient->doGET($_GET['url']);
>>
>> } else {
>> header( "Content-type: ".getContentType($_POST['filename']));
>> header( "Content-Disposition: attachment; filename=".$_POST['filename']
>> );
>> echo stripslashes($_POST['stream']);
>> }
>>
>> ?>
>>
>> Best regards,
>> Bart
>>
>>
>>> Hi Bart,
>>>
>>> Do you mind showing me a snippet of what you did ?
>>>
>>> Many thanks,
>>>
>>> Alexandre
>>>
>>> bartvde at osgis.nl wrote:
>>>
>>>> I did not find a way to do this with AJAX. So if you find one, I'd be
>>>> interested :-) but my search back then indicated this is not possible.
>>>>
>>>> So I ended up doing the following:
>>>>
>>>> 1) my script sends the url to the pdf
>>>> 2) I set the url as the action of a form and submit the form
>>>> 3) the download dialog starts
>>>>
>>>> I also had to have a static form in my HTML page instead of inserting it
>>>> with javascript, since otherwise IE would end up opening a new window.
>>>>
>>>> Best regards,
>>>> Bart
>>>>
>>>>
>>>>
>>>>> Dear users,
>>>>>
>>>>> Still looking for a way to achieve this. Does anyone have a hint ?
>>>>>
>>>>> Alexandre
>>>>>
>>>>> Alexandre Dube wrote:
>>>>>
>>>>>
>>>>>> Hi list,
>>>>>>
>>>>>> Can I load a script that returns a pdf using loadURL() ? It
>>>>>> currently
>>>>>> returns "Unhandled request return OK" but if I copy the URL in a new
>>>>>> tab
>>>>>> I get my pdf correctly. Any idea what may be wrong ?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> Alexandre Dubé
>>>>> Mapgears
>>>>> www.mapgears.com
>>>>>
>>>>> _______________________________________________
>>>>> Users mailing list
>>>>> Users at openlayers.org
>>>>> http://openlayers.org/mailman/listinfo/users
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> --
>>> Alexandre Dubé
>>> Mapgears
>>> www.mapgears.com
>>>
>>>
>>>
>>
>>
>>
>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
More information about the Users
mailing list