Wednesday, April 5, 2017

How to create custom renderer for a file type in AEM

Use Case:

Honestly use cases for this could be different based on what you want to change in response for a specific file type. We will take an example where we want to add some custom header for a PDF file based on what author has added in property of that file. For example here if author has added a canonical url and no index property, then we want to add these property in response header of all pdf file request.


Note that in order to make these property available for asset, you have to override asset editor as well. One example of adding extra property to asset editor is here

Key here is OptingServlet which get invoked on every request. Here is one example

Note: Let me know if you have any question about implementation.