Tuesday, July 4, 2023

How to download pdf in node.js

To export or download a PDF file in Node.js, you can make use of various libraries available. One popular library for generating PDF files is "pdfkit." Here's an example of how you can use it to export a PDF file in Node.js:
1. Install the "pdfkit" library by running the following command in your Node.js project directory:
```shell
npm install pdfkit
```
2. Create a new JavaScript file, for example, "pdfExport.js," and require the necessary modules:
```javascript
const PDFDocument = require('pdfkit');
const fs = require('fs');
```
3. Write the code to generate the PDF and save it to a file:
```javascript
// Create a new PDF document
const doc = new PDFDocument();
// Add content to the PDF
doc.fontSize(16).text('Hello, World!');
// Save the PDF to a file
doc.pipe(fs.createWriteStream('output.pdf'));
doc.end();
```
4. Run the script by executing the following command in your terminal:
```shell
node pdfExport.js
```
After running the script, a new file named "output.pdf" will be generated in the same directory, containing the PDF document with the specified content.
You can customize the PDF's content by using the various methods provided by the "pdfkit" library, such as adding text, images, tables, and more. Refer to the library's documentation for more details on its capabilities and options.

Labels:

Monday, July 3, 2023

How to Debug node.js application in VScode?

To debug a Node.js application using Visual Studio Code, follow these steps: 

 1. Install the Visual Studio Code editor from the official website: https://code.visualstudio.com/ 

 2. Open your Node.js project in Visual Studio Code.

 3. Make sure you have a `launch.json` configuration file in your project. If you don't have one, you can create it by clicking on the "Run and Debug" icon in the sidebar and selecting the "Add Configuration" button. Choose the "Node.js" environment. 4. In the `launch.json` file, you'll see a default configuration for debugging Node.js. By default, it launches the currently open JavaScript file. You can customize this configuration as needed, such as specifying the entry point file or adding environment variables. 

 5. Place breakpoints in your code by clicking in the left margin of the editor or using the shortcut `F9`. Breakpoints are markers that pause the execution of your code at specific lines, allowing you to inspect variables and step through the code. 

 6. Start the debugging session by selecting the debug configuration you want to use from the drop-down menu in the top toolbar. It should be the name you provided in the `launch.json` file. Alternatively, you can press `F5` to start debugging. 

 7. Once the debugging session starts, your Node.js application will run, and it will stop at the breakpoints you set. You can use the debug toolbar at the top to control the execution flow, step through the code, examine variables, and view call stacks. 

 8. While debugging, you can use the various debug-related buttons in the toolbar, such as stepping in (`F11`), stepping over (`F10`), stepping out (`Shift + F11`), and stopping the debugging session (`Shift + F5`). 

 9. You can also open the Debug Console in Visual Studio Code by selecting the "Debug Console" tab in the bottom panel. It allows you to execute JavaScript code and view console output during debugging.

 10. Finally, once you have finished debugging, you can stop the debugging session by clicking on the red "Stop" button in the debug toolbar or by pressing `Shift + F5`. By following these steps, you can effectively debug your Node.js application using Visual Studio Code.

Labels:

Wednesday, November 16, 2011

How to know the current postback is a full postback or partial postback in Asp.net

Here is the code used to differentiate between partial or full post back in Asp.net.
if (Page.IsPostBack)
{

if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)

{
//Partial post back

}

else

{

//full post back
}

}

Sunday, October 9, 2011

Silverlight vs Adobe Flash

Several other technologies use a plug-in like Java, ActiveX,Shockwave, Adobe Flash, But Adobe flash is most popular among them.Still Adobe Flash has an advantages over silverlight


Features
Silverlight
Animation
Better Than Flash
File size
Not better  than flash
Scripting
Better Than Flash
Video/Audio
Better Than Flash
Sound processing
Not better  than flash
Accessibility
Not better  than flash
Platform compatibility
Not better  than flash
Text representation/SEO
Better Than Flash
Supported image formats
Not better  than flash
Socket programming
Not better  than flash
Webcam support
Not better  than flash
Deployment
Not better  than flash
Windows application
Not better  than flash
Media streaming
Better Than Flash

Labels:

How to check silverlight plug in installed

If silverlight plug –in is not download on your machine then it shows you to download it on the silverlight content and after clicking it it will start downloading and if you click the run then it start running.




Labels:

Advantage and Disadvantage of silverlight plug in

Advantage:

The advantage of plug-in is that user needs to install it one time.It’a time taking process but still has a great advantage and browser can the browser can process any content that uses the plug-in seamlessly, with no further prompting.Silverlight allows you to develop more graphical and interactive applications.

Disadvantage;

It's a time taking process for the first time and No user want to wait for some time to see the content after downloading the plug in.




Labels:

What is silverlight runtime?

It's Plug-in for browser to display the silverlight content.


Labels:

Introduction to Silverlight


What is silverlight?
Silverlight is  a cross-platform and cross-browser plug-in that exposes a programming framework and features that are a subset of the .NET Framework and Windows Presentation Foundation (WPF).

Silverlight is a web browser plug-in which is small in size and can be installed on demand  and runs in all popular browsers, including Microsoft Internet Explorer, Mozilla Firefox, Apple Safari, Opera.It is similar to flash .It runs cross-browser , cross-platform that exposes a programming framework and features that are a subset of the .NET Framework and Windows Presentation Foundation (WPF) .You can develop business applications for the Web, desktop, and mobile devices .



Labels:

Tuesday, September 20, 2011

How to manually configure webserver for asp.net 4.0

Use below command in VS command prompt

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i

Thursday, August 25, 2011

How to spilt data in sql server while using "IN" operator

Sometime you send multiple comma separated values as parameter to a stored procedure.
Suppose you are set the parameter value as below
param[0].value = "3,4,5,6"; 
The above set value doesn't work in stored procedure.

But as the column type is int then it query condition should be like column name in (3,4,5) and if you send the parameter as

It doesn't work in stored procedure, So i have used a function to split it and to use it.
USE [Database name]
GO
/****** Object:  UserDefinedFunction [dbo].[Split_String]    Script Date: 08/26/2011 11:12:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER FUNCTION [dbo].[Split_String](@Param_String varchar(2000),@Delmeter varchar(5))  
RETURNS @RtnValue table 
(
	Id int identity(1,1),
	Data nvarchar(100)
) 
AS  
BEGIN 
	Declare @Cnt int
	Set @Cnt = 1

	While (Charindex(@Delmeter,@Param_String)>0)
	Begin
		Insert Into @RtnValue (data)
		Select 
			Data = ltrim(rtrim(Substring(@Param_String,1,Charindex(@Delmeter,@Param_String)-1)))

		Set @Param_String = Substring(@Param_String,Charindex(@Delmeter,@Param_String)+1,len(@Param_String))
		Set @Cnt = @Cnt + 1
	End
	
	Insert Into @RtnValue (data)
	Select Data = ltrim(rtrim(@Param_String))

	Return
END
Example:

SELECT NAME FROM TABLENAME  WHERE FK_DEFAULT_ID    
IN (select data from [dbo].[Split_String] (@DEFAULTIDS,',') ) 
Note : @DEFAULTIDS is the parameter in stored procedure which contains value like "3,4,5,6" and type id varchar.






Labels:

Wednesday, August 17, 2011

How to spilt string with string as a separator using c#

It's easy to split a string using character but sometimes the separator may present in the string with not as separator then at that time result comes as wrong.To avoid this kind of error use string with unique combination like "$#%$" or "$%%^^" .There may a less possibility of presence of this kind of string inside your string,But if you can't separate it with the way you separate using char as separator.

Here is the sample :
string[] arrStr = typeOfrecord.Split(new string[] {"#$%^"}, StringSplitOptions.None);

Note: typeOfrecord is the string containing the separator as "#$%^".

Labels: , ,