ITEXT PDF Персидский текст Проблема рендеринга - персонажи кажутся сломаннымиC#

Место общения программистов C#
Ответить
Anonymous
 ITEXT PDF Персидский текст Проблема рендеринга - персонажи кажутся сломанными

Сообщение Anonymous »

Я генерирую PDF, используя ITEXT (версия 9.2.0) в C#.
PDF содержит персидский (FARSI) текст, но символы не отображаются правильно - они кажутся разделенными или сломанными. < /p>
Вот мой код: < /p>
public async Task GenerateOrderPdf(Guid orderId, CancellationToken cancellationToken)
{
var order = await _orderRepository.GetOrderById(orderId, cancellationToken);
var orderServicesList = await _orderServicesRepository.GetOrderServices(orderId, cancellationToken);
var serviceIds = orderServicesList.Select(x => x.ServiceId);
var services = await _serviceRepository.GetServices(serviceIds, cancellationToken);

using var stream = new MemoryStream();
var writer = new PdfWriter(stream);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);

var vazirFontPath = Path.Combine(AppContext.BaseDirectory, "Resources", "Fonts", "Vazirmatn-Regular.ttf");
var vazirFont = PdfFontFactory.CreateFont(vazirFontPath, PdfEncodings.IDENTITY_H);

document.Add(new Paragraph($"جزئیات سفارش - کد #{order.OrderCode}")
.SetFontSize(20)
.SetTextAlignment(TextAlignment.RIGHT)
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont));

document.Add(new Paragraph("وضعیت : " + order.Status)
.SetTextAlignment(TextAlignment.RIGHT)
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont));

document.Add(new Paragraph("تاریخ ایجاد : " + order.CreateDate.ToString("yyyy-MM-dd"))
.SetTextAlignment(TextAlignment.RIGHT)
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont));

document.Add(new Paragraph("تاریخ پرداخت : " + order.ProcessedAt?.ToString("yyyy-MM-dd"))
.SetTextAlignment(TextAlignment.RIGHT)
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont));

document.Add(new Paragraph("آخرین تغییر وضعیت : " + order.LastStateChange?.ToString("yyyy-MM-dd"))
.SetTextAlignment(TextAlignment.RIGHT)
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont));

document.Add(new Paragraph(" ")
.SetFontSize(15));

var table = new Table(new float[] { 1, 1, 1, 1 });
table.SetWidth(UnitValue.CreatePercentValue(100))
.SetFont(vazirFont)
.SetTextAlignment(TextAlignment.CENTER);

var headerBgColor = new iText.Kernel.Colors.DeviceRgb(238, 238, 238);
table.AddHeaderCell(new Cell()
.SetBackgroundColor(headerBgColor)
.Add(new Paragraph("خدمت")
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont)));
table.AddHeaderCell(new Cell()
.SetBackgroundColor(headerBgColor)
.Add(new Paragraph("سیستم خدمت")
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont)));
table.AddHeaderCell(new Cell()
.SetBackgroundColor(headerBgColor)
.Add(new Paragraph("وضعیت")
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont)));
table.AddHeaderCell(new Cell()
.SetBackgroundColor(headerBgColor)
.Add(new Paragraph("جزئیات")
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont)));

foreach (var os in orderServicesList)
{
var serviceName = services.FirstOrDefault(x => x.Id == os.ServiceId)?.Name?.GetValue() ?? "";

table.AddCell(new Cell().Add(new Paragraph(serviceName)
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont)));

table.AddCell(new Cell().Add(new Paragraph(os.ServiceSystem.ToString())
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont)));

var statusCell = new Cell().Add(new Paragraph(os.Status.ToString())
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont));
if (os.Status.ToString() == "ناموفق")
{
var redBgColor = new iText.Kernel.Colors.DeviceRgb(255, 204, 204);
statusCell.SetBackgroundColor(redBgColor);
}
table.AddCell(statusCell);

table.AddCell(new Cell().Add(new Paragraph(os.DeleteStatus.ToString())
.SetBaseDirection(iText.Layout.Properties.BaseDirection.RIGHT_TO_LEFT)
.SetFont(vazirFont)));
}

document.Add(table);
document.Close();

return stream.ToArray();
}
< /code>
Вот часть PDF, которая показывает проблемы:
< /p>
Я пробовал персидские фонты, я пробовал. Pdffontfactory.createfont () с pdfencodings.identity_h
Я видел, что у ITEXT есть что -то, что называется pdfcalligraph, но я не уверен, как его использовать < /p>

Подробнее здесь: https://stackoverflow.com/questions/797 ... ear-broken
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»