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
- Using the appropriate query parameters
/my-csv-page?CSV=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 |
---|---|---|
Xml | ?XML | .xml |
Csv | ?CSV | .csv |
Json | ?JSON | .json |
Txt | ?TXT | .txt |
Additional parameters
- PDF.FileName - Server will produce the data as a file stream instead, giving the file the requested name
- PDF.DPI - Dpi of the pdf, default 300
- PDF.Orientation - Orientation, default Portrait (Portrait, Landscape)
- DF.PageSize - File size, default A4 (A0, A1, A2, A3, A4, A5, A6, A7, Letter, Legal, Ledger, Tabloid, Folio, Executive)
- PDF.MarginTopMM - Set a top margin
- PDF.MarginBottomMM - Set a bottom margin
- PDF.MarginLeftMM - Set a left margin
- PDF.MarginRightMM - Set a right margin
- PDF.PageWidth - Set a custom page width (this will override the page size value)
- PDF.PageHeight - Set a custom page height (this will override the page size value)
Xml
- XML.FileName - Server will produce the data as a file stream instead, giving the file the requested name
Csv
- CSV.FileName - Server will produce the data as a file stream instead, giving the file the requested name
Json
- JSON.FileName - Server will produce the data as a file stream instead, giving the file the requested name
Txt
- 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.