Implementation

Navigate to the PDF & Screenshot component present in the SmartBrowz section in your Catalyst console. PDF & Screenshot enables you to generate visual documents of any webpage. You can use this component in two ways:

  • Using SDKs catalyst_smartbrowz_pdfnscreen_code_snippets

  • Using the Playground feature catalyst_smartbrowz_pdfnscreen_playground_show

Generate PDF & Screenshots Through Code

Catalyst provides you the required SDKs to generate PDF & Screenshots in the following frameworks:

You can also use this Catalyst API to generate visual documents in your preferred format.

Based on your preferred programming language, you can copy and paste the below code snippets in your application logic to generate visual documents:

Java SDK

    
Java SDK to Generate Visual Documents
copy
// initialize SmartBrowz ZCSmartBrowz smartBrowz = ZCSmartBrowz.getInstance(); // generate output from a predefined template ZCSmartBrowzConvertDetails convertDetailsForTemplateConversion = ZCSmartBrowzConvertDetails.getInstance(); convertDetailsForTemplateConversion.setTemplateId(YOUR_TEMPLATE_ID); smartBrowz.generateFromTemplate(convertDetailsForTemplateConversion); // convert to PDF from HTML ZCSmartBrowzConvertDetails convertDetailsForPDF = ZCSmartBrowzConvertDetails.getInstance(); convertDetailsForPDF.setHtml("YOUR_HTML_CODE"); smartBrowz.takeScreenshot(convertDetailsForPDF); // take a screenshot from URL ZCSmartBrowzConvertDetails convertDetailsForScreenshot = ZCSmartBrowzConvertDetails.getInstance(); convertDetailsForScreenshot.setUrl("YOUR_URL"); smartBrowz.convertToPdf(convertDetailsForScreenshot);
View more

Note: This code snippet contains the individual logic to accept any of acceptable input and generate PDF and Screenshot. When you copy the snippet, ensure you retain the lines of code that are pertinent to your requirement and omit the rest.

Node.js SDK

    
Node.js SDK to Generate Visual Documents
copy
const smartbrowz = app.smartbrowz(); // Generate output from template smartbrowz.generateFromTemplate("YOUR_TEMPLATE_ID", {"template_data": YOUR_TEMPLATE_DATA} ) .then((data)=>{ // On Success }).catch((err)=>{ // On Error }) // Convert PDF from HTML smartbrowz.convertToPdf("YOUR_HTML_CODE", { "pdf_options": {}, "page_options": {} }).then((data)=>{ // On Success }).catch((err)=>{ // On Error }); // Capture a Screenshot from URL smartbrowz.takeScreenshot("YOUR_URL", { "screenshot_options": { "type": "jpeg" //Provide either jpg or png }, "page_options": { "device": "iPad" //Provide a device of your prefrence } }).then((data)=>{ // On Success }).catch((err)=>{ // On Error })
View more

Note: This code snippet contains the individual logic to accept any of acceptable input and generate PDF and Screenshot. When you copy the snippet, ensure you retain the lines of code that are pertinent to your requirement and omit the rest.

Python SDK

    
Python SDK to Generate Visual Documents
copy
# initialize smartbrowz instance smart_browz = app.smart_browz() # generate output from a predefined template output_template = smart_browz.generate_output_from_template( template_id='YOUR_TEMPLATE_ID', template_data={}, output_type='pdf', // You can determine the format of your visual document here pdf_options={}, navigation_options={} ) # convert to PDF from HTML output_pdf = smart_browz.convert_to_pdf(source='YOUR_HTML_CODE') # take a screenshot from URL output_screenshot = smart_browz.take_screenshot( source='YOUR_URL', screenshot_options={ 'quality': '100' }, page_options={ 'device': 'iphone 13 pro' //Provide a device of your prefrence }, navigation_options={ 'timeout': '3000', 'wait_until': 'domcontentloaded' } )
View more

Note: This code snippet contains the individual logic to accept any of acceptable input and generate PDF and Screenshot. When you copy the snippet, ensure you retain the lines of code that are pertinent to your requirement and omit the rest.

These code snippets are available under the SDK Code Snippets section of the PDF & Screenshot component in the console. You can copy the code of the stack you require and incorporate it in your business logic.

catalyst_smartbrowz_pdfnscreen_snippet_selection_py

You can also use this API to generate PDF & Screenshots. You can execute this API directly after authenticating your request.

Note: These code snippets are also available in the respective framework's SDK documentation.

Generate PDF & Screenshots Through Playground

Playground is available in the console for you to generate visual documents immediately or test this feature before incorporating it into your logic. The Playground itself comes loaded with pre-engineered inputs for you to test the functionality of the component.

You can generate visual documents of webpages in the console by providing the input in three different ways:

HTML Code

  1. Select the HTML Code option in the Select Input Type section. catalyst_smartbrowz_pdfnscreen_html_main_view

You can either customize the code present in the HTML code editor or paste your own code.

  1. Select the required format from the Select Output Format drop-down. catalyst_smartbrowz_pdfnscreen_html_output_drop

  2. This is an optional step, but you can customize your visual document by applying custom styling elements and layout and other aesthetic configurations using the options present in the Show Advanced Styling Options section. catalyst_smartbrowz_pdfnscreen_html_advanced_options

You can also use this section to password protect the generated visual document by setting up a password in the Set Password section.

  1. Click Generate. catalyst_smartbrowz_pdfnscreen_generated_output
    A preview of the visual document you generated will be shown in a pop-up. Click Download, to save the document in your local system.

If you have password protected your PDF, then the preview and download options will only be made active after you enter the password. catalyst_smartbrowz_pdfnscreen_pwd_protected

URL

You can generate a visual document of a webpage of your preference by directly entering its URL.

  1. Click the URL button to use URL as the input type.

  2. Enter the required URL in the Enter Web Page URL input field. catalyst_smartbrowz_pdfnscreen_url_select

  3. Select the required format from the Select Output Format drop-down. catalyst_smartbrowz_pdfnscreen_url_output_drop

  4. This is an optional step, but you can customize your visual document by applying custom styling elements and layout and other aesthetic configurations using the options present in the Show Advanced Styling Options section. catalyst_smartbrowz_pdfnscreen_url_styling

You can also use this section to password protect the generated visual document by setting up a password in the Set Password section.

  1. Click Generate. catalyst_smartbrowz_pdfnscreen_generated_url_output

If you have password protected your PDF, then the preview and download options will only be made active after you enter the password. catalyst_smartbrowz_pdfnscreen_pwd_protected

Templates

Note: Note: You can only this feature if you have previously created and saved template using the Templates component.
  1. Click the Template button to set templates as the input type.

  2. Select your preferred template from the Template drop-down. catalyst_smartbrowz_pdfnscreen_template_select_layout

  3. You can provide the data for the visual document as a JSON input through the editor present in this section. catalyst_smartbrowz_pdfnscreen_template_json_input

  4. Click Generate. catalyst_smartbrowz_pdfnscreen_generated_output

A preview of the visual document you generated will be shown in a pop-up. Click Download, to save the document in your local system.

Note:

  • Prior to generating a visual document, since your input type is Templates you would have chosen the layout, the styling elements and all the other aesthetic features of the visual document, while you were creating and designing the template. You can find out how to customize a template from this section.

  • Because you are using Templates to generate your password protected PDF, you have an option to code a logic that allows you to set the password dynamically. You can find out more about this feature in this section.

If you have password protected your document, then the preview and download options will only be made active after you enter the password. catalyst_smartbrowz_pdfnscreen_pwd_protected

Note: Any Browser action or operation that you code using the Browser Logic function, or any browser automation or web scraping task that you perform using any component of Catalyst SmartBrowz is at your own risk. We strongly recommend you use the SmartBrowz components to perform operations on domains that permit the actions, or with proper approval. Additionally, while Catalyst does provide a secure infrastructure to code your functions, any consequence of the logic you code using Catalyst functions is yours alone.

Last Updated 2024-01-31 12:43:52 +0530 +0530