Skip to content

Image decoder for PDF files for ImageSharp based on PdfLibCore

License

Notifications You must be signed in to change notification settings

skttl/ImageSharpCommunity.Formats.Pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ImageSharpCommunity.Formats.Pdf

Downloads NuGet GitHub license

Image decoder for PDF files for ImageSharp based on PdfLibCore

Install

via NuGet:

PM> Install-Package ImageSharp.Community.Formats.Pdf

Usage

using System.IO;

using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Processing;
using ImageSharpCommunity.Formats.Pdf;

// Create custom configuration with PDF decoder
var configuration = new Configuration(
    new PdfConfigurationModule());

using var inputStream = File.OpenRead("/path/to/document.pdf");
using var image = Image.Load(inputStream);

// Resize
image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2)); 

// Save image
image.SaveAsPng("document.png");

More info https://docs.sixlabors.com/articles/imagesharp/configuration.html

Usage in Umbraco

To use in Umbraco, you must inject the configuration in an appropriate manor, eg. in a Composer.

using Umbraco.Cms.Core.Composing;

namespace MyUmbracoProject;

public class PdfFormatComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        var config = SixLabors.ImageSharp.Configuration.Default.Clone();
        config.Configure(new ImageSharpCommunity.Formats.Pdf.PdfConfigurationModule());
    }
}

This will be picked up by Umbraco when starting the website, and adds the necessary configuration.

License

MIT

About

Image decoder for PDF files for ImageSharp based on PdfLibCore

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published