мы сталкиваемся с той же проблемой с арабским c при конвертации pdf из html с арабским c словом при конвертации в pdf, поэтому pdf будет как арабское c слово как обратное. который неправильно.
private bool CreatePDFFromHTMLString(string HtmlStream, string FileName, bool setWidth) {
WriteLogFile.WriteRequestLog("Convert Html To PDF Start-------------------------- " + DateTime.Now.ToString(), "HtmlToPdf", "HtmlToPDFConvert");
WriteLogFile.WriteRequestLog(HtmlStream, "HtmlToPdf", "HtmlToPDFConvert");
WriteLogFile.WriteRequestLog("-------------------------", "HtmlToPdf", "HtmlToPDFConvert");
WriteLogFile.WriteRequestLog(FileName, "HtmlToPdf", "HtmlToPDFConvert");
WriteLogFile.WriteRequestLog("-------------------------", "HtmlToPdf", "HtmlToPDFConvert");
try {
object TargetFile = FileName; string ModifiedFileName = string.Empty;
string FinalFileName = string.Empty;
ModifiedFileName = TargetFile.ToString();
ModifiedFileName = ModifiedFileName.Insert(ModifiedFileName.Length - 4, "1");
FileStream fileOutputStream = new FileStream(FileName, FileMode.Create);
WriteLogFile.WriteRequestLog("PDF Writer Object---", "HtmlToPdf", "HtmlToPDFConvert");
PdfWriter pdfWriter = new PdfWriter(fileOutputStream);
ConverterProperties converterProperties = new ConverterProperties();
WriteLogFile.WriteRequestLog("Generate Document Object---", "HtmlToPdf", "HtmlToPDFConvert");
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
WriteLogFile.WriteRequestLog("Get Font---", "HtmlToPdf", "HtmlToPDFConvert");
string font = $"{WebConfigurationManager.AppSettings["Unicode.fontPath"]}ARIALUNI.TTF";
string afont = $"{WebConfigurationManager.AppSettings["Unicode.fontPath"]}arial.TTF";
// string arfont = $"{WebConfigurationManager.AppSettings["Unicode.fontPath"]}NotoNaskhArabic-Regular.ttf";
FontProvider fontProvider = new DefaultFontProvider(false,false,false);
WriteLogFile.WriteRequestLog("Create Fonts---", "HtmlToPdf", "HtmlToPDFConvert");
WriteLogFile.WriteRequestLog("Create ARIALUNI Font---", "HtmlToPdf", "HtmlToPDFConvert");
fontProvider.AddFont(FontProgramFactory.CreateFont(font));
WriteLogFile.WriteRequestLog("Create Arial Font---", "HtmlToPdf", "HtmlToPDFConvert");
fontProvider.AddFont(FontProgramFactory.CreateFont(afont));
//fontProvider.AddFont(FontProgramFactory.CreateFont(arfont));
converterProperties.SetFontProvider(fontProvider);
WriteLogFile.WriteRequestLog("Set Page Size", "HtmlToPdf", "HtmlToPDFConvert");
//For setting the PAGE SIZE
PageSize pageSize = new PageSize(PageSize.A4);
if (setWidth)
pageSize.SetWidth(pageSize.GetWidth() * 2);
pdfDocument.SetDefaultPageSize(pageSize);
WriteLogFile.WriteRequestLog("Convert to Document start", "HtmlToPdf", "HtmlToPDFConvert");
Document document = new Document(pdfDocument, pageSize);
document = HtmlConverter.ConvertToDocument(HtmlStream, pdfDocument, converterProperties);
document.Close();
WriteLogFile.WriteRequestLog("Document Close", "HtmlToPdf", "HtmlToPDFConvert");
return true;
}
catch (Exception ex)
{
WriteLogFile.WriteRequestLog(ex.Message, "HtmlToPdf", "HtmlToPDFConvert");
WriteLogFile.WriteRequestLog("-------------------------", "HtmlToPdf", "HtmlToPDFConvert");
return false;
}
}