I'm having trouble getting landscape to work when exporting to pdf

I'm having trouble getting landscape to work when exporting to pdf

stycode7stycode7 Posts: 3Questions: 2Answers: 0
edited December 2021 in TableTools

Hi, I'm able to export to pdf, but it always does so in portrait. I tried adding the orientation option but it doesn't seem to be working. What am I doing wrong?

$( document ).ready(function() {
    $('#report').DataTable({
             "processing": true,
             "dom": 'lBfrtip',
             "buttons": [
                {
                    extend: 'collection',
                    text: 'Export',
                orientation: 'landscape',
                    buttons: [
                        'copy',
                        'excel',
                        'csv',
                        'pdf',
                        'print'
                    ]
                }
            ]
            });
    });

This question has an accepted answers - jump to answer

Answers

  • desperadodesperado Posts: 143Questions: 30Answers: 4
    Answer ✓

    You are placing orientation on the wrong element. You need to extend pdf and add the orientation. Like this.

                    {
                        extend: 'collection',
                        text: 'PDF',
                        collectionLayout: 'rcoi-dt-pdf-button-group-hack',
                        autoClose: true,
                        buttons: [
                            {
                                extend: 'pdfHtml5',
                                text: 'Portrait',
                                title: 'rCOI Disclosures',
                                exportOptions: {
                                    columns: ':visible', orthogonal: 'print'
                                }
                            },
                            {
                                extend: 'pdfHtml5',
                                text: 'Portrait legal',
                                pageSize: 'LEGAL',
                                title: 'rCOI Disclosures',
                                exportOptions: {
                                    columns: ':visible', orthogonal: 'print'
                                }
                            },
                            {
                                extend: 'pdfHtml5',
                                text: 'Landscape',
                                orientation: 'landscape',
                                title: 'rCOI Disclosures',
                                exportOptions: {
                                    columns: ':visible', orthogonal: 'print'
                                }
                            },
                            {
                                extend: 'pdfHtml5',
                                text: 'Land. legal',
                                pageSize: 'LEGAL',
                                orientation: 'landscape',
                                title: 'rCOI Disclosures',
                                exportOptions: {
                                    columns: ':visible', orthogonal: 'print'
                                }
                            }
                        ]
                    },
    
Sign In or Register to comment.