pdfmake RTL

pdfmake RTL

abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0

i did all steps described in
https://datatables.net/forums/discussion/62113/how-to-reverse-excel-pdf-columns-order-to-rtl#latest
but not worked for me as i attashed to you

i did it as discribed

columnDefs: [
{
targets: '_all',
render: function(data, type, row) {
if (type === 'PDF') {
return data.split(' ').reverse().join(' ');
}
return data;
}
}

but not worked for me

Replies

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    The code you posted is only part of the solution. Colin's example also has this:

          exportOptions: {
            orthogonal: "myExport"
          }
    

    The orthogonal string myExport is to match the type have in the if statement. If you still have problems please provide a link to your page or a test case showing the issue. Or you can update Colin's test case to show the problem.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0

    Yes i did it

    exportOptions: {
    orthogonal: "PDF"
    },

  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0

    next is all my script

    var table=$('<?php echo $id; ?>').DataTable({
    dom: 'Bfrtip',
    "order": [[ 0, "desc" ]],
    "ordering": false,
    buttons: [
    {
    extend: 'pdfHtml5',
    exportOptions: {
    orthogonal: "PDF"
    },
    customize: function (doc) {
    doc.defaultStyle.font = 'Roboto';
    }

                    },
                    'excelHtml5','csvHtml5','copyHtml5',
                ],
                columnDefs: [
                   {
                        targets: '_all',
                        render: function(data, type, row) {
                            if (type === 'PDF') {
                                return data.split(' ').reverse().join(' ');
                            }
                            return data;
                        }
                    }
                ],
                "language": {
                    "url": "{{app()->getLocale()=='ar'?asset('datatable/ar.json'):asset('datatable/en.json')}}"
                }
            });
    
  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Is the RTL code working now?

    Kevin

  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0

    No, it display statements words from left to right

  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0
    edited April 2021

    next is all my datatable code

    var table=$('<?php echo $id; ?>').DataTable({
                    dom: 'Bfrtip',
                    "order": [[ 0, "desc" ]],
                    "ordering": false,
                    buttons: [
                        {
                            extend: 'pdfHtml5',
                            exportOptions: {
                                orthogonal: "PDF"
                            },
                            customize: function (doc) {
                                doc.defaultStyle.font = 'Roboto';
                        
                            }
    
                        },
                        'excelHtml5','csvHtml5','copyHtml5',
                    ],
                    columnDefs: [
                        {
                             targets: '_all',
                            render: function(data, type, row) {
                                if (type === 'PDF') {
                                    return data.split(' ').reverse().join(' ');
                                }
                                 return data;
                             }
                        }
                    ],
                    "language": {
                        "url": "{{app()->getLocale()=='ar'?asset('datatable/ar.json'):asset('datatable/en.json')}}"
                    }
                });
    
  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Please can you update my example (in Kevin's post) above to demonstrate this, it'll be easier for us to debug if we can see it,

    Colin

  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0

    but arabic language not worked in your example, i already proccess that by changing the default font to other one in my work, i think your solution is correct may be not worked for me with the font that i used, i will try to solve it, thank you

  • abdosaeedabdosaeed Posts: 12Questions: 2Answers: 0
    edited June 2020

    it now worked for me, i have mistak in return key word not implemented in my editor code as i did her, the all datatable reversed correctly except the header, is there any work around , thank you for help

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This example shows how to colour the header cells - that shows where you need to make the edit, then you would use the code as before to flip the words,

    Colin

  • EmadeldeenEmadeldeen Posts: 1Questions: 0Answers: 0

    abdosaeed, Could you send the code that worked with you.

  • omar_helalomar_helal Posts: 1Questions: 0Answers: 0

    Emadeldeen , Code ?

  • mr2adammr2adam Posts: 1Questions: 0Answers: 0

    could you please share the final PDFMake RTL code

  • xbox2007xbox2007 Posts: 2Questions: 0Answers: 0

    hello
    please can you share Arabic RTL code

    thanks a lot

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This example from this thread demonstrates the reversing of the words,

    Colin

  • xbox2007xbox2007 Posts: 2Questions: 0Answers: 0

    thanks a lot for your replay .
    but i looking for Arabic PDF Example

    Arabic latter's not show in PDF

    thanks again

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    That'll be a font issue, you need to include all the necessary fonts - see this thread: https://datatables.net/forums/discussion/comment/138501#Comment_138501

    Colin

  • mostafamedhtmostafamedht Posts: 2Questions: 0Answers: 0

    hi @colin
    this a screenshot for same problem, of reverse word in Arabic
    I did all steps explained here from you and Keivin

    $(document).ready( function () {
                var table = $("#example1").DataTable({
                    dom: "Bfrtip",
                    "buttons": [{
                    extend: "pdfHtml5",
                    orientation: 'landscape',
                    pageSize: 'A4',
                    exportOptions: {
                        orthogonal: "myExport",
                        columns: [4, 3, 2, 1, 0],
                    },
                    customize: function (doc) {
                        doc.defaultStyle =
                        {
                            font: 'Cairo',
                        };
                            doc.styles.tableBodyEven.alignment = "center";
                            doc.styles.tableBodyOdd.alignment = "center";
                        },
                    }, {
                            extend: 'excelHtml5',
                            exportOptions: {
                                columns: ':visible'
                            }
                        },],
                    columnDefs: [
                    {
                        // targets: '_all',
                        targets: "hiddenCols", visible: false,
                        render: function(data, type, row) {
                        if (type = 'myExport') {
                            return data.split(' ').reverse().join(' ');
                        }
                            return data;
                        }
                    }
                    ]
                });
            });
    

  • mostafamedhtmostafamedht Posts: 2Questions: 0Answers: 0

    Hi @colin
    I did all the steps here, but it did not work for me

    $(document).ready( function () {
                var table = $("#example1").DataTable({
                    dom: "Bfrtip",
                    "buttons": [{
                    extend: "pdfHtml5",
                    orientation: 'landscape',
                    pageSize: 'A4',
                    exportOptions: {
                        orthogonal: "myExport",
                        columns: [4, 3, 2, 1, 0],
                    },
                    customize: function (doc) {
                        doc.defaultStyle =
                        {
                            font: 'Cairo',
                        };
                            doc.styles.tableBodyEven.alignment = "center";
                            doc.styles.tableBodyOdd.alignment = "center";
                        },
                    }, {
                            extend: 'excelHtml5',
                            exportOptions: {
                                columns: ':visible'
                            }
                        },],
                    columnDefs: [
                    {
                        // targets: '_all',
                        targets: "hiddenCols", visible: false,
                        render: function(data, type, row) {
                        if (type = 'myExport') {
                            return data.split(' ').reverse().join(' ');
                        }
                            return data;
                        }
                    }
                    ]
                });
            });
    
  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • hsm_senderhsm_sender Posts: 1Questions: 0Answers: 0

    hi here is my code for persian ltr to rtl this is a function that's can use in datatable to export as pdf :

    function buttonForDatatable(columns, margins, prtrait = "portrait",title='',message='') {
                return [
                     {
                extend: 'copy',
                text:"کپی",
                exportOptions: {
    
                    columns: columns.reverse(),
    
                },
    
            },  {
                extend: 'csv',
                text:"سی اس وی",
                exportOptions: {
    
                    columns: columns.reverse(),
    
                },
    
            },  {
                extend: 'print',
                text:"پرینت",
                exportOptions: {
    
                    columns: columns.reverse(),
    
                },
    
            }, {
                extend: 'excel',
                text:"اکسل",
                exportOptions: {
    
                    columns: columns,
    
                },
    
            }  ,{
                        extend: 'pdfHtml5',
                        orientation: prtrait,
                        footer: true,
                        alignment: "center",
                        title: title,
                        messageTop:message,
                        text: "PDF",
                        exportOptions: {
                            alignment: "center",
                            orthogonal: "PDF",
                            columns: columns,
                            modifier: {order: 'index', page: 'current'}
    
                        },
                        customize: function (doc) {
                            doc.styles.message.alignment = "right";
                            doc.styles.tableBodyEven.alignment = "center";
                            doc.styles.tableBodyOdd.alignment = "center";
                            doc.styles.tableFooter.alignment = "center";
                            doc.styles.tableHeader.alignment = "center";
                            doc.content[0]['text'] = doc.content[0]['text'].split(' ').reverse().join(' ');
                            doc.content[1].margin = margins;
                            doc.content[2].margin = margins;
                            for (var i = 0; i < doc.content[2].table.body.length; i++) {
                                // console.log(doc.content[1].table.body[i].length);
                                for (var j = 0; j < doc.content[2].table.body[i].length; j++) {
                                    doc.content[2].table.body[i][j]['text'] = doc.content[2].table.body[i][j]['text'].split(' ').reverse().join(' ');
                                }
                            }
                        }
                    }
                ];
            }
    

    and after that you are can use same as here :

     table = $('#mydatatable').DataTable({
                    language: language,
                    "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "all"]],
                    dom: 'Blfrtip',
                    buttons: buttonForDatatable([2, 3, 4], [0, 0, 0, 0]),
                    processing: true,
                    serverSide: true,
    .....
    
  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Nice, thanks for sharing,

    Colin

  • abanobrabanobr Posts: 1Questions: 0Answers: 0

    i have a proplem that when i export pdf in arabic it makes

    but english works well

Sign In or Register to comment.