Hello !
I am looking to create a pdf file, with data from my Unity application. Sorry for the explanations, a bit long, but I try to give as much detail as possible to “make it easier” for you.
Before the explanations I give, I want to specify that any solution to generate a PDF with game values written in it, even completely different from what I am doing, is fine with me.
To begin with, I can already create a .csv file (Excel) with Unity, and C#'s System I/O.
However, I understood that to create a PDF file, we had to add a framework in our project.
The first framework that came up was: iText7.
So I added the plugin using the NuGet package manager.
I then saw that we had to add the .dll files, in our Unity project. I did that too.
But every time I add a dll file, Unity asks me for another one (see picture):
I have added the dll files as requested 5 times, but I have the impression that it never stops.
Finally, here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using iText.Layout;
using iText.Kernel.Geom;
using iText.Kernel.Pdf;
public class PDF_Generator : MonoBehaviour
{
string filename = "";
[System.Serializable]
public class Player
{
public string name;
public int health;
public int damage;
public int defence;
}
[System.Serializable]
public class PlayerList
{
public Player[] player;
}
public PlayerList myPlayerList = new PlayerList();
// Start is called before the first frame update
void Start()
{
filename = Application.dataPath + "/test.pdf";
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
EnglishPDF();
}
}
public void EnglishPDF()
{
string dest = Application.dataPath + "/test.pdf";
PdfWriter writer = new PdfWriter(dest);
// Creating a PdfDocument
PdfDocument pdfDoc = new PdfDocument(writer);
// Adding an empty page
pdfDoc.AddNewPage();
// Creating a Document
Document document = new Document(pdfDoc);
// Closing the document
document.Close();
}
}
As you can see on this picture, there is only the Close() function that does not work.
The error message is the following:
<The type “AbstractIdentifiableElement” is defined in an assemby that is not referenced. You need to add a reference to the assembly ‘itext.commons’, Version 7.2.2.0, Culture = neutral, PublicKeyToken = (a long number)>
I work with Unity 2019.4.36f1, and Visual Studio 2019. I thank you in advance for your answers.
Thank you in advance for your answers. Sincerely.
