Cross-platform development using Apitron PDF Kit

From
Jump to: navigation, search

Windows

If you develop for Windows or other platforms and the OS you're using is Windows also, then to create an app utilizing the Apitron PDF Kit you need the following:

  • An IDE supporting .NET development[1]: Visual Studio or Visual Studio with Xamarin support, Visual Studio Code, MonoDevelop, or any other
  • Install .NET SDK or .NET framework package, usually gets installed with the IDE or install Mono package if you plan to test your builds using the Mono runtime
  • Open any of the available sample projects or create a new one by your choice
  • Add reference to the standard build of the library via the Nuget package manager or directly from the file system if needed
  • You're done

There're many sample projects available in our Apitron PDF Kit Samples repository and included into the component package available for download on our website which you can try out with this setup.

macOS

If you develop for macOS or other platforms and the OS you're using is macOS, then to create an app utilizing the Apitron PDF Kit you need the following:

  • An IDE supporting .NET development[1]: Visual Studio for Mac (successor to Xamarin Studio), Visual Studio Code, MonoDevelop or any other)
  • Install .NET SDK or .NET framework package, usually gets installed with the IDE or install Mono package if you plan to test your build using the Mono runtime
  • Open any of the available sample projects, create a new one by your choice, or check the tutorials below
  • Add reference to the platform-specific build of the library via the Nuget package manager or directly from the file system if needed
  • You're done

There're many sample projects available in our Apitron PDF Kit Samples repository and included into the component package available for download on our website which you can try out with this setup.

Below you can find a few tutorials showing how one could proceed with the development for/on macOS.

Visual Studio Code

  • Step 2: Download and install Visual Studio Code for Mac
  • Step 3: Open Visual Studio Code for Mac and install the C# development extension
Installing C# extension to Visual Studio Code
  • Step 4: Select file explorer tab and click the Add Folder button, select desired folder in the newly opened folder selection dialog
Selecting project folder
  • Step 5: Select the newly added folder as current folder and navigate to View -> Integrated Terminal, after that type the command "dotnet new console", and confirm the addition of all necessary build dependencies offered by the app
  • Step 6: Staying in the same terminal execute the following command: "dotnet add package Apitron.PDF.Kit" and wait until the package is added
  • Step 7: Select the Program.cs in the project tree and add the code shown below
using System;
using System.IO;
using Apitron.PDF.Kit;
using Apitron.PDF.Kit.FixedLayout;
using Apitron.PDF.Kit.FixedLayout.Content;
using Apitron.PDF.Kit.FixedLayout.Resources.Fonts;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            // create output PDF file stream
            using (FileStream outputStream = new FileStream("outfile.pdf", FileMode.Create, FileAccess.Write))
            {
                // create new document
                using(FixedDocument document = new FixedDocument())
                {
                    // add blank first page
                    document.Pages.Add(new Page(Boundaries.A4));

                    // create text object and append text to it
                    TextObject textObject = new TextObject(StandardFonts.Helvetica,16);                

                    // apply identity matrix, that doesn't change default appearance
                    textObject.SetTextMatrix(1,0,0,1,0,0);
                    textObject.AppendText("Hello world using Apitron PDF Kit and Visual Studio Code on Mac!");

                    // set current transformation matrix so text will be added to the top of the page,
                    // PDF coordinate system has Y-axis directed from bottom to top.
                    document.Pages[0].Content.SetTranslate(10, 820);

                    // add text object to page content, it will automatically create text showing operators                                
                    document.Pages[0].Content.AppendText(textObject);

                    // save to output stream
                    document.Save(outputStream);
                }
            }
        }
    }
}
 

So that your workspace would look as follows:

Project workspace view
  • Step 8: type "dotnet run" command in the intergrated terminal to build and run the app, resulting PDF document generated by the app is shown below
Generated PDF document


Linux

Visual Studio Code

Please follow the steps described for macOS


[1] Actually it's possible to use only command-line tools coming with the .NET SDK or Mono package, and avoid using the IDE if one can develop using custom code editors, or Notepad or VIM for example.