QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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,
28 const QgsWmsRequest &request,
29 QgsServerResponse &response )
30 {
31 QgsWmsRenderContext context( project, serverIface );
40 context.setParameters( request.wmsParameters() );
41 QTemporaryFile tmpFile;
42 tmpFile.open();
43 QgsRenderer renderer( context );
44 std::unique_ptr<QgsMapRendererTask> pdfTask = renderer.getPdf( tmpFile.fileName() );
45 QgsApplication::taskManager()->addTask( pdfTask.get() );
46 pdfTask->waitForFinished();
47 response.setHeader( "Content-Type", "application/pdf" );
48 response.write( tmpFile.readAll() );
49 tmpFile.close();
50 }
51} // 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.