Я генерирую 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
ITEXT PDF Персидский текст Проблема рендеринга - персонажи кажутся сломанными ⇐ C#
Место общения программистов C#
1755072416
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>
Подробнее здесь: [url]https://stackoverflow.com/questions/79733097/itext-pdf-persian-text-rendering-issue-characters-appear-broken[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия