We are happy to announce the new monthly 25.4 version of Wordize is published.
Issue | Description |
---|---|
WRDZNET‑34 | Incorrect image export in Merger.Merge method |
WRDZNET-44 | Wordize library fails to process PDF files correctly in Replacer and Watermarker modules |
WRDZNET-21 | Implement chain-like API in Wordize. |
WRDZNET-35 | Watermarker.SetImage requires SkiaSharp dependency for image input instead of supporting Stream |
WRDZNET-17 | Create wrappers for FontSetting classes. |
WRDZNET-18 | Create wrappers for LoadOptions classes. |
WRDZNET-19 | Create wrappers for SaveOptions classes. |
WRDZNET-20 | Create wrapper for IWarningCallback. |
WRDZNET-48 | Create wrappers for LayoutOptions classes. |
What’s new
Fluent API
Starting from 25.3 version new Fluent API has been introduced in Wordize.
Conversion is as simple as specifying the input and output documents. The input can be either a file path or a stream containing the input file data. The following example demonstrates how to convert a DOCX file to PDF:
Converter.Create()
.From(@"C:\Temp\in.docx")
.To(@"C:\Temp\out.pdf")
.Execute();
Sometimes it is required to specify additional document load options, for example for conversion password encrypted document. In this case simply pass the appropriate LoadOptions
:
Converter.Create()
.From(@"C:\Temp\encrypted.docx", new LoadOptions() { Password = "1234" })
.To(@"C:\Temp\out.pdf")
.Execute();
The result can be saved directly to a file, a stream, or a list of streams. The last is particularly useful when saving the result as images, where each page of the document is saved as a separate stream and added to the list. You can specify multiple output types at the same time.
MemoryStream outStream = new MemoryStream();
List<Stream> outputStreams = new List<Stream>();
Converter.Create()
.From(@"C:\Temp\in.docx")
.To(@"C:\Temp\out.rtf")
.To(outStream, SaveFormat.Odt)
.To(outputStreams, SaveFormat.Png) // Note: a separate stream is created for each page. The streams disposing is the consumer responsibility.
.Execute();
The output document format can be detected automatically based on the specified file extension, as shown above. Alternatively, the output format can be set explicitly. Additionally, you can specify advanced save options by passing the appropriate SaveOptions
instance. The following example demonstrates how to convert a document to PDF with Ua2
compliance.
Converter.Create()
.From(@"C:\Temp\in.docx")
.To(@"C:\Temp\out.pdf", new PdfSaveOptions() { Compliance = PdfCompliance.PdfUa2 })
.Execute();
Configuring Wordize
The processor context allows configuring the document layout process using LayoutOptions
, specifying font settings with FontSettings
, and setting a warning callback to receive notifications about issues during document processing. The following code example demonstrates configuring of LayoutOptions
:
ConverterContext context = new ConverterContext();
context.LayoutOptions.CommentDisplayMode = Layout.CommentDisplayMode.Hide;
context.LayoutOptions.RevisionOptions.ShowRevisionMarks = false;
context.LayoutOptions.RevisionOptions.ShowRevisionBars = false;
Converter.Create(context)
.From(@"C:\Temp\in.docx")
.To(@"C:\Temp\out.pdf")
.Execute();
The following example demonstrates how to specify fonts folder location using FontSettings
:
ConverterContext context = new ConverterContext();
context.FontSettings = new FontSettings();
context.FontSettings.SetFontsFolder(@"C:\Temp\Fonts", true);
Converter.Create(context)
.From(@"C:\Temp\in.docx")
.To(@"C:\Temp\out.pdf")
.Execute();
Note: The example above demonstrates how to configure font settings for a specific document processing operation. If you need to configure font settings globally, you can use Wordize.Settings.DefaultFontSettings
:
Wordize.Settings.DefaultFontSettings.SetFontsFolder(@"C:\Temp\Fonts", true);
Converter.Create()
.From(@"C:\Temp\in.docx")
.To(@"C:\Temp\out.pdf")
.Execute();
The following code example demonstrates how to receive notifications about font substitution upon performing document processing operation:
ConverterContext context = new ConverterContext();
context.WarningCallback = new FontSubstitutionWarningCallback();
Converter.Create(context)
.From(@"C:\Temp\in.docx")
.To(@"C:\Temp\out.pdf")
.Execute();
private class FontSubstitutionWarningCallback : IWarningCallback
{
public void Warning(WarningInfo info)
{
if (info.WarningType == WarningType.FontSubstitution)
Console.WriteLine(info.Description);
}
}