Html field in print format

this is the html table

this is what it appears when i print

how do i convert the html table which store data in json format, to a html table in print format
basically how can i get a table for this html in print
anyone know the solution?

not idea, but can you use like

{{ doc.get_formatted('html_data_field') }}

not working for me

somehow i have made the table

the problem is i want to add a scroll bar, because you can see some columns data are lost.
can anyone help how can i add scroll bar
below is the whole jinja code for this print format

{% set fixed_columns_start = ["PO NO", "Store", "Col. Cd", "Col. Name"] %}
{% set fixed_columns_end = ["Total Qty", "D.D", "Intercom", "Forex Rate", "Total Amount", "%"] %}
{% set fixed_columns_end_2 = ["Total Qty"] %}
{% set dynamic_columns = [] %}

<style>
        .table_border2 td, th{
            
            border:none;
            padding:8px;
            font-size:20px;
        }
        table{
            border-collapse:collapse;
        }
       
    </style>
    <div class="print-heading">
		<h1 style="font-size:40px;">
			<div>Order Sheet</div>
			<small class="sub-heading">OS00007</small>
		</h1>
	</div>

<table class="table_ss table_border2" id="loanTable" style="margin-bottom: 20px; display: table; width:100%;;border:none;">
         <tr>
            <td style="color:#000; font-weight:600;">Client : </td>
            <td>{{doc.client}}</td>
            <td style="color:#000; font-weight:600;">Merchandiser : </td>
            <td>{{doc.merchandiser}}</td>
         </tr>
         <tr>
            <td style="color:#000; font-weight:600;">Style : </td>
            <td>{{doc.style}}</td>
            <td style="color:#000; font-weight:600;">Marketing Division Head : </td>
            <td>{{doc.marketing_division_head}}</td>
         </tr>
         <tr>
            <td style="color:#000; font-weight:600;">Agent: </td>
            <td>{{doc.agent}}</td>
            <td style="color:#000; font-weight:600;">Date: </td>
            <td>{{doc.date}}</td>
         </tr>
         <tr>
            <td style="color:#000; font-weight:600;">Description : </td>
            <td>{{doc.description}}</td>
            <td style="color:#000; font-weight:600;">Brand : </td>
            <td>{{doc.brand}}</td>
         </tr>
         <tr>
            <td style="color:#000; font-weight:600;">Total Quantity: </td>
            <td>{{doc.total_quantity}}</td>
            <td style="color:#000; font-weight:600;">Season: </td>
            <td>{{doc.season}}</td>
         </tr>
      </table>





{% if doc.size %}
    <!--<p style="font-size:22px;"><b>Size Table</b></p>-->
    <style>
        .table_border td, th{
            
            border:1px solid #ddd;
            padding:8px;
            font-size:17px;
        }
        table{
            border-collapse:collapse;
        }
    </style>
    <!--<table class="table_s table_border" id="loanTable" style="margin-bottom: 20px; display: table; border:1px solid #ddd; width:100%;">-->
    <!--    <thead>-->
    <!--        <tr style="background: #eeeeee;">-->
    <!--            <th><b>Sr</b></th>-->
    <!--            <th><b>Size</b></th>-->
    <!--        </tr>-->
    <!--    </thead>-->
    <!--    <tbody>-->
    <!--        {% for row in doc.size %}-->
    <!--            <tr>-->
    <!--                <td>{{ loop.index }}</td>-->
    <!--                <td>{{ row.size }}</td>-->
    <!--            </tr>-->
    <!--        {% endfor %}-->
    <!--    </tbody>-->
    <!--</table>-->
    <br><br>
{% endif %}


{% if doc.size %}
    {% for row in doc.size %}
        {% set _dummy = dynamic_columns.append(row.size) %}
    {% endfor %}
{% endif %}

{% set htmldata = doc.htmldata %}

{% if htmldata %}
    <table class="table_border" style="width=100%;"> 
        <thead>
            <tr>
                <!-- Fixed columns at the start -->
                {% for col in fixed_columns_start %}
                    <th>{{ col }}</th>
                {% endfor %}
                
                <!-- Dynamic columns from row.size -->
                {% for col in dynamic_columns %}
                    <th>{{ col }}</th>
                {% endfor %}
                
                <!-- Fixed columns at the end -->
                {% for col in fixed_columns_end %}
                    <th>{{ col }}</th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            {% for row_str in htmldata[1:-1].split('},{') %}
                <tr>
                    {% set row_str = row_str | replace('{', '') | replace('}', '') %}
                    {% set row_values = row_str.split(',') %}
                    
                    <!-- Helper function to get value for a column -->
                    {% macro get_value(row_values, col) %}
                        {% for val in row_values %}
                            {% set parts = val.split(':') %}
                            {% if parts[0].strip().replace('"', '') == col %}
                                {{ parts[1].strip().replace('"', '') }}
                            {% endif %}
                        {% endfor %}
                    {% endmacro %}
                    
                    <!-- Fixed columns at the start -->
                    {% for col in fixed_columns_start %}
                        <td>{{ get_value(row_values, col) }}</td>
                    {% endfor %}
                    
                    <!-- Dynamic columns from row.size -->
                    {% for col in dynamic_columns %}
                        <td>{{ get_value(row_values, col) }}</td>
                    {% endfor %}
                    
                    <!-- Fixed columns at the end -->
                    {% for col in fixed_columns_end %}
                        <td>{{ get_value(row_values, col) }}</td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% else %}
    <p>No data available</p>
{% endif %}




{% set dynamic_columns = [] %}

{% if doc.size %}
    {% for row in doc.size %}
        {% set _dummy = dynamic_columns.append(row.size) %}
    {% endfor %}
{% endif %}

{% set production_text_field = doc.production_text_field %}

{% if production_text_field %}
<br><br>
 <p style="font-size:22px;"><b>Production Table</b></p>
 <br>
    <table class="table_border" style="width:100%;"> 
        <thead>
            <tr>
                <!-- Fixed columns at the start -->
                {% for col in fixed_columns_start %}
                    <th>{{ col }}</th>
                {% endfor %}
                
                <!-- Dynamic columns from row.size -->
                {% for col in dynamic_columns %}
                    <th>{{ col }}</th>
                {% endfor %}
                
                <!-- Fixed columns at the end -->
                {% for col in fixed_columns_end_2 %}
                    <th>{{ col }}</th>
                {% endfor %}
            </tr>
        </thead>
        <tbody>
            {% for row_str in production_text_field[1:-1].split('},{') %}
                <tr>
                    {% set row_str = row_str | replace('{', '') | replace('}', '') %}
                    {% set row_values = row_str.split(',') %}
                    
                    <!-- Helper function to get value for a column -->
                    {% macro get_value(row_values, col) %}
                        {% for val in row_values %}
                            {% set parts = val.split(':') %}
                            {% if parts[0].strip().replace('"', '') == col %}
                                {{ parts[1].strip().replace('"', '') }}
                            {% endif %}
                        {% endfor %}
                    {% endmacro %}
                    
                    <!-- Fixed columns at the start -->
                    {% for col in fixed_columns_start %}
                        <td>{{ get_value(row_values, col) }}</td>
                    {% endfor %}
                    
                    <!-- Dynamic columns from row.size -->
                    {% for col in dynamic_columns %}
                        <td>{{ get_value(row_values, col) }}</td>
                    {% endfor %}
                    
                    <!-- Fixed columns at the end -->
                    {% for col in fixed_columns_end_2 %}
                        <td>{{ get_value(row_values, col) }}</td>
                    {% endfor %}
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% else %}
    <p>No data available</p>
{% endif %}

I’m not sure, but the scroll bar doesn’t seem to work in the PDF.

I think you need to use a landscape format because I see there are many columns. Using landscape will provide a better view.

How can i use landscape, any help, where to change code, or is their some button somewhere ?

Please select the Landscape in Layout.

this setting doesn’t comes directly

also when i open the setting (Ctrl+Shift+P), and change orientation to Landscape

this page opens up everytime, causing no change

How can i do this, is their any other way?
through code or something
The endpoint for Print format if have some landscape code, maybe then it works
http://0.0.0.0:8004/api/method/frappe.utils.print_format.download_pdf?doctype=Order%20Sheet&name=OS00010&format=Order%20Sheet&no_letterhead=1&letterhead=No%20Letterhead&settings={}&_lang=en

Please select the Print, not PDF.

yeah it is working, the pdf is always A4 portrait, therefore we can’t write code in Print format and change the PDF to landscape?
am i right

Add the below line in your code and try it.

<meta name="pdfkit-orientation" content="Landscape"/>
1 Like

how do i remove this

coming when printing, not finding anything in print setting, is it some backend code, can you tell me file where i can find, so that i can comment it
help

Please check it.

1 Like

yes, working

How did you manage to include so many columns in a table. I am trying to create print format with 15 columns in a table. But somehow table is breaking up after some column

This is the HTML Table, not the child table.

Okay. But I am trying to include columns from child table which are 15 in number. And I have written HTML code to render a table. But somehow the columns are breaking up