Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
conholdate-gists / merge-pdf.java
Created January 22, 2025 02:26
Merge PDF Files in Java | Combine PDF Documents
// Open first document
Document pdfDocument1 = new Document(dataDir + "Concat1.pdf");
// Open second document
Document pdfDocument2 = new Document(dataDir + "Concat2.pdf");
// Add pages of second document to the first
pdfDocument1.getPages().add(pdfDocument2.getPages());
// Save concatenated output file
pdfDocument1.save(dataDir+"ConcatenatePdfFiles_out.pdf");
@conholdate-gists
conholdate-gists / redact-pdf.java
Created January 20, 2025 20:46
Redact PDF Documents in Java
// Open document
Document document = new Document("input.pdf");
com.aspose.pdf.Page page = document.getPages().get_Item(1);
// Create RedactionAnnotation instance for specific page region
com.aspose.pdf.RedactionAnnotation annot = new com.aspose.pdf.RedactionAnnotation(page, new com.aspose.pdf.Rectangle(200, 500, 300, 600));
annot.setFillColor(com.aspose.pdf.Color.getGreen());
annot.setBorderColor(com.aspose.pdf.Color.getYellow());
annot.setColor(com.aspose.pdf.Color.getBlue());
@conholdate-gists
conholdate-gists / convert-svg-to-xps.java
Created January 9, 2025 09:25
Convert SVG to XPS in Java | SVG to XPS Converter
// Set the path to the working directory.
String dir = "/Desktop/";
// Load the source SVG document by initializing a constructor of the SVGDocument class.
com.aspose.html.dom.svg.SVGDocument svgDocument = new com.aspose.html.dom.svg.SVGDocument("input.svg");
// Instantiate an object of the XpsSaveOptions class.
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions();
// Invoke the setBackgroundColor to set the background color.
@conholdate-gists
conholdate-gists / convert-svg-to-jpg-image.cs
Created January 9, 2025 09:25
Convert SVG to JPG PNG Image in C# | Vector to Raster Image
// Prepare SVG code
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" +
"<circle cx ='100' cy ='100' r ='55' fill='green' stroke='red' stroke-width='10' />" +
"</svg>";
// Prepare a path for converted file saving
string savePath = Path.Combine(dataDir, "svgtojpgimage.jpg");
// Create an instance of the ImageSaveOptions class
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg);
@conholdate-gists
conholdate-gists / create-z-archive.cs
Created December 24, 2024 16:42
Create Z Archive in C#
// Create an instance of the ZArchive class.
Aspose.Zip.Z.ZArchive archive = new Aspose.Zip.Z.ZArchive();
// Invoke the setSource method to set the content to be compressed within the archive.
archive.SetSource("first.txt");
// Call the save method to save Z archive to destination file provided.
archive.Save("archive.z");
@conholdate-gists
conholdate-gists / convert-stl-to-pdf.cs
Created December 24, 2024 16:41
Convert STL to PDF in C# | STL to PDF Converter
// Load input STL image
using (var cadImage = (Aspose.CAD.FileFormats.Cad.CadImage)Aspose.CAD.Image.Load("input.stl"))
{
// Initialize PdfOptions class instance
Aspose.CAD.ImageOptions.PdfOptions pdfOptions = new Aspose.CAD.ImageOptions.PdfOptions();
string outPath = "test.pdf";
// Convert STL to PDF
cadImage.Save(outPath, pdfOptions);
@conholdate-gists
conholdate-gists / Create-Pie-Chart-Word.cs
Created December 24, 2024 16:41
Create Pie Chart in Word Documents using C# | Insert Pie Chart in DOCX
Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
Aspose.Words.Drawing.Shape shape = builder.InsertChart(Aspose.Words.Drawing.Charts.ChartType.Pie, 432, 252);
Aspose.Words.Drawing.Charts.Chart chart = shape.Chart;
chart.Series.Clear();
Aspose.Words.Drawing.Charts.ChartSeries series = chart.Series.Add("Series 1",
new string[] { "Category1", "Category2", "Category3" },
new double[] { 2.7, 3.2, 0.8 });
@conholdate-gists
conholdate-gists / convert-mpp-to-excel-advanced.java
Last active December 20, 2024 08:05
Convert MPP to Excel XLSX in Java | Microsoft Project to Excel
// Load the input MPP file
com.aspose.tasks.Project project = new com.aspose.tasks.Project("New Project.mpp");
// Initiate XlsxOptions class object
com.aspose.tasks.XlsxOptions options = new com.aspose.tasks.XlsxOptions();
options.setPageSize(com.aspose.tasks.PageSize.A4);
// Convert MS Project MPP to Excel XLSX
project.save("MS Project.xlsx", options);
@conholdate-gists
conholdate-gists / convert-mpp-to-csv-advanced.java
Last active December 23, 2024 08:49
Convert MS Project File to CSV in Java | MPP to comma-separated Value File
// Load the input MPP file
com.aspose.tasks.Project project = new com.aspose.tasks.Project("New Project.mpp");
// Create CsvOptions class object
com.aspose.tasks.CsvOptions options = new com.aspose.tasks.CsvOptions();
options.setTextDelimiter(com.aspose.tasks.CsvTextDelimiter.Semicolon);
// Save the output CSV file
project.save("CsvOptions_out.csv", options);
@conholdate-gists
conholdate-gists / compare-folders.cs
Created December 16, 2024 09:37
Compare Folders or Directories in C# .NET
// Create an object of CompareOptions class
GroupDocs.Comparison.Options.CompareOptions compareOptions = new GroupDocs.Comparison.Options.CompareOptions();
compareOptions.DirectoryCompare = true;
// Initiate an instance of the Comparer class and specify the folders
GroupDocs.Comparison.Comparer comparer = new GroupDocs.Comparison.Comparer("C:\\folder1\\", compareOptions);
comparer.Add("C:\\folder2\\", compareOptions);
// Compare folders
comparer.Compare("C:\\res.html", compareOptions);