Save Barcode as PNG
Save generated barcodes as PNG image attachments linked to the current record. These images can be used in email templates, Apex code, or other applications.
How it works
The component automatically saves the generated barcode as a PNG file whenever the code renders successfully on the page. The saved images are attached to the record and can be accessed from the Files related list.
Key aspects
- The code must render correctly on the page to be saved.
- The image is generated client-side; there is no full backend generation.
- You can use the scale parameter in the component to adjust the size of the generated image. A higher scale value results in a larger image.
- By default, the component renders codes with a transparent background. However, when saving as PNG, the background is set to white to ensure the code displays correctly in various contexts, such as emails with different background colors.
- If you edit the field being encoded (e.g., change an email address), the component will rerender and save a new PNG file automatically.
File naming convention
Saved files are named using the pattern {code_type}:{text}.png, where:
- code_type is the type of code (e.g., qrcode, code128).
- text is the value being encoded (e.g., a hardcoded text value, a field value, or the record ID).
Enable functionality
This feature is disabled by default. To enable it, you must edit the Lightning Page in the Lightning App Builder and activate it using the corresponding checkbox.
- Open the Lightning App Builder by navigating to Setup > Lightning App Builder.
- Select the Lightning Page where the code component is placed.
- In the page editor, locate the code component.
- In the component's properties panel, check the Save as PNG box.
- Click Save to apply the changes to the page. Once enabled, the component will save the generated code as a PNG attachment to the record each time the code renders successfully.