System.DllNotFoundException:'gdi32.dll程序集:<未知程序集>类型:<未知类型>成员:(null)'

时间:2020-09-08 13:36:46

标签: c# pdf xamarin.android gdi itext7

我必须在itext7 pdf文件中写一个表。该表必须包含阿拉伯语单词。我已经尝试解决这个问题几个小时了。我找到了此代码,所以我尝试了它:

string[] sources = new string[] { "english.xml", "arabic.xml", "hindi.xml", "tamil.xml" };
            PdfWriter writer = new PdfWriter(DEST);
            PdfDocument pdfDocument = new PdfDocument(writer);
            Document document = new Document(pdfDocument);
            FontSet set = new FontSet();
            set.AddFont("NotoNaskhArabic-Regular.ttf");
            set.AddFont("NotoSansTamil-Regular.ttf");
            set.AddFont("FreeSans.ttf");
            document.SetFontProvider(new FontProvider(set));
            document.SetProperty(Property.FONT, new String[] { "MyFontFamilyName" });
            foreach (string source in sources)
            {
                XmlDocument doc = new XmlDocument();
                var stream = new FileStream(source, FileMode.Open);
                doc.Load(stream);
                XmlNode element = doc.GetElementsByTagName("text").Item(0);
                Paragraph paragraph = new Paragraph();
                XmlNode textDirectionElement = element.Attributes.GetNamedItem("direction");
                Boolean rtl = textDirectionElement != null && textDirectionElement.InnerText.Equals("rtl");
                if (rtl)
                {
                    paragraph.SetTextAlignment(TextAlignment.RIGHT);
                }
                paragraph.Add(element.InnerText);
                document.Add(paragraph);
            }
            document.Close();

我是从https://itextpdf.com/en/blog/technical-notes/displaying-text-different-languages-single-pdf-document获得的。我开始收到我的FontSet和FontSet提供程序为空的异常,因此我猜想我没有代码中提到的字体。我开始寻找一种安装方式,并且找到了答案Installing and using a specific font in a winform,因此添加了以下代码:

public class user
    {
       
        [DllImport("gdi32.dll", EntryPoint = "AddFontResourceW", SetLastError = true)]
        public static extern int AddFontResource([In][MarshalAs(UnmanagedType.LPWStr)]
                                     string lpFileName);
         
    }

这是我的主要建议:

var result = user.AddFontResource(@"C:\MY_FONT_LOCATION\NotoNaskhArabic-Regular.ttf");

但是它不起作用,我得到了例外:System.DllNotFoundException:'gdi32.dll程序集:类型:member:(null)'。我该怎么办?我在正确的道路上吗? 预先感谢

0 个答案:

没有答案