ITextSharp在unity编辑器中完美运行,但是当应用程序独立构建到Windows时,会生成损坏的0字节文件



下面的代码应该生成一个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 + "rn");
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 Effectsrnrn");
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: rnrn");
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 Numbersrnrn");
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("Planesrn");
Paragraph ArrowStrength = new Paragraph("Arrows of Strengthrn");
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("rnrnFour Short Arrowsrn");
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("rnrnArrows of Weaknessrn");
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 Daysrnrn");
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 Colorsrnrn");
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 Professionsrnrn");
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 Colorsrnrn");
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 Professionsrnrn");
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();
}

我关注了一些与此类似的其他主题,但其中大多数都缺少文档。最后的 Close((,这在我的代码中并非如此。我从一开始就拥有它。我该如何解决这个问题?

该构建也成功构建,没有任何错误,一切运行良好。我猜代码中缺少一些东西。任何帮助都会有所帮助。

升级到 Itext7 将被修复。谢谢

相关内容

最新更新