I have HTML content converted to stream- with R2L language content- (Arabic language).
When I create an PDF - Arabic language words jumble. I used google translator
So suppose if I write “هذا هو السطر الأول” - in PDF it is like “ذه وه رطسلا لوأل”—
We are using 17.8.0
But problem is not in 19.5.0
Is it existing bug?
private static Document _document;
private static bool _disposed;
private static byte[] _pdfByteArray;
public void ConverrtToPDF()
{
//read HTMl
var htmlString = File.ReadAllText(@"<path>\HTMLToPDF.html");
ConvercentPdfService(htmlString);
if (_pdfByteArray == null)
{
using (var ms = new MemoryStream())
{
using (var stamp = new PdfFileStamp(_document))
{
var pageNumber = Invariant($"Page: # of {_document.Pages.Count}");
var ft = new FormattedText(
pageNumber,
new FontColor(0, 0, 0),
FontStyle.Helvetica,
EncodingType.Winansi,
false,
10);
stamp.AddPageNumber(ft, 1); //PosBottomRight
//stamp.SaveOptions = new PdfSaveOptions();
_document.Save(ms, SaveFormat.Pdf);
_pdfByteArray = ms.ToArray();
//stamp.Close(); causes CA error
}
}
}
System.IO.File.WriteAllBytes(@"<path>\Test17.8.pdf", _pdfByteArray);
}
public static void ConvercentPdfService(string pdfMarkup)
{
//we need to make sure that markup has control of page margins
var options = new HtmlLoadOptions { PageInfo = { Margin = new MarginInfo(25, 25, 25, 25) } };
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(pdfMarkup)))
{
_document = new Document(stream, options);
_document.Direction = Direction.R2L;
_disposed = false;
}
_document.DisplayDocTitle = true;
_document.FitWindow = true;
_document.CenterWindow = true;
_document.Info.Title = "Convercent PDF";
_document.Info.Author = "";
_document.Info.Subject = "";
_document.Optimize();
}