Skip to content

Instantly share code, notes, and snippets.

View aspose-com-gists's full-sized avatar

Aspose.com Gists aspose-com-gists

View GitHub Profile
@aspose-com-gists
aspose-com-gists / mhtml_to_pdf.java
Created August 7, 2026 07:25
MHTML to PDF Conversion Tutorial in Java
import com.aspose.html.HTMLDocument;
import com.aspose.html.converters.Converter;
import com.aspose.html.converters.PdfSaveOptions;
public class MhtmlToPdfConversion {
public static void main(String[] args) {
// Paths to the source MHTML file and the destination PDF file
String sourceMhtmlPath = "input.mhtml";
String destinationPdfPath = "output.pdf";
@aspose-com-gists
aspose-com-gists / add_barcode_to_pdf.java
Created August 5, 2026 19:52
Add Barcode to PDF in Java
import com.aspose.pdf.Document;
import com.aspose.pdf.Page;
import com.aspose.pdf.Barcode;
import com.aspose.pdf.BarcodeType;
import com.aspose.pdf.PlacementType;
public class AddBarcodeToPdf {
public static void main(String[] args) {
try {
// Load the existing PDF document
@aspose-com-gists
aspose-com-gists / pdf_barcode_insert.java
Created August 5, 2026 19:29
Add Barcode to PDF in Java
import com.aspose.pdf.*;
public class AddBarcodeToPdf {
public static void main(String[] args) {
// Load the existing PDF document
Document pdfDocument = new Document("input.pdf");
// Get the first page of the PDF
Page page = pdfDocument.getPages().get_Item(1);
@aspose-com-gists
aspose-com-gists / html_to_text.py
Created August 5, 2026 08:29
Convert HTML to TXT in Python
import os
import sys
import aspose.html as ah
import aspose.html.saving as ahs
def convert_html_to_txt(input_path: str, output_path: str, encoding: str = "utf-8") -> None:
"""
Converts an HTML file to a plain text (TXT) file using Aspose.HTML for Python via .NET.
"""
if not os.path.isfile(input_path):
@aspose-com-gists
aspose-com-gists / html_editor.py
Created August 5, 2026 07:04
Create Read and Edit HTML in Python
import os
import sys
from aspose.html import HtmlDocument, HtmlLoadOptions, HtmlSaveOptions, HtmlLoadOptions
def create_html(output_path: str):
# Create a new empty HTML document
doc = HtmlDocument()
try:
# Build <html><head><title>...</title></head><body>...</body></html>
html = doc.create_element("html")
@aspose-com-gists
aspose-com-gists / markdown_to_docx.py
Created July 23, 2026 18:12
MD to DOCX Conversion in Python
import markdown
from aspose.html import HtmlDocument, SaveFormat
# Path to the source Markdown file
markdown_path = "sample.md"
# Path for the generated DOCX file
docx_path = "output.docx"
# Step 1: Read Markdown content
with open(markdown_path, "r", encoding="utf-8") as md_file:
@aspose-com-gists
aspose-com-gists / pdf_to_txt_aspose.py
Created July 22, 2026 08:17
Convert PDF to TXT in Python
import aspose.pdf as ap
def convert_pdf_to_txt(input_path: str, output_path: str):
# Load the PDF document
document = ap.Document(input_path)
# Create a TextAbsorber to extract text
absorber = ap.TextAbsorber()
document.pages.accept(absorber)
@aspose-com-gists
aspose-com-gists / pdf_to_docx_aspose.py
Created July 20, 2026 08:49
Convert PDF to DOCX in Python
import aspose.pdf as ap
# Load the source PDF document
pdf_document = ap.Document("input.pdf")
# Optional: Set conversion options (e.g., preserve formatting)
save_options = ap.DocSaveOptions()
save_options.preserve_form_fields = True
save_options.preserve_text = True
@aspose-com-gists
aspose-com-gists / images_to_pdf.py
Created July 17, 2026 08:02
Generate PDF from Images in Python
import os
import io
from PIL import Image
import aspose.pdf as ap
# -------------------- Configuration --------------------
image_folder = "input_images" # Folder containing source images
output_pdf = "output/result.pdf" # Destination PDF file
jpeg_quality = 80 # Compression quality (0‑100)
@aspose-com-gists
aspose-com-gists / epub_to_pdf_advanced.cs
Created July 16, 2026 08:57
Convert EPUB to PDF in C#
using System;
using Aspose.Pdf;
using Aspose.Pdf.SaveOptions;
namespace EpubToPdfDemo
{
class Program
{
static void Main(string[] args)
{