Я использую страницы Razor для выставления счета-фактуры и экспортирую его в файл PDF
Я пытаюсь экспортировать детали счета-фактуры (номер счета, название компании,....) в PDF-файл, но в PDF-файле появляется арабское слово вот так: ةروتافلا مقر.
Я использовал все шрифты Windows, но безрезультатно, это мой код csthml.cs
Что мне следует сделать, чтобы правильно отображать арабские слова, а также отображать страницы из справа налево, учитывая, что я новичок в этой области?
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using AfterFix.Pages.Items;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace AfterFix.Pages.Sales
{
public class NewSalesModel : PageModel
{
private readonly string _connectionString = "Data Source=DESKTOP-9CABSPL\\SQLEXPRESS;Initial Catalog=mystore;Integrated Security=True;MultipleActiveResultSets=true";
public SalesInfo salesInfo = new SalesInfo();
public ItemsInfo itemsInfo = new ItemsInfo();
public string errorMessage = "";
public string SuccessMessage = "";
// Fetch customers
public List CustomerList { get; set; } = new List();
public List Items { get; set; } = new List();
public void OnGet()
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
var query = "SELECT Id, Name FROM customers";
using (var command = new SqlCommand(query, connection))
{
var reader = command.ExecuteReader();
while (reader.Read())
{
var customerId = reader["Id"].ToString();
var customerName = reader["Name"].ToString();
CustomerList.Add(new SelectListItem
{
Value = customerId,
Text = customerName
});
}
}
// Fetch items
var itemQuery = "SELECT Id, ItemName FROM items"; // Adjust the query according to your database schema
using (var itemCommand = new SqlCommand(itemQuery, connection))
{
var itemReader = itemCommand.ExecuteReader();
while (itemReader.Read())
{
var itemId = itemReader["Id"].ToString();
var itemName = itemReader["ItemName"].ToString();
Items.Add(new SelectListItem
{
Value = itemId,
Text = itemName
});
}
}
}
}
public IActionResult OnPostGeneratePDF()
{
// Get invoice information from form
string invoiceNumber = Request.Form["InvNo"];
string invoiceDate = Request.Form["InvDate"];
// Create PDF document
using (MemoryStream memoryStream = new MemoryStream())
{
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
// Font settings for Arabic text
BaseFont baseFont = BaseFont.CreateFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font arabicFont = new Font(baseFont, 12, Font.NORMAL);
// Add Arabic text to PDF
Paragraph paragraph = new Paragraph("رقم الفاتورة: " + invoiceNumber, arabicFont);
document.Add(paragraph);
paragraph = new Paragraph("تاريخ الفاتورة: " + invoiceDate, arabicFont);
document.Add(paragraph);
// Add company name, item names, item prices, total price, etc. as needed
document.Close();
// Export PDF
return File(memoryStream.ToArray(), "application/pdf", "invoice.pdf");
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... age-to-pdf
Невозможно отобразить арабское слово при экспорте страницы бритвы в PDF ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как перенести слово на предыдущее слово, если не подходит только последнее слово
Anonymous » » в форуме Android - 0 Ответы
- 133 Просмотры
-
Последнее сообщение Anonymous
-