Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 2.01 KB

README.md

File metadata and controls

63 lines (45 loc) · 2.01 KB

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