sherazam
sherazam
Reputation Top 1%
sherazam azam
32 Snippets  (13rd place)
Published
1 Channel
Created
9 Channels
Following
8582 points  (12nd place)
Reputation
Top 5% Publisher
Junior Code Generator
Serious Code Generator
Senior Code Generator
Junior Publisher
Serious Publisher
Senior Publisher
Junior Topic Hub
Junior Trend Maker
Serious Trend Maker
Senior Trend Maker
Junior Popular Coder
Serious Popular Coder
Senior Popular Coder
Junior Autobiographer
Senior Autobiographer
Master Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by sherazam

public by sherazam  120625  0  5  0

How to Set Line Spacing of a Paragraph in an Excel Shape or Textbox inside .NET Apps

This technical tip shows how to Set Line Spacing of the Paragraph in a Shape or Textbox in .NET applications. You can set the line space of the paragraph, its space before and space after using the TextParagraph.LineSpace, TextParagraph.SpaceBefore and TextParagraph.SpaceAfter respectively. The following example shows how to Set Line Spacing of the
// Enter here the actual content of the snippet.            

//[C# Code]
 
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

// Create a workbook
Workbook wb = new Workbook();

// Access first worksheet
Worksheet ws = wb.Worksheets[0];

// Add text box inside the sheet
ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200);

// Access first shape which is a text box and set is text
Shape shape = ws.Shapes[0];
shape.Text = "Sign up for your free phone number.\nCall and text online for free.";

// Acccess the first paragraph
TextParagraph p = shape.TextBody.TextParagraphs[1];

// Set the line space
p.LineSpaceSizeType = LineSpaceSizeType.Points;
p.LineSpace = 20;

// Set the space after
p.SpaceAfterSizeType = LineSpaceSizeType.Points;
p.SpaceAfter = 10;

// Set the space before
p.SpaceBeforeSizeType = LineSpaceSizeType.Points;
p.SpaceBefore = 10;

// Save the workbook in xlsx format
wb.Save(dataDir + "output_out_.xlsx", SaveFormat.Xlsx); 

//[VB.NET Code]

' For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

' Create a workbook
Dim wb As New Workbook()

' Access first worksheet
Dim ws As Worksheet = wb.Worksheets(0)

' Add text box inside the sheet
ws.Shapes.AddTextBox(2, 0, 2, 0, 100, 200)

' Access first shape which is a text box and set is text
Dim shape As Shape = ws.Shapes(0)
shape.Text = "Sign up for your free phone number." & vbLf & "Call and text online for free."

' Acccess the first paragraph
Dim p As TextParagraph = shape.TextBody.TextParagraphs(1)

' Set the line space
p.LineSpaceSizeType = LineSpaceSizeType.Points
p.LineSpace = 20

' Set the space after
p.SpaceAfterSizeType = LineSpaceSizeType.Points
p.SpaceAfter = 10

' Set the space before
p.SpaceBeforeSizeType = LineSpaceSizeType.Points
p.SpaceBefore = 10

' Save the workbook in xlsx format
wb.Save(dataDir & Convert.ToString("output_out_.xlsx"), SaveFormat.Xlsx) 

;

public by sherazam  2138  0  5  0

How to Add Rectangle or Line Object to An Existing PDF File using .NET

This technical tip shows how .NET developers can add line object to an Existing PDF File inside their .NET applications. Aspose.Pdf for .NET supports the feature to add graph objects (for example graph, line, rectangle etc.) to PDF documents. You also get the leverage to add Line object where you can also specify the dash pattern, color and other f
// Enter here the actual content of the snippet.   
//The following code snippet shows how to add a Rectangle object that is filled with color.

//[C# Code]
 
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.Pages.Add();
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);             
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
// Create Rectangle instance
Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[]{100, 100, 200, 100});
// Specify fill color for Graph object
line.GraphInfo.DashArray = new int[] { 0, 1, 0 };
line.GraphInfo.DashPhase = 1;
// Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(line);
// Save PDF file
doc.Save("c:/pdftest/LineAdded.pdf");

//[VB.NET Code]
 
' Create Document instance
Dim doc As Document = New Document()
' Add page to pages collection of PDF file
Dim page As Page = doc.Pages.Add()
' Create Graph instance
Dim graph As Aspose.Pdf.Drawing.Graph = New Aspose.Pdf.Drawing.Graph(100, 400)
' Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph)
' Create Rectangle instance
Dim line As Aspose.Pdf.Drawing.Line = New Aspose.Pdf.Drawing.Line(New Single() {100, 100, 200, 100})
' Specify fill color for Graph object
line.GraphInfo.DashArray = New Integer() {0, 1, 0}
line.GraphInfo.DashPhase = 1
' Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(line)
' Save PDF file
doc.Save("c:/pdftest/LineAdded.pdf")

//DashLengthInBlack and DashLengthInWhite properties for Line object

//[C# Code]
 
 // instantiate Document instance
Document doc = new Document();
// add page to pages collection of Document object
Page page = doc.Pages.Add();
// create Drawing object with certain dimensions
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
// add drawing object to paragraphs collection of page instance
page.Paragraphs.Add(canvas);
// create Line object
Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[] { 100, 100, 200, 100 });
// set color for Line object
line.GraphInfo.Color = Aspose.Pdf.Color.Red;
// specify dash array for line object
line.GraphInfo.DashArray = new int[] { 0, 1, 0 };
// set the dash phase for Line instance
line.GraphInfo.DashPhase = 1;
// add line to shapes collection of drawing object
canvas.Shapes.Add(line);
// save PDF document
doc.Save("c:/DashLineInBlack.pdf");

//[VB.NET Code]
 
' instantiate Document instance
Dim doc As Document = New Document()
' add page to pages collection of Document object
Dim page As Page = doc.Pages.Add()
' create Drawing object with certain dimensions
Dim canvas As Aspose.Pdf.Drawing.Graph = New Aspose.Pdf.Drawing.Graph(100, 400)
' add drawing object to paragraphs collection of page instance
page.Paragraphs.Add(canvas)
' create Line object
Dim line As Aspose.Pdf.Drawing.Line = New Aspose.Pdf.Drawing.Line(New Single() {100, 100, 200, 100})
' set color for Line object
line.GraphInfo.Color = Aspose.Pdf.Color.Red
' specify dash array for line object
line.GraphInfo.DashArray = New Integer() {0, 1, 0}
' set the dash phase for Line instance
line.GraphInfo.DashPhase = 1
' add line to shapes collection of drawing object
canvas.Shapes.Add(line)
' save PDF document
doc.Save("c:/DashLineInBlack.pdf")

;

public by sherazam  184662  0  5  0

How to Render an Image of 3D Model from the Camera inside .NET Application

This Technical tip explains how .NET developers can render an image of 3D model from the camera inside their .NET applications. Using Aspose.3D for .NET, developers can render an image to view a realistic image of 3D model, with or without the enhanced background, textures, shadows and also adjust the image size. The Render method exposed by the Sc
// Enter here the actual content of the snippet.            // this code example creates a camera in a 3D scene, sets its target and render an image.

// [C# Code Sample]

// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir();

// Load scene from file
Scene scene = new Scene(MyDir + "camera.3ds");
// Create a camera at (10,10,10) and look at the origin point for rendering,
// it must be attached to the scene before render
Camera camera = new Camera();
scene.RootNode.CreateChildNode("camera", camera);
camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
camera.LookAt = Vector3.Origin;

// Specify the image render option
ImageRenderOptions opt = new ImageRenderOptions();
// Set the background color
opt.BackgroundColor = Color.AliceBlue;
// Tells renderer where the it can find textures
opt.AssetDirectories.Add(MyDir + "textures");
// Turn on shadow
opt.EnableShadows = true;
// Render the scene in given camera's perspective into specified png file with size 1024x1024
scene.Render(camera, MyDir + "Render3DModelImageFromCamera_out_.png", new Size(1024, 1024), ImageFormat.Png, opt);

//[VB.NET Code Sample]

' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
' The path to the documents directory.
Dim MyDir As String = RunExamples.GetDataDir()

' Load scene from file
Dim scene As New Scene(MyDir & Convert.ToString("camera.3ds"))
' Create a camera at (10,10,10) and look at the origin point for rendering,
' it must be attached to the scene before render
Dim camera As New Camera()
scene.RootNode.CreateChildNode("camera", camera)
camera.ParentNode.Transform.Translation = New Vector3(10, 10, 10)
camera.LookAt = Vector3.Origin

' Specify the image render option
Dim opt As New ImageRenderOptions()
' Set the background color
opt.BackgroundColor = Color.AliceBlue
' Tells renderer where the it can find textures
opt.AssetDirectories.Add(MyDir & Convert.ToString("textures"))
' Turn on shadow
opt.EnableShadows = True
' Render the scene in given camera's perspective into specified png file with size 1024x1024
scene.Render(camera, MyDir & Convert.ToString("Render3DModelImageFromCamera_out_.png"), New Size(1024, 1024), ImageFormat.Png, opt)
;

public by sherazam  4263  3  5  0

How to Crop EMF Image using Shifts or Rectangle Approaches in .NET Applications

This technical tip explains how .NET developers can Crop an EMF Image inside their .NET applications. Image cropping usually refers to the removal of the outer parts of an image to help improve the framing. Cropping may also be used to cut out some portion of an image to increase the focus on a particular area. Aspose.Imaging for .Net API supports
// Enter here the actual content of the snippet.            // Cropping by Shifts

//[C# Code Sample]

// create an instance of Rasterization options
EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;

// create an instance of PNG options
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;

//Declare variables to store file paths for input and output images
string filePath = @"TestEmfBezier.emf";
string outPath = filePath + ".pdf";

//Load an existing image into an instance of EMF class
using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
{
  using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
  {
    //Based on the shift values, apply the cropping on image
    //Crop method will shift the image bounds toward the center of image
    image.Crop(30, 40, 50, 60);

    // Set height and width
    pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
    pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;

    //Save the results to disk
    image.Save(outputStream, pdfOptions);
  }
}
 
//[VB.NET Code Sample]

' create an instance of Rasterization options
Dim emfRasterizationOptions As New EmfRasterizationOptions()
emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke

' create an instance of PNG options
Dim pdfOptions As New PdfOptions()
pdfOptions.VectorRasterizationOptions = emfRasterizationOptions

'Declare variables to store file paths for input and output images
Dim filePath As String = "TestEmfBezier.emf"
Dim outPath As String = filePath & Convert.ToString(".pdf")

'Load an existing image into an instance of EMF class
Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
	Using outputStream As New FileStream(outPath, FileMode.Create)
		'Based on the shift values, apply the cropping on image
		'Crop method will shift the image bounds toward the center of image
		image.Crop(30, 40, 50, 60)

		' Set height and width
		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height

		'Save the results to disk
		image.Save(outputStream, pdfOptions)
	End Using
End Using

// Cropping by Rectangle

//[C# Code Sample]

// create an instance of Rasterization options
EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;

// create an instance of PNG options
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;

//Declare variables to store file paths for input and output images
string filePath = @"TestEmfExtPen.emf";
string outPath = filePath + ".pdf";

//Load an existing image into an instance of EMF class
using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
{
    using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
    {
        //Create an instance of Rectangle class with desired size
        //Perform the crop operation on object of Rectangle class
        image.Crop(new Aspose.Imaging.Rectangle(30, 50, 100, 150));

        // Set height and width
        pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
        pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;

        //Save the results to disk
        image.Save(outputStream, pdfOptions);
    }
}

//[VB.NET Code Sample]

' create an instance of Rasterization options
Dim emfRasterizationOptions As New EmfRasterizationOptions()
emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke

' create an instance of PNG options
Dim pdfOptions As New PdfOptions()
pdfOptions.VectorRasterizationOptions = emfRasterizationOptions

'Declare variables to store file paths for input and output images
Dim filePath As String = "TestEmfExtPen.emf"
Dim outPath As String = filePath & Convert.ToString(".pdf")

'Load an existing image into an instance of EMF class
Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
	Using outputStream As New FileStream(outPath, FileMode.Create)
		'Create an instance of Rectangle class with desired size
		'Perform the crop operation on object of Rectangle class
		image.Crop(New Aspose.Imaging.Rectangle(30, 50, 100, 150))

		' Set height and width
		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height

		'Save the results to disk
		image.Save(outputStream, pdfOptions)
	End Using
End Using

;

public by sherazam  2867  3  5  0

How to Convert PDF Pages to TIFF Image inside .NET Applications

This technical tip shows how to convert PDF pages to TIFF image inside .NET Applications. The TiffDevice class allows you to convert PDF pages to TIFF images. This class provides a method named Process which allows you to convert all the pages in a PDF file to a single TIFF image. To convert a particular page in a PDF file to a TIFF image, use an
// Enter here the actual content of the snippet.            
//The following code snippet shows how to convert all the PDF pages to a single TIFF image.

//[C# Code Sample]
 

// Open document
Document pdfDocument = new Document("input.pdf");

// Create Resolution object
Resolution resolution = new Resolution(300);

// Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.None;
tiffSettings.Depth = ColorDepth.Default;
tiffSettings.Shape = ShapeType.Landscape;
tiffSettings.SkipBlankPages = false;

// Create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);

// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, "output.tif");

//[VB.NET Code Sample]
 

'Open document
Dim pdfDocument As New Document("input.pdf")

'Create Resolution object
Dim resolution As New Resolution(300)

'Create TiffSettings object
Dim tiffSettings As New TiffSettings()
tiffSettings.Compression = CompressionType.None
tiffSettings.Depth = ColorDepth.Default
tiffSettings.Shape = ShapeType.Landscape
tiffSettings.SkipBlankPages = False

'Create TIFF device
Dim tiffDevice As New TiffDevice(resolution, tiffSettings)

'Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, "output.tif")


//Convert One Page to TIFF Image

//[C# Code Sample]
 

// Open document
Document pdfDocument = new Document("input.pdf");

// Create Resolution object
Resolution resolution = new Resolution(300);

// Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.None;
tiffSettings.Depth = ColorDepth.Default;
tiffSettings.Shape = ShapeType.Landscape;
tiffSettings.SkipBlankPages = false;

// Create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);


// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, 1, 1, "output.tif");


//[VB.NET Code Sample]
 

'Open document
Dim pdfDocument As New Document("input.pdf")

'Create Resolution object
Dim resolution As New Resolution(300)

'Create TiffSettings object
Dim tiffSettings As New TiffSettings()
tiffSettings.Compression = CompressionType.None
tiffSettings.Depth = ColorDepth.Default
tiffSettings.Shape = ShapeType.Landscape
tiffSettings.SkipBlankPages = False

'Create TIFF device
Dim tiffDevice As New TiffDevice(resolution, tiffSettings)

'Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, 1, 1, "output.tif")

//Use Bradley algorithm during conversion

//[C# Code Sample]
 

string outputImageFile = @"c:\resultant.tif";
string outputBinImageFile = @"c:\37116-bin.tif";
//open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"c:\input.pdf");
//create Resolution object
Resolution resolution = new Resolution(300);
//create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.LZW;
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp;
//create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
//convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, outputImageFile);

using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open))
{
       using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create))
       {
              tiffDevice.BinarizeBradley(inStream, outStream, 0.1);
       }
}

//[VB.NET Code Sample]
 

Dim outputImageFile As String = "c:\resultant.tif"
Dim outputBinImageFile As String = "c:\37116-bin.tif"
'open document
Dim pdfDocument As Aspose.Pdf.Document = New Aspose.Pdf.Document("c:\input.pdf")
'create Resolution object
Dim resolution As Aspose.Pdf.Devices.Resolution = New Aspose.Pdf.Devices.Resolution(300)
'create TiffSettings object
Dim tiffSettings As TiffSettings = New TiffSettings()
tiffSettings.Compression = CompressionType.LZW
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp
'create TIFF device
Dim tiffDevice As TiffDevice = New TiffDevice(resolution, tiffSettings)
'convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, outputImageFile)

Using inStream As FileStream = New FileStream(outputImageFile, FileMode.Open)

    Using outStream As FileStream = New FileStream(outputBinImageFile, FileMode.Create)
        tiffDevice.BinarizeBradley(inStream, outStream, 0.1)
    End Using
End Using

;