i have issue with python Arabic text #874
-
I use Python program and I have to export excel data to pdf and it work okey with English’s text But when I have arabic text in excel and export it to pdf It comes like black squares I attack looks of pdf after save it as pdf and also there is the code below of def save pdf Library Code: from bidi.algorithm import get_display
import arabic_reshaper
from reportlab.lib import colors
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
def save_as_pdf(self, result, font_size=12):
# Prompt the user to select the save location
save_dialog = QFileDialog()
save_dialog.setWindowTitle("Save PDF File")
save_dialog.setNameFilter("PDF Files (*.pdf)")
save_dialog.setDefaultSuffix("pdf") # Set the default file extension
save_dialog.setAcceptMode(QFileDialog.AcceptSave)
if save_dialog.exec():
file_path = save_dialog.selectedFiles()[0]
# Check if a file was selected
if file_path:
# Create a PDF document
doc = SimpleDocTemplate(file_path, pagesize=landscape(A4))
# Get the available page width and height in landscape orientation
page_width, page_height = landscape(A4)
# Define the table data and style
# Reshape and reorient Arabic text
reshaped_table_data = []
for row in result.values.tolist():
reshaped_row = [get_display(arabic_reshaper.reshape(str(item))) for item in row]
reshaped_table_data.append(reshaped_row)
reshaped_columns = [get_display(arabic_reshaper.reshape(str(item))) for item in result.columns]
table_data = [reshaped_columns] + reshaped_table_data
table_style = TableStyle([
('BACKGROUND', (0, 0), (-1, 0), colors.lightgrey),
('TEXTCOLOR', (0, 0), (-1, 0), colors.black),
('ALIGN', (0, 0), (-1, -1), 'RIGHT'),
('FONTNAME', (0, 0), (-1, 0), 'Arial'), # Use the font you registered
('FONTSIZE', (0, 0), (-1, 0), 7),
('BOTTOMPADDING', (0, 0), (-1, 0), 7),
('BACKGROUND', (0, 1), (-1, -1), colors.beige),
('GRID', (0, 0), (-1, -1), 1, colors.black)
])
# Create a table with the data and style
table = Table(table_data)
table.setStyle(table_style)
# Build the PDF document with the table
elements = [table]
doc.build(elements)
QMessageBox.information(None, "DONE") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @Monther1990 Sorry but I will not be able to help you. Your are using For support when using ReportLabs, you should check there: |
Beta Was this translation helpful? Give feedback.
Hi @Monther1990
Sorry but I will not be able to help you.
Your are using
reportlabs
in your code.This is the GitHub project for
fpdf2
, which is another Python library that can render PDF documents.For support when using ReportLabs, you should check there:
https://www.reportlab.com/support/