Articles in this section
Category / Section

How to use PDF control in NodeJS environment

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

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

 

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