无法使用 PdfSharpCore 从我的 dotnet core 6 中的数据库中获取乌尔都语数据

Unable to get Urdu data from database in my dotnet core 6 using PdfSharpCore

提问人:Ahmed Hassan 提问时间:11/15/2023 最后编辑:CharliefaceAhmed Hassan 更新时间:11/15/2023 访问量:22

问:

我正在尝试获取包含特定用户数据的 Pdf 表单,例如姓名、年龄、出生日期、注册号等,以英语或日期存储的数据很好,就像乌尔都语中显示为矩形框的名称和地址一样

我的后端代码:

using PdfSharpCore;
using PdfSharpCore.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
using PdfSharpCore.Fonts;
using PdfSharpCore.Utils;
using PdfSharpCore.Drawing;

    [HttpGet("{serialNo}")]
    public async Task<IActionResult> GenerateNotificationsPdfForm(string serialNo)
    {
        Notifications notification = await repository.GetNotificationReport(serialNo); 
        JsonElement json = notification.Params.RootElement;
        Member member = await memberRepository.Get(json.GetProperty("MemberId").GetInt32());

        NotificationPdfModel data = new()
        {
            FullName = member.FullName,
            RegistranNumber = member.RegistrationNumbers.Where(r => r.Current).Select(s => s.Code).FirstOrDefault(),
            FatherName = member.FatherName,
            Dob = member.DateOfBirth,
            Education = member.MemberEducations.Select(s => s.SetupEducations.Degree).FirstOrDefault(),
            Occupation = member.MemberOccupations.Select(s => s.SetupOccupations.Name).FirstOrDefault(),
            MaritalStatus = member.MemberMaritalStatuses.Select(s => s.SetupMaritalStatus.Name).FirstOrDefault(),
            ContactNo = string.Join(",", memberRepository.GetMemberMobileNumbers(member)),
            PreviousAddress = memberRepository.GetMemberCurrentAddress(member),
            ResponsibilityName = member.MemberResponsibilities.Where(mr => mr.Current).Select(s => s.DisplayName).FirstOrDefault(),
            MubtadiCourse = member.CourseParticipants.Where(cp => cp.Course.Published && cp.Course.CourseType.StaticType == CourseType.StaticCourseTypes.MubtadiTarbiyatiCourse).Select(cp => new MemberCourseModel(){
                StartDate = cp.Course.StartDate,
                Location = cp.Course?.Address ?? cp.Course?.CourseLocation?.Address,
            }).FirstOrDefault(),
            MultazimCourse = member.CourseParticipants.Where(cp => cp.Course.Published && cp.Course.CourseType.StaticType == CourseType.StaticCourseTypes.MultazimTarbiyatiCourse).Select(cp => new MemberCourseModel(){
                StartDate = cp.Course.StartDate,
                Location = cp.Course?.Address ?? cp.Course?.CourseLocation?.Address,
            }).FirstOrDefault(),
            NisabBaraEMutaliya = json.GetProperty("NisabBaraEMutaliya").GetString(),
            TaluqMaAllah = json.GetProperty("TaluqMaAllah").GetString(),
            SamaOTaat = json.GetProperty("SamaOTaat").GetString(),
            SamaOBasar = json.GetProperty("SamaOBasar").GetString(),
            InfradiDawat = json.GetProperty("InfradiDawat").GetString(),
            JihadBilMaal = json.GetProperty("JihadBilMaal").GetString(),
        };

        var document = new PdfDocument();
        string HtmlContent = "<h1>"+data.Dob.Value.ToString("dd-MM-yyyy")+"</h1>";
        HtmlContent += "<h1 style='font-family: Alvi Nastaleeq;'>"+data.FullName+"</h1>";
        PdfGenerator.AddPdfPages(document, HtmlContent, PageSize.A4);

        byte[] response = null;
        
        using (MemoryStream ms = new MemoryStream())
        {
            document.Save(ms);
            response = ms.ToArray();
        }

        string FileName = "Test.pdf";

        return File(response, "application/pdf", FileName);
    }
C# ASP.NET-Core .NET-Core 字体 PDFSHARPCORE

评论

0赞 ChrisBD 11/15/2023
您是否安装了正确的语言字符集?
0赞 Charlieface 11/15/2023
您确定数据正确存储在数据库中吗?
0赞 Ahmed Hassan 11/15/2023
数据来自数据库,我可以在控制台中看到它,当我生成带有日期和英文数据的表单时,它会在 A4 大小的页面上以 pdf 格式打印出来,但是当我使用可以在控制台(前端)中看到的乌尔都语数据时,它显示为框,就像我们在计算机中看到的那样,当它显示未知语言时@Charlieface
0赞 Ahmed Hassan 11/15/2023
在控制台中,它显示所有数据(乌尔都语和英语),但它以 pdf 格式显示英语数据,但乌尔都语数据显示不然@ChrisBD
0赞 Charlieface 11/15/2023
也许您需要更改字体?

答: 暂无答案