Content types

Introduction

With inbuilt methods its possible to make the server render page content data with different content type header or even produce a file stream for the content.

For this to work we would need to construct the data in the template in correct format we expect to return.

Methods to return

There are 2 ways we can make these calls

  1. Using the appropriate query parameters
/my-csv-page?CSV=1
  1. Using file type suffix
/my-csv-page.csv

Note that -page suffix is not required, a link without it will lead to the correct route.

/my-csv.csv

Supported content types

Type Parameter Path suffix
Pdf ?PDF .pdf
Xml ?XML .xml
Csv ?CSV .csv
Json ?JSON .json
Txt ?TXT .txt

Additional parameters

Pdf

  1. PDF.FileName - Server will produce the data as a file stream instead, giving the file the requested name
  2. PDF.DPI - Dpi of the pdf, default 300
  3. PDF.Orientation - Orientation, default Portrait (Portrait, Landscape)
  4. DF.PageSize - File size, default A4 (A0, A1, A2, A3, A4, A5, A6, A7, Letter, Legal, Ledger, Tabloid, Folio, Executive)
  5. PDF.MarginTopMM - Set a top margin
  6. PDF.MarginBottomMM - Set a bottom margin
  7. PDF.MarginLeftMM - Set a left margin
  8. PDF.MarginRightMM - Set a right margin
  9. PDF.PageWidth - Set a custom page width (this will override the page size value)
  10. PDF.PageHeight - Set a custom page height (this will override the page size value)

Xml

  1. XML.FileName - Server will produce the data as a file stream instead, giving the file the requested name

Csv

  1. CSV.FileName - Server will produce the data as a file stream instead, giving the file the requested name

Json

  1. JSON.FileName - Server will produce the data as a file stream instead, giving the file the requested name

Txt

  1. TXT.FileName - Server will produce the data as a file stream instead, giving the file the requested name

Setting content type in the template

This will apply same rules as setting the content type in the url, but in this case entire template would be processed using most suited template processor (not related to PDF). For example, setting content type to json or xml would process template through text processor, not html, removes all html related validations/encoding and makes process much faster.

Content type setting in template Content type setting in template