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

问题描述 投票:-1回答:1

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

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();
     }
}
c# unity3d itext pc
1个回答
0
投票

谢谢,这是版本问题。我通过升级到itext7来修复它

© www.soinside.com 2019 - 2024. All rights reserved.