I have an HTML page that has some texts, a checkbox element, and a button to generate the HTML to PDF.
the checkbox control whether the text element will be shown or hidden in the HTML page using JavaScript
my question is: how to reflect this in the generated PDF? how to hide the element from the PDF if the checkbox is checked?
I tried to use one JS file but it didn't work.
*I'm using WeasyPrint in Django to generate the PDF file This is the HTML code for the PDF
{% load i18n %}
{% load static %}
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="{% static 'barcode-print.css' %}">
</head>
<body>
<section data-controller="barcode-page" id="first-section">
<span>
{{ ticket.number }}
</span>
</section>
<section>
<span>
{{ ticket.created|convert_date:True }}
</span>
</section>
<section>
<span id=“showHideinfo”>
</span>
<label>
{% trans 'attachments' %}:
</label>
</section>
<section id="ticket">
<p>
{{ tichket.number }}
</p>
</section>
</body>
</html>
This is the HTML page which has generate PDF button:
{% load i18n %}
{% load staticfiles %}
{% load correspondence_tags %}
{% load guardian_tags %}
{% block child %}
<div data-controller="barcode-page">
<div class="barcode-page-section1">
<div class="barcode-tickets-number">
{{ ticket.number }}
</div>
<div class="barcode-corres-date-label">
{% if correspondence.class_name_en == 'GeneralOutboundCorrespondence' %}
<label><strong> {% trans 'corres_outbound_date' %}:</strong></label>
{% else %}
<label><strong> {% trans 'entity_outbound_date' %}:</strong></label>
{% endif %}
</div>
<div class="barcode-corres-attachment-label" data-target="barcode-page.attachmentslabelDiv">
<label><strong> {% trans 'attachments' %}:</strong></label>
</div>
<div class="barcode-corres-attachment" data-target="barcode-page.attachmentsInfoDiv">
</div>
</div>
<div class="barcode-page-section2">
<div class="barcode-img-element">
<svg>
{{ form.instance.barcode }}
</svg>
</div>
<div class="barcode-checkbox-element">
<input class="barcode-checkbox" type="checkbox" data-action="barcode-page#showHideAttachments"
id="id_barcode_checkbox" checked data-target="barcode-page.attachmentsCheckbox">
{% trans 'Show attachments in barcode'%}
</div>
<div class="barcode-button-element">
{% if correspondence %}
<a target="_blank" href="{% url ’ticket:barcode-print' pk=ticket.id %}"
class="btn btn-primary barcode-button" id="barcode-pdf-button"
data-target="barcode-page.barcodeToPDFButton">
{% trans 'print' %}
</a>
{% endif %}
</div>
</div>
</div>
{% endblock %}
and this is the Django view:
class BarcodePrintView(LoginRequiredMixin, DetailView, DeleteView):
model = Correspondence
context_object_name = 'ticket'
class BarcodePrint(WeasyTemplateResponseMixin, BarcodePrintView):
pdf_stylesheets = [
settings.STATIC_ROOT + '/main.css',
]
template_name = 'tickets/barcode_print.html'