Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PDFSharp AcroForms Textfields“;“未找到文件”;窗体似乎已加载时出现异常_C#_.net_Pdfsharp_Acrofields - Fatal编程技术网

C# PDFSharp AcroForms Textfields“;“未找到文件”;窗体似乎已加载时出现异常

C# PDFSharp AcroForms Textfields“;“未找到文件”;窗体似乎已加载时出现异常,c#,.net,pdfsharp,acrofields,C#,.net,Pdfsharp,Acrofields,我正在尝试使用PDFSharp(下面的代码)在AcroForm中更改PdfTextField的文本。当我迭代form.Fields.Count时,它进入循环,调试器向我显示form.Fields.Count等于1,据我所知,这意味着表单加载成功,文本字段的数量正确。 但是,当我尝试通过索引或名称访问form.Fields时,我会出现以下错误: System.IO.FileNotFoundException:“无法加载文件或程序集'System.Drawing.Common,版本=4.0.2.1,

我正在尝试使用PDFSharp(下面的代码)在AcroForm中更改PdfTextField的文本。当我迭代form.Fields.Count时,它进入循环,调试器向我显示form.Fields.Count等于1,据我所知,这意味着表单加载成功,文本字段的数量正确。 但是,当我尝试通过索引或名称访问form.Fields时,我会出现以下错误:

System.IO.FileNotFoundException:“无法加载文件或程序集'System.Drawing.Common,版本=4.0.2.1,区域性=neutral,PublicKeyToken=CC7B13FFCD2DD51'。系统找不到指定的文件

这很奇怪,因为它不像此线程中的空引用: 但有些不同。我仍然认为它与链接线程中的问题有关,但我尝试了解决方案,但仍然遇到了相同的问题

这是我的密码:

static void createPDFfromTemplate() {

            string templateDocPath = ("Res/MyTemplate.pdf");
            PdfSharp.Pdf.PdfDocument myTemplate = PdfSharp.Pdf.IO.PdfReader.Open(templateDocPath, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
            PdfSharp.Pdf.AcroForms.PdfAcroForm form = myTemplate.AcroForm;

            if (form.Elements.ContainsKey("/NeedAppearances"))
            {
                form.Elements["/NeedAppearances"] = new PdfSharp.Pdf.PdfBoolean(true);
            }
            else
            {
                form.Elements.Add("/NeedAppearances", new PdfSharp.Pdf.PdfBoolean(true));
            }



            for (int i = 0; i < form.Fields.Count; i++)
            {
                Console.WriteLine(form.Fields.Count);
                Console.WriteLine(form.Fields[i].ToString()); //ERROR APPEARS HERE

            }




            PdfSharp.Pdf.AcroForms.PdfTextField testField = (PdfSharp.Pdf.AcroForms.PdfTextField)form.Fields["Name"];

            testField.Text = "dog";


            myTemplate.Save("Output/Zertifikat.pdf");  // Save to new file.


        }
static void createPdfromTemplate(){
字符串templateDocPath=(“Res/MyTemplate.pdf”);
PdfSharp.Pdf.PdfDocument myTemplate=PdfSharp.Pdf.IO.PdfReader.Open(templateDocPath,PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
PdfSharp.Pdf.AcroForms.PdfAcroForm form=myTemplate.AcroForm;
if(form.Elements.ContainsKey(“/needAppearanses”))
{
form.Elements[“/needAppearancess”]=new PdfSharp.Pdf.PdfBoolean(true);
}
其他的
{
添加(“/needAppearancess”,new PdfSharp.Pdf.PdfBoolean(true));
}
for(int i=0;i
您使用的是“官方”PDFsharp版本还是某些移植版本?哪个?哪个框架?哪个版本?