Streaming PDF with FME Server Data Streaming Service

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2020.1

Live Demo

Introduction

Build and format PDFs in FME Workbench then stream the contents using FME Server’s Data Streaming Service. Geospatial PDFs are capable of storing raster or vector data, distinct layers, custom formatting, and interactive features. With Data Streaming, you can easily share spatial and non-spatial data through a browser using PDF. This example is set up and running on Safe's FME Server demo site. There are no installation requirements other than a standard web browser.

 

Try it out by clicking the Live Demo link at the top of the page. A PDF of an area map is generated. Click on a tile in the index map (lower left) to generate a PDF of another area, or return to the overview map by clicking the text. 

 

PDFStreamingDemo.fmw streamed to a browser PDF viewer


Optionally, download and open the PDF in Adobe Reader, there you can explore the layers by turning them on and off, hover over features for more information, and navigate to other pages with hyperlinks. When saving the file to desktop, ensure you are the saving the file with the extension *.pdf, not *.fmw.
 

PDF File in Adobe Acrobat Reader


The process to make this demo happen is twofold: a workspace created in FME Workbench is uploaded to FME Server, where it can stream data back to a user with a click. Keep reading to get into the nuts and bolts of the workspace.

 

Step-by-step Instructions

The map layers source data are read from feature types in the linked GeoPackage file (InterpolisDatabase.gpkg) with Individual Feature Types selected. 

PDFStreamingDemo.fmw
 

This file is located in the FME Server Resources folder, and can be updated and uploaded to produce the most current layers on demand (provided the feature types names remain the same). 
 

Part 1: Map View and Grid

Map View and Grid bookmark


Using AttributeCreator for each incoming feature, we can define the layer order by assigning an attribute (_order) with a value that defines its order number (0 to N). This will later be used to organize the features prior to drawing them on the PDF. 
 


The user has the choice to select what tile they want to view. The list of tiles are available as a Published Parameter Choice for selection for when running the workspace from FME Server, or by choosing a tile on the PDF’s Index map. Once the view is selected, Tester checks if it is the Overview tile. If it is not Overview, Tester_2 compares the value to the TILE_NAME attribute values to determine which tile is selected. 
 

From here, the tile choice is routed to two workflows: one to create the map’s grid and index map, the other to clip and format the other features to the chosen view. 

To create the grid, the features are funnelled through a GeometryCoercer that ensures the geometries are restricted to line features. Labels for the tile names are created using TextAdder_4. From here, PDFStyler_6 and PDFStyler_9 assign styles to the grid (_CITY_GRID) and labels (TILE_NAME), respectively. 
 

 

Part 2: Map Features

Map Features bookmark


The rest of the incoming feature types need to be clipped to the chosen tile. The tile acts as the Clipper and all the other features (Hydrography, BusRoutes, BusStops, Roads) are the Clippee(s). To distinguish the features, they are routed through the FeatureTypeFilter.

A series of PDFStyler transformers assign custom styles, colors, and Interactivity options to the layers.

A 2DEllipseReplacer transformer places an ellipse over each point feature in the BusStop feature type. PDFStyler_3 Interactivity is turned on to display a Tooltip with the stop name when the user hovers over it. Additionally, a URL redirects to the bus stop’s Google Maps location when selected. 

 

Part 3: Index Map

Index Map bookmark
 

Another workflow extends from the CityGrid feature type to create the small index map. TextAdder creates labels for the tile names, and PDFStyler_10 formats the text.

PDFStyler formats the small grid that is displayed in the bottom left corner. It’s Interactivity features’ Tooltip instructs the user to “Click to View Tile”. The URL links to the FME Server workspace using the Data Streaming service and the tile_name parameter populated by the user selection.  

Because Interactivity features are always drawn on top, regardless of layer order, we did not assign an _order attribute to the Index map. To view the labels, the Fill Opacity was set to 0.44 so that the labels would still be visible through the interactive tiles.

 

Part 4: Order Layer Drawing

Order Layer Drawing bookmark
 

All of the transformed features for the large map are fed through a Sorter. The transformers sort the features based on the _order attribute (assigned earlier in the workflows by the AttributeCreators) to create a layer hierarchy. The hierarchy is respected by most PDF viewers, but not all (if the layers are not displaying as intended, try a different browser or PDF viewer).

 

Part 5: Page Text

Page Text bookmark
 

The plain text on the PDF begins with the Creator reader. A VertexCreator assigns geometry so that it can be placed on the page. ParameterFetcher_2 also gets the tile name from the Published Parameter. The title text is created with TextAdder_2, then formatted with StringCaseChanger and PDFStyler_7. 

TextAdder_3 creates the page text, “View Overview Map”. The PDFStyler_8 Interactively is turned on with a URL that redirects to the workspace with the Overview parameter selected. This functions to return the user to the Overview map. 

 

Part 6: Page Layout and Geospatial PDF Writer

Page Layout bookmark and Adobe Geospatial PDF Writer
 

The sorters route their features to ports in the PDFPageFormatter that represent the distinct elements on the final page. 

The transformed features have all been routed into their respective ports on the PDFPageFormatter. The different elements can be precisely positioned and resized using the visual layout. 

The formatted PDF is routed to an Adobe Geospatial PDF writer. To preserve the distinct feature layers, the Layer Name parameter is set to the fme_feature_type Attribute Value. Ensure Attribute Definition is set to Automatic so that all feature properties are written.

 

Part 7: Upload to FME Server

The data (InteropolisDatabase.gpkg) must be located in the Resources folder on FME Server. This will allow you to easily access and update the data as needed. 

In FME Workbench, ensure the OGC Geopackage Reader in the workspace is pointed to location on FME Server. Publish the workspace to FME Server with Data Streaming selected. 

 

Part 8: Run the workspace

When running the workspace directly from FME Server, you will be prompted to choose a Tile Name before streaming the PDF. 

You can run the workspace from a direct link, such as in this article, to stream the PDF instantly. Stream another PDF of a different view by making selections on the Index Map. 

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.