ItextSharp 在 PC 构建中生成 0 字节的 pdf 文件。在编辑器中工作

ItextSharp generates pdf file of 0 bytes in PC build. Works in editor

我正在使用 iTextSharp.dll 在 PC 版本中生成 pdf。版本:2018.4.9f - OS 10 - Build:PC - C# - Visual Studio 2017 community

pdf 正在编辑器中生成,它应该与我在脚本中输入的文本一起生成,但在为 PC 构建之后,它生成了一个 0 字节的 pdf。打开它时会弹出一个对话框,提示无法识别文件类型或损坏的 pdf。它如何在 PC 构建中实现相同的结果?我错过了什么?

在我的场景中,我有一个带有 c# 脚本的相机。脚本有一个方法,当按下 UI 按钮时调用该方法。这是代码:

using UnityEngine;
using UnityEngine.UI;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System;

public class Panel : MonoBehaviour
{
     WaitForEndOfFrame frameEnd = new WaitForEndOfFrame();

     public void EnglishPdf()
     {
         FileStream fs = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)+ "\Test.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
         Document doc = new Document(PageSize.A4);
         PdfWriter writer = PdfWriter.GetInstance(doc, fs);
         doc.Open();

         //Page0
         doc.NewPage();
         // PdfPTable page0 = new PdfPTable(2);
         Paragraph title = new Paragraph("Test PDF");
         title.Alignment = Element.ALIGN_CENTER;

         Chunk nameChunk = new Chunk("Name: "  + "\r\n");
         Chunk bday = new Chunk("Date of Birth: "  );
         doc.Add(title);
         // doc.Add(page0);
         doc.Add(nameChunk);
         doc.Add(bday);

         doc.Close();
     }
}

谢谢,是版本问题。我通过升级到 itext7

来修复它