Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.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# ITextSharp在unity editor中运行良好,但在将应用程序构建到windows单机版时会生成损坏的0字节文件_C#_Unity3d_Itext_Pdf Generation - Fatal编程技术网

C# ITextSharp在unity editor中运行良好,但在将应用程序构建到windows单机版时会生成损坏的0字节文件

C# ITextSharp在unity editor中运行良好,但在将应用程序构建到windows单机版时会生成损坏的0字节文件,c#,unity3d,itext,pdf-generation,C#,Unity3d,Itext,Pdf Generation,下面的代码应该生成一个pdf,并将其保存在桌面上,其中包含unity编辑器中正常运行的内容,但最终的windows构建未能做到这一点。它生成了pdf并保存在桌面上,但pdf已损坏,显示0字节大小。我找不到错误,以下是代码: public void EnglishPdf() { FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\\Loshu-Num

下面的代码应该生成一个pdf,并将其保存在桌面上,其中包含unity编辑器中正常运行的内容,但最终的windows构建未能做到这一点。它生成了pdf并保存在桌面上,但pdf已损坏,显示0字节大小。我找不到错误,以下是代码:

 public void EnglishPdf()
{

    FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\\Loshu-Numerology.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
    Document doc = new Document(PageSize.A4);

    PdfWriter writer = PdfWriter.GetInstance(doc, fs);
    doc.Open();

    //Page0
    doc.NewPage();

    Paragraph title = new Paragraph("Loshu Grid Numerology Report");
    title.Alignment = Element.ALIGN_CENTER;

    Chunk nameChunk = new Chunk("Name: " + Gridvalues.instance.name_string + "\r\n");
    Chunk bday = new Chunk("Date of Birth: " + Gridvalues.instance.Date.text+ "-"+ Gridvalues.instance.Month.text+"-"+Gridvalues.instance.Year.text);
   /* iTextSharp.text.Image gridSample = iTextSharp.text.Image.GetInstance(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ScreenShot.png");
    gridSample.Alignment = Element.ALIGN_LEFT;*/
    doc.Add(title);

    doc.Add(nameChunk);
    doc.Add(bday);



    //Page-1
    doc.NewPage();
    Paragraph Title1 = new Paragraph("Missing Number Effects\r\n\r\n");
    Title1.Alignment = Element.ALIGN_CENTER;
    Paragraph Description1 = new Paragraph("The missing Number in the Grid signifies what lessons a person has to learn in this lifetime and through proper analysis, we can help them in understanding what is required to learn and provide remedies for the same so that they can improve the difficult situations of life.The Numbers missing in your Grid are: \r\n\r\n");
    Description1.Alignment = Element.ALIGN_LEFT;
    Paragraph content1 = new Paragraph(missingdetailsFull);
    content1.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title1);
    doc.Add(Description1);
    doc.Add(content1);


    //Page-2
    doc.NewPage();
    Paragraph Title2 = new Paragraph("Repeating Numbers\r\n\r\n");
    Title2.Alignment = Element.ALIGN_CENTER;
    Paragraph Content2 = new Paragraph(repetitionDetails);
    Content2.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title2);
    doc.Add(Content2);


    //Page-3
    doc.NewPage();
    Paragraph Title3 = new Paragraph("Planes\r\n");
    Paragraph ArrowStrength = new Paragraph("Arrows of Strength\r\n");
    Paragraph StrengthDetails = new Paragraph(strengthArrows);
    Title3.Alignment = Element.ALIGN_CENTER;
    ArrowStrength.Alignment = Element.ALIGN_CENTER;
    StrengthDetails.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title3);
    doc.Add(ArrowStrength);
    doc.Add(StrengthDetails);

    Paragraph shortarrows = new Paragraph("\r\n\r\nFour Short Arrows\r\n");
    Paragraph shortArrowDetails = new Paragraph(shortArrows); 
    shortarrows.Alignment = Element.ALIGN_CENTER;
    StrengthDetails.Alignment = Element.ALIGN_LEFT;
    doc.Add(shortarrows);
    doc.Add(shortArrowDetails);



    Paragraph weaknessarrow = new Paragraph("\r\n\r\nArrows of Weakness\r\n");
    Paragraph weakDetails = new Paragraph(weaknessArrows); 
    weaknessarrow.Alignment = Element.ALIGN_CENTER;
    weakDetails.Alignment = Element.ALIGN_LEFT;
    doc.Add(weaknessarrow);
    doc.Add(weakDetails);

    //Page4
    doc.NewPage();
    Paragraph title4 = new Paragraph("Lucky Colors, Professions & Days");
    title4.Alignment = Element.ALIGN_CENTER;
    Paragraph luckyd = new Paragraph("Lucky Days\r\n\r\n");
    luckyd.Alignment = Element.ALIGN_CENTER;
    Paragraph lucky_days = new Paragraph(luckydays);
    lucky_days.Alignment = Element.ALIGN_LEFT; 
    doc.Add(title4);
    doc.Add(luckyd);
    doc.Add(lucky_days);


    Paragraph luckyc = new Paragraph("Lucky Colors\r\n\r\n");
    luckyc.Alignment = Element.ALIGN_CENTER;
    Paragraph lucky_color = new Paragraph(colors);
    lucky_color.Alignment = Element.ALIGN_LEFT;
    doc.Add(luckyc);
    doc.Add(lucky_color);

    Paragraph lucky_P = new Paragraph("Lucky Professions\r\n\r\n");
    lucky_P.Alignment = Element.ALIGN_CENTER;
    Paragraph luckyprof = new Paragraph(luckyProfessions);
    luckyprof.Alignment = Element.ALIGN_LEFT;
    doc.Add(lucky_P);
    doc.Add(luckyprof);


    //Page5
    doc.NewPage();
    Paragraph Title5 = new Paragraph("Avoid Professions, Colors");
    Title5.Alignment = Element.ALIGN_CENTER;
    Paragraph avoidC = new Paragraph("Avoid Colors\r\n\r\n");
    avoidC.Alignment = Element.ALIGN_CENTER;
    Paragraph avoidCol = new Paragraph(avoidColors);
    avoidCol.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title5);
    doc.Add(avoidC);
    doc.Add(avoidCol);

    Paragraph avoidP = new Paragraph("Avoid Professions\r\n\r\n");
    avoidP.Alignment = Element.ALIGN_CENTER;
    Paragraph avoidProf = new Paragraph(avoidProfessions);
    avoidProf.Alignment = Element.ALIGN_LEFT;
    doc.Add(avoidP);
    doc.Add(avoidProf);



    //Page6
    doc.NewPage();
    Paragraph Title6 = new Paragraph("KUA Number");
    Title6.Alignment = Element.ALIGN_CENTER;
    Paragraph kuaN = new Paragraph("Your Kua Number is " + kua);
    kuaN.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title6);
    doc.Add(kuaN);


    //Page7
    doc.NewPage();
    Paragraph Title7 = new Paragraph("PM-PY-PD");
    Title7.Alignment = Element.ALIGN_CENTER;
    Paragraph PyearNumber = new Paragraph("Your Personal Year Number is "+ Py);
    PyearNumber.Alignment = Element.ALIGN_LEFT;
    Paragraph PmonthNumber = new Paragraph("Your Personal Month Number is "+ Pm);
    PmonthNumber.Alignment = Element.ALIGN_LEFT;
    Paragraph PdateNumber = new Paragraph("Your Personal Day Number is "+ Pd);
    PdateNumber.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title7);
    doc.Add(PyearNumber);
    doc.Add(PmonthNumber);
    doc.Add(PdateNumber);


    //Page8
    doc.NewPage();
    Paragraph Title8 = new Paragraph("Vedic Power Boosters");
    Title8.Alignment = Element.ALIGN_CENTER;
    Paragraph boosterDetails = new Paragraph(vedicBooster);
    boosterDetails.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title8);
    doc.Add(boosterDetails);


    //Page9
    doc.NewPage();
    Paragraph Title9 = new Paragraph("Punchlines");
    Title9.Alignment = Element.ALIGN_CENTER;
    Paragraph punchLine = new Paragraph(punchlines);
    punchLine.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title9);
    doc.Add(punchLine);



    //Page10
    doc.NewPage();
    Paragraph Title10 = new Paragraph("Driver Characterstics");
    Title10.Alignment = Element.ALIGN_CENTER;
    Paragraph driverChar = new Paragraph(characterstics);
    driverChar.Alignment = Element.ALIGN_LEFT;
    doc.Add(Title10);
    doc.Add(driverChar);

    doc.Close();

}
我遵循了一些与此类似的其他主题,但大多数主题最后都缺少doc.Close(),这在我的代码中不是这样的。我从一开始就有。我该如何解决这个问题


构建也成功构建,没有任何错误,并且一切运行正常。我猜代码中缺少了一些东西。任何帮助都会很有帮助。

升级到Itext7,它将被修复。谢谢

升级到Itext7,它将被修复。谢谢