0

I'm using p:dataExporter to export the contents of my p:dataTable, which has Arabic content. When I export it as Excel it works fine, but if I try to export it as PDF, the Arabic content is not displayed. I'm using iText 2.1.7.

here is my p:dataTable with the p:dataExporter

<p:dataTable id="chequeReport_tbl" value="#{reportsController.listOfChequeReports}"  var="chequeReport"
                             paginator="true" editable="false" rows="10" 
                             tableStyle="width: auto;" style="direction: ltr; text-align: right;margin-top: 5px;margin-bottom:20px"
                             paginatorTemplate="{Exporters} {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             rowsPerPageTemplate="10">
                    <f:facet name="{Exporters}">
                        <div style="float:right;">
                            <h:commandLink actionListener="#{reportsController.generateBankChequeReportPDF()}">
                                <p:graphicImage value="res/images/pdf_2.png" width="12"/>
                            </h:commandLink>
                            <h:commandLink>
                                <p:graphicImage value="res/images/excel.png" width="24"/>
                                <p:dataExporter type="xls" target="chequeReport_tbl" fileName="chequeReport"/>
                            </h:commandLink>
                        </div>
                    </f:facet>
                    <p:column headerText="تاريخ الصرف" style="text-align: center">
                        <h:outputText value="#{chequeReport.exchangeDate}"/>
                    </p:column>
                    <p:column headerText="أسم المستفيد" style="text-align: center">
                        <h:outputText value="#{chequeReport.beneficiaryName}"/>
                    </p:column>
                    <p:column headerText="مبلغ الشيك بالدولار" style="text-align: center">
                        <h:outputText value="#{chequeReport.chequeAmountInDollar}"/>
                    </p:column>
                    <p:column headerText="العملة" style="text-align: center">
                        <h:outputText value="#{chequeReport.currency}"/>
                    </p:column>
                    <p:column headerText="قيمة الشيك" style="text-align: center">
                        <h:outputText value="#{chequeReport.chequeAmount}"/>
                    </p:column>
                    <p:column headerText="تاريخ الإصدار" style="text-align: center">
                        <h:outputText value="#{chequeReport.issuingDate}"/>
                    </p:column>
                    <p:column headerText="القطاع الإقتصادي" style="text-align: center">
                        <h:outputText value="#{chequeReport.financialDep}"/>
                    </p:column>
                    <p:column headerText="الفرع" style="text-align: center">
                        <h:outputText value="#{chequeReport.branch}"/>
                    </p:column>
                    <p:column headerText="رقم الحساب" style="text-align: center">
                        <h:outputText value="#{chequeReport.accountNumber}"/>
                    </p:column>
                    <p:column headerText="رقم الهوية" style="text-align: center">
                        <h:outputText value="#{chequeReport.idNumber}"/>
                    </p:column>
                    <p:column headerText="أسم العميل" style="text-align: center">
                        <h:outputText value="#{chequeReport.customerName}"/>
                    </p:column>
                </p:dataTable>
Ahmad Mousa
  • 33
  • 1
  • 1
  • 6
  • Welcome to Stakoverflow. Please provide a [MCVE](https://stackoverflow.com/help/mcve) Without the code it is difficult to really help you. – Lonzak Feb 06 '19 at 17:45
  • Same as for chinese japanese etc... Try to get it working in a very simple plain piece of code just using itext and maybe some extensions to it and then use the PrimeFaces preprocessor feature to add the relevant code to the exporter. – Kukeltje Feb 06 '19 at 19:45
  • @Lonzak I edited the question with the dataTable that contains the data and dataExporter – Ahmad Mousa Feb 07 '19 at 06:47
  • @Kukeltje I know I can do that, but I have a lot of dataTables that I want to export its data to pdf and every table has different column name and data, so it will be hard to implement code for every table. – Ahmad Mousa Feb 07 '19 at 06:49
  • Then hire someone to do it... it is creating **one** class and adding **one** attribute to each datatable. And next time **please state what you tried and know, would have saved ME 15-30 minutes of searching** – Kukeltje Feb 07 '19 at 06:53
  • @Kukeltje I'm sorry for that, I'm new to stackoverflow. What do you mean buy adding one attribute to each dataTable? Also I'm sorry i'm new to JSF. – Ahmad Mousa Feb 07 '19 at 06:58
  • No offence, but why do you state it is a lot of work then? Using the preprocessor is all in the PrimeFaces docs. And also Q/A on stackoverflow (related to other pdf enhancements, not fonts) – Kukeltje Feb 07 '19 at 07:01
  • I said that because i have around 100 dataTable and every table has different number of columns and different columns names. I searched a lot about the subject before asking and i tried changing font, using special encoding, but nothing worked for me. – Ahmad Mousa Feb 07 '19 at 07:05
  • The problem may be with the default Font which is used by the exporter, so you need to download some arabic font and register it with correct alias, hopefully, exporter will pick it up. – Babl Feb 07 '19 at 07:10
  • @Bable: that is what needs to be done and what I referred to in my first comment. – Kukeltje Feb 07 '19 at 10:34
  • @AhmadMousa: it is not related to the columns at all. And a decent IDE can do the adding of the preprocessor with a 'search/replace' in under 10 minutes. And please reformat your code, it is not visible – Kukeltje Feb 07 '19 at 10:35
  • @AhmadMousa you said you added some data. But you are asking an iText question and I don't see any source code. Where and how do you use iText? Provide your code and we might be able to help you. It is like coming to a car workshop without a car and saying your car doesn't drive. What do you expect the car mechanics will tell you? – Lonzak Feb 07 '19 at 10:41
  • @Kukeltje i tried changing the default Font but still it didn't work. – Ahmad Mousa Feb 07 '19 at 11:08
  • @Lonzak I'm really sorry, I thought the code was added and visible. I use it in p:dataExporter. – Ahmad Mousa Feb 07 '19 at 11:11

1 Answers1

1

Effectively, your question can be (and should have been) split in two questions, both of which have existing Q/A in stackoverflow.

Question 1: How do I display arabic in a PDF when using iText.
Answer 1:   How to display Arabic in PDF created using iText

Question 2: How do I customize the PrimeFaces dataExporter when exporting to PDF
Answer 2:  How do I customize the PDF from a PrimeFaces p:dataExporter, e.g. page size

Combine them and you have your solution.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Thank you, but i already saw these questions but they don't fix my problem. for the first one it only works if i have static data (hard codded), but my data are fetched from database. As for the second question I'm not trying to customize it. And i'm sorry for all the mistakes in the question i'm still new. – Ahmad Mousa Feb 07 '19 at 11:17
  • you **need** to customize it when you want to add these fonts (or override the source of the exporter) – Kukeltje Feb 07 '19 at 13:50