How to create PDF in Unity platform using C# in WinForms PDF?
Our WinForms PDF feature tour page Unity is a cross-platform game engine that was initially released by Unity Technologies in 2005. The focus of Unity lies in the development of both 2D and 3D games as well as interactive content. Unity now supports over 20 different target platforms for deploying, while its most popular platforms are the PC, Android and iOS systems.
Unity has a complete toolkit for designing and building games, including interfaces for graphics, audio, and level-building tools, requiring minimal use of external programs to work on projects.
The Syncfusion Essential® PDF is a feature-rich and high-performance .NET Core PDF library that is used to create, read, and edit the PDF documents programmatically without Adobe dependencies. Using this library, you can create pdf in the Unity platform using C# and VB.NET
Steps to create a Pdf document in the Unity Platform using C# programmatically:
- Create a new Unity project.
- Add the Button to the UI as follows:
- Add the C# script to the unity project and assign the event handler for the Button in the UI as follows:
- Add the required assemblies to the assets folder in the package directory:
- Add the following code snippet to the attached c# script file:
public void TestButton() { //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. PdfPage page = document.Pages.Add(); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; //Set the standard font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); //Create the stream object. MemoryStream stream = new MemoryStream(); //Save the document into memory stream. document.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. File.WriteAllBytes("Sample.pdf", stream.ToArray()); System.Diagnostics.Process.Start("Sample.pdf", @"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\AcroRd32.exe"); }
A complete working sample can be downloaded from UnityProjectsample.zip
By executing the project, you will get the PDF document as follows.
Refer to this link to explore a rich set of Syncfusion Essential® PDF
features.
Note:
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or NuGet feed, include a license key in your projects. Refer to this link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trail message.
Also see:
https://www.syncfusion.com/blogs/post/create-validate-pdf-digital-signatures-csharp.aspx
Conclusion
I hope you enjoyed learning about how to create PDF in Unity platform using C# in WinForms PDF.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!