Unity中使用iText7

预备知识

在 Unity 中使用 .NET 4.x

导入iText

  1. 在Unity项目中打开VS
  2. 使用NuGet 获取iText包
  3. 下载完毕 在Unity项目的Packages文件夹中可找到
  4. 提取每个文件夹中 net4 版本的dll文件
  5. 提取后可以删除 Packages 中导入的包
  6. 在Unity中新建 Plugins 文件夹 dll 放入其中
  7. 注意:不需要提取System.ValueTuple.4.5.0文件的dll
  8. Project Settings_>Player->Api Compatilibity level 设置为 .Net 4.x

测试

测试成功:我的文档 ——>ExamPaperScore 有Hello.pdf 文件

using iText.IO.Font;
using iText.Kernel.Colors;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using System;
using System.IO;
using UnityEngine;

public class Test : MonoBehaviour
{
    
    
    void Start(){
    
    
        PDFCreate.CreatePDF();
    }
}
public class PDFCreate
{
    
    
    public static string pdfPath= Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        +@"\ExamPaperScore\Hello.pdf";
    public static void CreatePDF()
    {
    
    
        FileInfo file = new FileInfo(pdfPath);
        file.Directory.Create();

        PdfWriter writer = new PdfWriter(pdfPath);
        PdfDocument pdf = new PdfDocument(writer);
        Document document = new Document(pdf);
      
        Paragraph p = new Paragraph("Hello World!");
        document.Add(p);
        document.Close();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43796392/article/details/121057331#comments_22647450