Skip to content

Instantly share code, notes, and snippets.

View farhan-raza's full-sized avatar

Farhan Raza farhan-raza

View GitHub Profile
@farhan-raza
farhan-raza / Web page to PDF Encryption.cs
Last active June 10, 2022 13:03
Save webpage as PDF in C# | C# print web page to PDF
// Load input HTML from URL
HTMLDocument document = new HTMLDocument("https://www.aspose.com");
// Initialize PdfPermissions class object to allow printing and form filling in the PDF document
PdfPermissions permissions = PdfPermissions.PrintDocument | PdfPermissions.FillForm;
// Initialize PdfSaveOptions class object and set the encryption properties
PdfSaveOptions options = new PdfSaveOptions();
options.Encryption = new PdfEncryptionInfo("user", "owner", permissions, Encryption.PdfEncryptionAlgorithm.RC4_128);
@farhan-raza
farhan-raza / Add_Image_Watermark.cs
Created January 9, 2021 21:35
Insert or Delete Text/Image Watermark in PDF File using C#
// Load input PDF document
Document pdfDocument = new Document(dataDir + "Input.pdf");
// Access any page of the input PDF
Page testpage = pdfDocument.Pages[1];
// Create image stamp
ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.png");
imageStamp.Background = true;
imageStamp.Height = 300;
@farhan-raza
farhan-raza / SetLicense.cs
Last active January 7, 2021 00:26
Install or Apply License for Aspose.Total API
// Set license for all APIs one by one
Aspose.Words.License WordsLicense = new Aspose.Words.License();
WordsLicense.SetLicense(@"D:\Test\Aspose.Total.Product.Family.lic");
// Comment the code if you do not want to set license for any of the API
//Aspose.Pdf.License PdfLicense = new Aspose.Pdf.License();
//PdfLicense.SetLicense(@"D:\Test\Aspose.Total.Product.Family.lic");
Aspose.Cells.License CellsLicense = new Aspose.Cells.License();
CellsLicense.SetLicense(@"D:\Test\Aspose.Total.Product.Family.lic");
@farhan-raza
farhan-raza / Set_License.cs
Last active July 11, 2024 21:26
Evaluation Only. Created with Aspose. Copyright 2003-2020 Aspose Pty Ltd, At most 4 elements (for any collection) can be viewed in evaluation mode, This document was truncated here because it was created using Aspose API in Evaluation Mode
Aspose.Words.License license = new Aspose.Words.License();
// This line attempts to set a license from several locations relative to the executable and Aspose.Words.dll.
// You can also use the additional overload to load a license from a stream, this is useful for instance when the
// license is stored as an embedded resource
try
{
license.SetLicense("Aspose.Words.lic");
Console.WriteLine("License set successfully.");
}
@farhan-raza
farhan-raza / Grid.cpp
Created December 31, 2020 22:28
Insert Gradient, Grid, or Transparent Objects in XPS File with C++
auto doc = System::MakeObject<XpsDocument>();
// Geometry for magenta grid VisualBrush
System::SharedPtr<XpsPathGeometry> pathGeometry = doc->CreatePathGeometry();
pathGeometry->AddSegment(doc->CreatePolyLineSegment(System::MakeArray<System::Drawing::PointF>({ System::Drawing::PointF(240.f, 5.f), System::Drawing::PointF(240.f, 310.f), System::Drawing::PointF(0.f, 310.f) })));
pathGeometry->idx_get(0)->set_StartPoint(System::Drawing::PointF(0.f, 5.f));
// Canvas for magenta grid VisualBrush
System::SharedPtr<XpsCanvas> visualCanvas = doc->CreateCanvas();
@farhan-raza
farhan-raza / AddImage.cpp
Created December 30, 2020 21:09
Insert Text or Image in XPS File Programmatically using C++
// Create new XPS Document
System::SharedPtr<XpsDocument> doc = System::MakeObject<XpsDocument>();
// Add Image
System::SharedPtr<XpsPath> path = doc->AddPath(doc->CreatePathGeometry(u"M 30,20 l 258.24,0 0,56.64 -258.24,0 Z"));
// Creating a matrix is optional, it can be used for proper positioning
path->set_RenderTransform(doc->CreateMatrix(0.7f, 0.f, 0.f, 0.7f, 0.f, 20.f));
//Create Image Brush
@farhan-raza
farhan-raza / PLTtoJPG.cs
Created December 25, 2020 22:49
Convert PLT to PDF, JPEG, or PNG File Programmatically in C#
// The path to the documents directory.
string sourceFilePath = MyDir + "50states.plt";
// Load input PLT file
using (Image cadImage = Image.Load(sourceFilePath))
{
// Initilize JpegOptions class instance
ImageOptionsBase imageOptions = new JpegOptions();
// Specify CadRasterizationOptions properties
@farhan-raza
farhan-raza / Split-HTML-file.cs
Created December 23, 2020 18:07
Split HTML Webpage into Multiple Files Programmatically using C#
String content = File.ReadAllText(dataDir1 + "Product.html");
// Create an instance of HTML document
var document = new HTMLDocument(content, "");
// Split HTML webpage to multiple files
// find all paragraph elements inside document by using CSS Selector Query
var elements = document.QuerySelectorAll("p");
for (int i = 0; i < elements.Length; i++)
{
// create an empty document to export content
@farhan-raza
farhan-raza / AItoJPEG.cs
Created December 21, 2020 21:58
Convert AI files to PSD, PDF, JPEG or PNG Image Format Programmatically in Java
String dataDir = Utils.getDataDir(AIToJPG.class) + "AI/";
String sourceFileName = dataDir + "34992OStroke.ai";
String outFileName = dataDir + "34992OStroke.jpg";
// Load input AI file
AiImage image = (AiImage)Image.load(sourceFileName);
// Initialize JpegOptions class instance
JpegOptions options = new JpegOptions();
@farhan-raza
farhan-raza / FBXtoOBJ.cs
Created December 18, 2020 21:53
Convert FBX to Wavefront OBJ | Export FBX to PDF in C#
// Load the FBX file to be converted
Scene scene = new Scene(dataDir + "Test1.fbx");
// Save in wavefront OBJ file format
scene.Save(dir + "output.obj", FileFormat.WavefrontOBJ);