Forum Replies Created

Viewing 3 replies - 16 through 18 (of 18 total)
  • Hi msaudi,
    to fix Arabic characters support problem in PDF
    you should follow these steps to integrate ar-php library for khaled.alshamaa inside dompdf library
    so, please follow these steps:

    1- download the ar-php library for khaled.alshamaa from the following link

    https://www.ar-php.org/

    2 – upload I18N folder to the path on your site

    \wp-content\plugins\woocommerce-pdf-invoices-packing-slips\lib

    3-in text_renderer.cls.php file

    woocommerce-pdf-invoices-packing-slips/lib/dompdf/include/text_renderer.cls.php

    before this line

    $this->_canvas->text($x, $y, $text

    add this code

    if ( ! class_exists( 'I18N_Arabic' ) ){
    
    	require_once( WooCommerce_PDF_Invoices::$plugin_path ."lib/I18N/Arabic/Glyphs.php" );
    	$Arabic = new I18N_Arabic_Glyphs('Glyphs');
    	$text = $Arabic->utf8Glyphs($text);
    
    		}

    4-you should use custom arabic font , so follow this steps

    download any custom Arabic font , for Example you can use this font or other

    https://www.arfonts.net/fonts/e3lan-unicode/alhurratxtlight.zip

    extract it in this path

    \wp-content\plugins\woocommerce-pdf-invoices-packing-slips\templates\pdf\Simple

    replace style.css content with this code

    <?php global $wpo_wcpdf;?>
    /* Main Body */
    @font-face {
    	font-family: 'alhurratxtlight';
    	font-style: normal;
    	font-weight: normal;
    	src: local('alhurratxtlight'), local('alhurratxtlight'), url(<?php echo $wpo_wcpdf->export->template_path; ?>/alhurratxtlight.ttf) format('truetype');
    }
    
    @page {
    	margin-top: 1cm;
    	margin-bottom: 3cm;
    	margin-left: 2cm;
    	margin-right: 2cm;
    	font-family: 'alhurratxtlight', sans-serif !important;
    	direction:rtl;
    }
    body {
    	background: #fff;
    	color: #000;
    	margin: 0cm;
    	font-family: 'alhurratxtlight', sans-serif !important;
    	font-size: 9pt;
    	line-height: 100%; /* fixes inherit MPDF bug */
    	direction:rtl;
    
    }
    
    h1, h2, h3, h4 {
    	font-weight: normal;
    	margin: 0;
    	font-family: 'alhurratxtlight', sans-serif !important;
    
    }
    
    h1 {
    	font-size: 16pt;
    	margin: 5mm 0;
    	font-family: 'alhurratxtlight', sans-serif !important;
    
    }
    
    h2 {
    	font-size: 14pt;
    	font-family: 'alhurratxtlight', sans-serif !important;
    
    }
    
    h3, h4 {
    	font-size: 9pt;
    
    }
    
    ol,
    ul {
    	list-style: none;
    	margin: 0;
    	padding: 0;
    }
    
    li,
    ul {
    	margin-bottom: 0.75em;
    }
    
    p {
    	margin: 0;
    	padding: 0;
    }
    
    p + p {
    	margin-top: 1.25em;
    }
    
    a {
    	border-bottom: 1px solid;
    	text-decoration: none;
    }
    
    /* Basic Table Styling */
    table {
    	border-collapse: collapse;
    	border-spacing: 0;
    	page-break-inside: always;
    	border: 0;
    	margin: 0;
    	padding: 0;
    	font-family: 'alhurratxtlight', sans-serif !important;
    }
    
    th, td {
    	vertical-align: top;
    	text-align: left;
    }
    
    table.container {
    	width:100%;
    	border: 0;
    }
    
    tr.no-borders,
    td.no-borders {
    	border: 0 !important;
    	border-top: 0 !important;
    	border-bottom: 0 !important;
    	padding: 0 !important;
    	width: auto;
    }
    
    /* Header */
    table.head {
    	margin-bottom: 12mm;
    	font-family: 'alhurratxtlight', sans-serif !important;
    }
    
    td.header img {
    	max-height: 3cm;
    	width: auto;
    }
    
    td.header {
    	font-size: 16pt;
    	font-weight: 100;
    }
    
    td.shop-info {
    	width: 40%;
    }
    .document-type-label {
    	text-transform: uppercase;
    }
    
    /* Recipient addressses & order data */
    table.order-data-addresses {
    	width: 100%;
    	margin-bottom: 10mm;
    }
    
    td.order-data {
    	width: 40%;
    }
    
    .invoice .shipping-address {
    	width: 30%;
    }
    
    .packing-slip .billing-address {
    	width: 30%;
    }
    
    td.order-data table th {
    	font-weight: normal;
    	padding-right: 2mm;
    }
    
    /* Order details */
    table.order-details {
    	width:100%;
    	margin-bottom: 8mm;
    }
    
    .quantity,
    .price {
    	width: 20%;
    }
    
    .order-details tr {
    	page-break-inside: always;
    	page-break-after: auto;
    }
    
    .order-details td,
    .order-details th {
    	border-bottom: 1px #ccc solid;
    	padding: 0.375em;
    }
    
    .order-details th {
    	font-weight: normal;
    	text-align: left;
    }
    
    .order-details thead th {
    	color: white;
    	background-color: black;
    	border-color: black;
    }
    
    dl {
    	margin: 4px 0;
    }
    
    dt, dd, dd p {
    	display: inline;
    	font-size: 7pt;
    	line-height: 7pt;
    }
    
    dd {
    	margin-left: 5px;
    }
    
    dd:after {
    	content: "\A";
    	white-space: pre;
    }
    
    /* Notes & Totals */
    .customer-notes {
    	margin-top: 5mm;
    }
    
    table.totals {
    	width: 100%;
    	margin-top: 5mm;
    }
    
    table.totals th,
    table.totals td {
    	border: 0;
    	border-top: 1px solid #ccc;
    	border-bottom: 1px solid #ccc;
    }
    
    table.totals th.description,
    table.totals td.price {
    	width: 50%;
    }
    
    table.totals tr:last-child td,
    table.totals tr:last-child th {
    	border-top: 2px solid #000;
    	border-bottom: 2px solid #000;
    	font-weight: normal;
    }
    
    table.totals tr.payment_method {
    	display: none;
    }
    
    /* Footer Imprint */
    #footer {
    	position: absolute;
    	bottom: -2cm;
    	left: 0;
    	right: 0;
    	height: 2cm; /* if you change the footer height, don't forget to change the bottom (=negative height) and the @page margin-bottom as well! */
    	text-align: center;
    	border-top: 0.1mm solid gray;
    	margin-bottom: 0;
    	padding-top: 2mm;
    	font-family: 'alhurratxtlight', sans-serif !important;
    }

    its the only good solution to fix Arabic language character in dompdf library

    thanks

    Hi ThosEnt to fix this problem
    in [website]/wp-content/plugins/mage-reviews/core/mage-cast.php
    replace
    $string = preg_replace('/[^A-Za-z0-9_-\s]/', '', $string);

    with
    $string = preg_replace('/^([-\w\s])+$/i', '', $string);

    Hi Nick ,
    if you want to fix Hebrew words/phrases reversed problem in PDF you can use this code in this file
    woocommerce-pdf-invoices-packing-slips/lib/dompdf/include/text_renderer.cls.php

    before this line
    $this->_canvas->text($x, $y, $text

    add this code

    if (strtolower($style->direction) == 'rtl' && !mb_detect_encoding($text, array("ASCII"))) {
      preg_match_all('/./us', $text, $ar);
      $text = join('',array_reverse($ar[0]));
      // if there are numbers in the string
      // so the next line reverse the number back
      // treat also numbers with dot (decimal) and email
      $text = preg_replace_callback('/\d+-\d+|\d+|\d+\.\d+|\S+@\S+/', function (array $m) { return strrev($m[0]); }, $text);
    
    }

    this will fix reversed letters

Viewing 3 replies - 16 through 18 (of 18 total)