Skip to content

Instantly share code, notes, and snippets.

@documentprocessing
Created October 26, 2024 06:17
Show Gist options
  • Save documentprocessing/c604ed891e41186d6f3d8ba1008fa4a3 to your computer and use it in GitHub Desktop.
Save documentprocessing/c604ed891e41186d6f3d8ba1008fa4a3 to your computer and use it in GitHub Desktop.
Add image to PDF using QuestPDF
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
class Program
{
static void Main(string[] args)
{
// Create a PDF document
Document.Create(document =>
{
// Define document structure
document.Page(page =>
{
// Set page size and margin
page.Size(PageSizes.A4);
page.Margin(2, Unit.Centimetre);
// Add image to the PDF
page.Content()
.Image("path/to/your/image.jpg", ImageScaling.FitWidth); // Adjust the path accordingly
});
})
.GeneratePdf("ImageDocument.pdf"); // Save the PDF to a file
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment