Question:
How can I exclude the cookie banner from the PDF generated using the PDF Generator widget on my Wix Studio site?
Product:
Wix Studio Editor – PDF Generator App and Dynamic Pages.
What are you trying to achieve:
I am using the PDF Generator app on a dynamic product page to allow users to download product-specific PDFs. The template for the PDF is hosted at the following URL:
https://www.fsg-sensors.de/pdfvorlage
.
The dynamic product page is located at:
https://www.fsg-sensors.de/pdf-produkte/b2
.
The PDF dynamically displays product data from my database. However, when generating the PDF, the cookie banner (from Wix’s default cookie management tool) is included in the output. This disrupts the layout and presentation of the PDF document.
My goal is to exclude or hide the cookie banner during PDF generation without affecting its visibility for normal users browsing the page. I assume this might require detecting when the page is being rendered for a PDF request and conditionally hiding the banner.
What have you already tried:
Currently, I have not implemented any specific solutions to remove or hide the cookie banner for PDF generation. Below is the code I am using on the dynamic product page and the PDF template page to generate the product-specific PDF:
Dynamic Product Page Code:
This code generates the PDF link dynamically based on the product data:
import wixLocationFrontend from 'wix-location-frontend';
$w.onReady(() => {
const currentItem = $w("#dataset").getCurrentItem(); // Get the current product
const productId = currentItem._id; // Product ID
const productName = currentItem.name; // Product name from the database
// URL to the PDF template with product ID as a query parameter
const templateUrl = `https://www.fsg-sensors.de/pdfvorlage?productId=${productId}`;
// Set the template URL and the file name for the PDF widget
$w("#pdfGeneratorWidget").templateUrl = templateUrl;
$w("#pdfGeneratorWidget").fileName = productName; // Use the product name as the PDF file name
});
PDF Template Page Code:
This code dynamically loads the product data for the PDF generation:
import wixLocationFrontend from 'wix-location-frontend';
import wixData from 'wix-data';
$w.onReady(() => {
const { productId } = wixLocationFrontend.query;
// Query the "PDF_Produkte" database for the product ID
wixData.query("PDF_Produkte")
.eq("_id", productId)
.find()
.then((results) => {
if (results.items.length > 0) {
const product = results.items[0];
// Populate the elements with the product data
$w("#produktName").text = product.name; // Product name
$w("#produktPreis").text = product.text; // Price or text data
$w("#produktSignal").text = product.text1; // Signal or additional data
}
})
.catch((err) => {
console.error("Error loading product data:", err);
});
});
Additional information:
- The cookie banner is generated by Wix’s default cookie management tool.
- The PDF Generator is configured to generate dynamic PDFs by passing the product ID as a query parameter to the template page.
- I’m unsure how to detect when the page is being rendered by the PDF Generator (e.g., via backend rendering) to conditionally hide the cookie banner.
If there is a recommended approach or best practice to exclude the cookie banner from the PDF output, I would greatly appreciate your guidance.
Thank you for your support!