QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgspdfwriter.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspdfwriter.cpp
3 -------------------------------------------------------------------
4Date : 09 October 2023
5Copyright : (C) 2023
6email : marco.hugentobler at sourcepole dot com
7
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include "qgsapplication.h"
18#include "qgsmaprenderertask.h"
19#include "qgsmapsettings.h"
20#include "qgsmodule.h"
21#include "qgspdfwriter.h"
22#include "qgswmsrenderer.h"
23
24
25namespace QgsWms
26{
27 void writeAsPdf( QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response )
28 {
29 QgsWmsRenderContext context( project, serverIface );
38 context.setParameters( request.wmsParameters() );
39 QTemporaryFile tmpFile;
40 tmpFile.open();
41 QgsRenderer renderer( context );
42 std::unique_ptr<QgsMapRendererTask> pdfTask = renderer.getPdf( tmpFile.fileName() );
43 QgsApplication::taskManager()->addTask( pdfTask.get() );
44 pdfTask->waitForFinished();
45 response.setHeader( "Content-Type", "application/pdf" );
46 response.write( tmpFile.readAll() );
47 tmpFile.close();
48 }
49} // namespace QgsWms
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Map renderer for WMS requests.
std::unique_ptr< QgsMapRendererTask > getPdf(const QString &tmpFileName)
Returns a configured pdf export task.
Rendering context for the WMS renderer.
void setParameters(const QgsWmsParameters &parameters)
Sets WMS parameters.
void setFlag(Flag flag, bool on=true)
Sets or unsets a rendering flag according to the on value.
Class defining request interface passed to WMS service.
const QgsWmsParameters & wmsParameters() const
Returns the parameters interpreted for the WMS service.
Median cut implementation.
void writeAsPdf(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in PDF format.