Articles in this section
Category / Section

How to use PDF control in NodeJS environment?

4 mins read

Using PDF control in NodeJS environment

PDF control can be used in NodeJS environment by using EdgeJS. Please follow the steps below to achieve this.

1)Create a new folder(CSharpToNodeJS).

2)Open command prompt and install EdgeJS using npm.

npm install edge

 

3)Create a new CS file as like below

Source.cs
 
using System.Threading.Tasks;
using System.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
 
namespace Source
{
    public class Startup
    {
        public async Task<object> Invoke(object outputPath)
        {
            //Create new PDF document
            PdfDocument doc = new PdfDocument();
            //Add new page to the PDF document
            PdfPage page = doc.Pages.Add();
            //Draw a string to the page
            page.Graphics.DrawString("Hello World from .Net",
                new PdfStandardFont(PdfFontFamily.TimesRoman, 10),
                PdfBrushes.Black,
                new PointF(100, 100));
            //Save and close the document
            doc.Save(outputPath as string);
            doc.Close(true);
            return "PDF generated successfully..!";
        }
    }
}

 

4)Create new JS file as like below.

Sample.js
 
var edge = require('edge');
 
var CreatePDF = edge.func('Source.dll');
 
CreatePDF("Output.pdf", function (error, result) {
    if (error) throw error;
    console.log(result);
});

 

5)Place the below required assemblies in the project folder(CSharpToNodeJS)

  1. Syncfusion.Compression.Base.dll
  2. Syncfusion.Pdf.Base.dll

        Copy the required assemblies

6)Open the command prompt and build the cs file with the necessary reference by using the below command.

"C:\Windows\Microsoft.NET\Framework\vx.x.xx\csc.exe" /r:Syncfusion.Compression.Base.dll,Syncfusion.Pdf.Base.dll,System.Drawing.dll /target:library /debug Source.cs

 

7)Once the command succeed Source.dll will be generated as like below. generated source.dll

8)Run the below code in command prompt to run the C# code with NodeJS.

node Sample.js

        Get the output PDF document

Please find the attached sample for reference.

https://www.syncfusion.com/downloads/support/directtrac/general/ze/CSharpToNodeJS-735846718

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion:

I hope you enjoyed learning about how to use PDF control in NodeJS environment.

 

You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples 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 explore 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 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
Please  to leave a comment
Access denied
Access denied