Podcast
Questions and Answers
What is the purpose of modifying a custom view template in the custom PDF implementation?
What is the purpose of modifying a custom view template in the custom PDF implementation?
Which method must be added to the TypeScript controller to facilitate the PDF generation?
Which method must be added to the TypeScript controller to facilitate the PDF generation?
What is returned by the GetPdf() method in the custom API controller?
What is returned by the GetPdf() method in the custom API controller?
What is the purpose of the PdfGeneratorHelper.GeneratePdf() method?
What is the purpose of the PdfGeneratorHelper.GeneratePdf() method?
Signup and view all the answers
What information does the ContentDisposition header include in the response to the PDF request?
What information does the ContentDisposition header include in the response to the PDF request?
Signup and view all the answers
What is the first step required for implementing a custom PDF?
What is the first step required for implementing a custom PDF?
Signup and view all the answers
Which scenario is NOT a use case for generating custom PDFs?
Which scenario is NOT a use case for generating custom PDFs?
Signup and view all the answers
What should the GetPdfHtml() method return?
What should the GetPdfHtml() method return?
Signup and view all the answers
What is the purpose of the method GetPdfHtml() in the provided code?
What is the purpose of the method GetPdfHtml() in the provided code?
Signup and view all the answers
In which format does the custom PDF view template need to be generated?
In which format does the custom PDF view template need to be generated?
Signup and view all the answers
Where should the custom PDF template be located in the project directory?
Where should the custom PDF template be located in the project directory?
Signup and view all the answers
What type of object is cartModelDynamic in the provided code?
What type of object is cartModelDynamic in the provided code?
Signup and view all the answers
Which repository method is called to obtain the current theme's details?
Which repository method is called to obtain the current theme's details?
Signup and view all the answers
What does the variable themeSourceName represent in the method GetPdfHtml()?
What does the variable themeSourceName represent in the method GetPdfHtml()?
Signup and view all the answers
What conditions are checked to determine if the logo should be included in the PDF template?
What conditions are checked to determine if the logo should be included in the PDF template?
Signup and view all the answers
What service is used to parse the template content in the GetPdfHtml() method?
What service is used to parse the template content in the GetPdfHtml() method?
Signup and view all the answers
Study Notes
Custom PDF Implementation
-
Optimizely Commerce Cloud platform provides a way to generate custom PDF documents.
-
Use Cases:
- Generating a PDF of the current items in the cart.
- Creating a PDF that shows the top ten most purchased products for a given category.
- Creating a PDF that shows a category’s marketing content.
-
To create a custom PDF, developers need to modify the following:
- Custom view template: Adds a line to trigger the PDF generation via a button or other action.
-
Custom TypeScript controller: Includes the
getPdf()
method which calls the custom API controller. - Custom API controller: A method that is called asynchronously, handles PDF generation and returns the output.
-
The
getPdf()
method in the TypeScript controller opens a new window to display the PDF. -
The custom API controller includes a
GetPdf()
method that:- Generates a PDF stream from rendered HTML using
PdfGeneratorHelper
. - Returns the PDF stream as a response with the appropriate content type and file name.
- Generates a PDF stream from rendered HTML using
-
GetPdfHtml()
method returns the HTML content for the PDF view:- It fetches the template from the appropriate path based on the theme.
- Parses the template with the cart model data.
- Returns the rendered HTML.
-
Custom PDF view template (e.g.,
CartPdfTemplate.cshtml
):- Needs to be in DotLiquid format and have the .cshtml extension.
- Located in the
PdfViews
folder within the theme directory. - Uses DotLiquid syntax to render the PDF content.
-
The provided C# code samples demonstrate how to implement these components.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Explore how to implement custom PDF generation in the Optimizely Commerce Cloud platform. This quiz covers use cases, the modification of templates, and methods necessary for generating PDFs, including TypeScript and API integration. Test your knowledge on creating interactive and dynamic PDF documents based on e-commerce data.