new overloads to generate images based on the passed settings

This commit is contained in:
2023-05-17 16:09:57 +02:00
parent 3a73886d70
commit f20d7af0c5
2 changed files with 24 additions and 11 deletions
+4 -3
View File
@@ -45,13 +45,14 @@ namespace QuestPDF.Drawing
throw new ArgumentException("The library requires a Stream object with the 'seek' capability available (the CanSeek flag). Please consider using the MemoryStream class.");
}
internal static ICollection<byte[]> GenerateImages(IDocument document)
internal static ICollection<byte[]> GenerateImages(IDocument document, ImageGenerationSettings settings)
{
ValidateLicense();
var settings = document.GetSettings();
var documentSettings = document.GetSettings();
documentSettings.ImageRasterDpi = settings.RasterDpi;
var canvas = new ImageCanvas(settings);
RenderDocument(canvas, document, settings);
RenderDocument(canvas, document, documentSettings);
return canvas.Images;
}
+20 -8
View File
@@ -75,30 +75,42 @@ namespace QuestPDF.Fluent
public static IEnumerable<byte[]> GenerateImages(this IDocument document)
{
return DocumentGenerator.GenerateImages(document);
return document.GenerateImages(ImageGenerationSettings.Default);
}
public static IEnumerable<byte[]> GenerateImages(this IDocument document, ImageGenerationSettings settings)
{
return DocumentGenerator.GenerateImages(document, settings);
}
/// <param name="filePath">Method should return fileName for given index</param>
public static void GenerateImages(this IDocument document, Func<int, string> filePath)
{
document.GenerateImages(filePath, ImageGenerationSettings.Default);
}
/// <param name="filePath">Method should return fileName for given index</param>
public static void GenerateImages(this IDocument document, Func<int, string> filePath, ImageGenerationSettings settings)
{
var index = 0;
foreach (var imageData in document.GenerateImages())
foreach (var imageData in document.GenerateImages(settings))
{
var path = filePath(index);
if (File.Exists(path))
File.Delete(path);
File.WriteAllBytes(path, imageData);
index++;
}
}
#endregion
#region Helpers
private static void OpenFileUsingDefaultProgram(string filePath)
{
var process = new Process