X

The Oracle APEX blog is your source for APEX news, technical tips and strategic direction

Supporting Arabic and Hebrew in PDF Printing - APEX 21.1

Salim Hlayel
Principal Product Manager

Built-in Printing History

Native PDF Printing feature was added back in Oracle APEX 20.1. The support was only available to Interactive Grids by then. In Oracle APEX 20.2 more enhancements have been added to the report printing such as:

  • Built-in PDF printing and Excel download
    Built-in APIs to print PDF and download Excel in interactive reports and classic reports.
  • Interactive Report - Send E-Mail
    All download formats can now be attached.
  • Enhanced integration with Oracle BI Publisher
  • New APIs to generate files
    Introduced new APEX_REGION.EXPORT_DATA and APEX_DATA_EXPORT APIs to programmatically generate PDF, CSV, Excel, HTML, JSON and XML files.
  • More language support
    Built-in PDF now supports Chinese, Japanese, and Korean languages.

You can read more about that in detail in Exploring Report Printing in APEX 20.2 blog post. 

In Oracle APEX 21.1, one of the features that some customers have been waiting for is the ability to print PDF files in Arabic and Hebrew languages. 

Report printing now supports complex text layout languages, such as Arabic and Hebrew, when exporting to PDF.

In this blog post, I will take you through a quick journey of testing that.

Dataset Preparation

In order to test this, we will use a sample dataset for some Arabic poems written by great historic poets.

The following is a SQL Script to create a table and populates it with poems from three famous poets. Use SQL Scripts under SQL Workshop to apply the code.

CREATE TABLE "ARABIC_POEMS" 
(	"ID" NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE  NOKEEP  NOSCALE , 
	"امرئ_القيس" VARCHAR2(255), 
	"المتنبي" VARCHAR2(255), 
	"الخنساء" VARCHAR2(255)
) ;
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (1,'قفا نبك من ذِكرى حبيب ومنزل  *  بسِقطِ اللِّوى بينَ الدَّخول فحَوْمل','عَلى قَدْرِ أهْلِ العَزْم تأتي العَزائِمُ  *  وَتأتي علَى قَدْرِ الكِرامِ المَكارمُ','قذى بعينكِ امْ بالعينِ عوَّارُ  *  أمْ ذرَّفتْ اذْخلتْ منْ اهلهَا الدَّار');
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (2,'فتوضح فالمقراة لم يَعفُ رسمها  *  لما نسجتْها من جنوب وَشَمْأل','وَتَعْظُمُ في عَينِ الصّغيرِ صغارُها  *  وَتَصْغُرُ في عَين العَظيمِ العَظائِمُ','كأنّ عيني لذكراهُ إذا خَطَرَتْ  *  فيضٌ يسيلُ علَى الخدَّينِ مدرار');
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (3,'ترى بَعَرَ الأرْآمِ في عَرَصاتِها  *  وقيعانها كأنه حبَّ فلفل','يُكَلّفُ سيفُ الدّوْلَةِ الجيشَ هَمّهُ  *  وَقد عَجِزَتْ عنهُ الجيوشُ الخضارمُ','تبكي لصخر هي العبرَى وَقدْ ولهتْ  *  وَدونهُ منْ جديدِ التُّربِ استار');
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (4,'كأني غَداة البَيْنِ يَوْمَ تَحَمَلّوا   *  لدى سَمُراتِ الحَيّ ناقِفُ حنظل','وَيَطلُبُ عندَ النّاسِ ما عندَ نفسِه  *  وَذلكَ ما لا تَدّعيهِ الضّرَاغِمُ','تبكي خناس فما تنفكُّ مَا عمرت  *  لها علَيْهِ رَنينٌ وهيَ مِفْتار');
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (5,'وقوفاًبها صَحْبي عَليَّ مَطِيَّهُمْ يقُولون لا تهلكْ أسى وتجمّل','هَلِ الحَدَثُ الحَمراءُ تَعرِفُ لوْنَها  *  وَتَعْلَمُ أيُّ السّاقِيَيْنِ الغَمَائِمُ','تبكي خناسٌ علَى صخرٍ وحقَّ لهَا  *  إذ رابهَا الدَّهرُ انَّ الدَّهرَ ضرَّار');
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (6,'وإنَّ شفائي عبرة مهراقة   *  فهلْ عند رَسمٍ دارِسٍ من مُعوَّل','سَقَتْها الغَمَامُ الغُرُّ قَبْلَ نُزُولِهِ  *  فَلَمّا دَنَا مِنها سَقَتها الجَماجِمُ','لاَ بدَّ منْ ميتة في صرفهَا عبر  *  وَالدَّهرُ في صرفهِ حولٌ وأطوار');
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (7,'كدأبكَ من أمِّ الحويَرثِ قبلها  *  وجارتها أمَّ الربابِ بمأسل','بَنَاهَا فأعْلى وَالقَنَا يَقْرَعُ القَنَا  *  وَمَوْجُ المَنَايَا حَوْلَها مُتَلاطِمُ','قدْ كانَ فيكمْ أبو عمرو يسودكم  *  نِعْمَ المُعَمَّمُ للدّاعينَ نَصّار');
Insert into ARABIC_POEMS (ID,"امرئ_القيس","المتنبي","الخنساء") values (8,'فَفاضَت دُموعُ العَينِ مِنّي صَبابَة  *   على النَحرِ حَتى بَلَّ دَمعِيَ مِحمَلي','وَكانَ بهَا مثْلُ الجُنُونِ فأصْبَحَتْ  *  وَمِنْ جُثَثِ القَتْلى عَلَيْها تَمائِمُ','صلبُ النَّحيزة وَهَّاب إذَا منعُوا  *  وفي الحروبِ جريءُ الصّدْرِ مِهصَار');

Application Preparation

Next, we will create an empty application setting its Primary Language to Arabic (ar) and Document Direction to Right-To-Left from the Globalization tab in Shared Components. We can utilize the new User Interface and Theme Enhancements to beautify our application a bit. Then, on the home page, we will create a Classic Report based on the above-generated table.

Our application can look similar to the below image now:

Classic Report's Printing feature has to be enabled first so we are able to click the "Print" link to start printing. In our case, the "Print" text has been replaced with the equivalent Arabic word.

Under the "Printing" tab we can change the layout and provide some Arabic header and footer to our generated PDF. We will increase the font size a little for the page header and footer texts.

PDF Printing in Arabic

If we run our application and click on the Arabic print text "طباعة" the PDF file will be generated and available for download.

The generated PDF should display the Arabic text which is similar to how the text looks on the application's page.

This includes the extra Arabic marks as you can see in the following image:

The same can be done to generate Hebrew text as well.

The PDF generation for reports with complex text layout languages like Arabic has a layer of complexity. It requires specifying a document direction, rendering Bi-Directional texts, replacing default glyphs depending on their position in a word. 
The following link shows some of that complexity: https://increment.com/programming-languages/unplain-text-primer-on-non-latin/
 
Oracle APEX 21.1 takes care of such complexity for you. 
During PDF generation, the text is analyzed, and the Unicode Bidirectional Algorithm is applied to render the text in its visual order.
The Document Direction of your application is now also used to set the base direction of your PDF report.

Summary

Oracle Application Express (APEX) continues to add more features to the built-in printing engine. In the recent release, Arabic and Hebrew have been added to the list of supported languages.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.