Articles in this section
Category / Section

How to create PDF in Unity platform using C# in WinForms PDF?

5 mins read

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:

  1. Create a new Unity project.

create unity project

  1. Add the Button to the UI as follows:

create button in UI screenshot

  1. Add the C# script to the unity project and assign the event handler for the Button in the UI as follows:

add files to the asset folder

 

  1. Add the required assemblies to the assets folder in the package directory:

asset folder overview

 

  1. 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.

output pdf screenshot


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://help.syncfusion.com/file-formats/pdf/working-with-digitalsignature#deferred-signing-in-pdf-document

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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied