Pacem.Extensions.OfficeWord.Pdf 0.8.6

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Pacem.Extensions.OfficeWord.Pdf --version 0.8.6                
NuGet\Install-Package Pacem.Extensions.OfficeWord.Pdf -Version 0.8.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pacem.Extensions.OfficeWord.Pdf" Version="0.8.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pacem.Extensions.OfficeWord.Pdf --version 0.8.6                
#r "nuget: Pacem.Extensions.OfficeWord.Pdf, 0.8.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pacem.Extensions.OfficeWord.Pdf as a Cake Addin
#addin nuget:?package=Pacem.Extensions.OfficeWord.Pdf&version=0.8.6

// Install Pacem.Extensions.OfficeWord.Pdf as a Cake Tool
#tool nuget:?package=Pacem.Extensions.OfficeWord.Pdf&version=0.8.6                

Office Word Extensions

About

Pacem.Extensions.OfficeWord.Pdf provides a lightweight set of utilities that ease the conversion of .docx documents into PDFs.

This library depends on Pacem.Extensions.OfficeWord. Please, check its documentation first.

The following paragraphs exemplify the library utilization.

Getting started

Inject the IOfficeWordPdfConverter singleton service into the DI container.

Currently, there's no other [than the dependency injection] way to reach the instance of the processor service.

Like this:

// Program.cs
// You can inject your own instance of `IOfficeWordPdfConverter`
services.AddPacemOfficeWordProcessor()
	.WithPdfConverter<MyConverterType>();

Or you can lean on the - actually sole - implementation of IOfficeWordPdfConverter, which relies on Microsoft Graph API.

You need an account bound to an Office 365 subscription, and an Azure Application relevant to that user with access to the Microsoft Graph API.

// Program.cs
// You can inject your own instance of `IOfficeWordPdfConverter`
services.AddPacemOfficeWordProcessor()
	.WithMicrosoftGraphPdfConverter(options => {
		options.TenantId = "00000000-0000-0000-0000-000000000000", // your tenant id
		options.ClientId = "00000000-0000-0000-0000-000000000000", // your application id
		options.ClientSecret = "Sneaky~Password", // your application secret
		options.UserId = "00000000-0000-0000-0000-000000000000", // the user id licensed w Office 365
	});

Then use it in your services, like this:

namespace Pacem.OpenXml.OfficeWord;

public class MyController : ControllerBase
{
    private readonly IOfficeWordProcessor _word;
    private readonly IOfficeWordPdfConverter _pdf;

    public MyController(IOfficeWordProcessor word, IOfficeWordPdfConverter pdf)
    {
        _word = word;
		_pdf = pdf;
    }

    // [...]
}

Usage

For a comprehensive list of usage example, please refer to Pacem.Extensions.OfficeWord documentation.

Here's a simple find and replace code sample.
The important part is the conversion function, which is the last instruction in the code sample.

string root = AppContext.BaseDirectory;
string source = Path.Combine(root, "file1.docx");
string target = Path.Combine(root, "file1-replaced.pdf");
await _word.Open(source)
    .Find("[_my_placeholder_]")
    .ReplaceWith("Hello, World!")
    .FlushPdfAsync(_pdf, target);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.10-abel 106 4/22/2024
0.8.6 129 3/17/2024
0.8.6-abel 87 3/14/2024
0.8.5 114 3/13/2024
0.8.4 106 3/12/2024
0.8.3 110 3/12/2024
0.8.2 109 3/11/2024
0.8.1 97 3/11/2024
0.8.0 122 2/4/2024
0.8.0-akkad 180 12/8/2023
0.7.4 226 11/20/2023
0.7.3 128 11/17/2023