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: 21,330Questions: 26Answers: 4,951

    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: 21,330Questions: 26Answers: 4,951

    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,240Questions: 1Answers: 2,599

    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,240Questions: 1Answers: 2,599

    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,240Questions: 1Answers: 2,599

    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,240Questions: 1Answers: 2,599

    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,240Questions: 1Answers: 2,599

    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,240Questions: 1Answers: 2,599

    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

  • marcobarsoummarcobarsoum Posts: 4Questions: 0Answers: 1

    final solution:
    1. encode your font (that font you need to use) using this page: https://www.giftofspeed.com/base64-encoder/
    2. download vfs_fonts.js >> https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js
    3. take encoded font text , and replace it with text of Roboto font , in each line in vfs_fonts.JS (4 times) , to change effect of font Roboto into your font characters..

    good luck

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Nice one - thanks for posting back with your solution.

    Allan

  • marcobarsoummarcobarsoum Posts: 4Questions: 0Answers: 1
    edited April 27

    :wink:

  • marcobarsoummarcobarsoum Posts: 4Questions: 0Answers: 1
    edited April 28

    you can find full solution expalined in my last comment Here

Sign In or Register to comment.