Method RenderToFiles
- Namespace
- LMKit.Document.Conversion
- Assembly
- LM-Kit.NET.dll
RenderToFiles(string, string, string, double, string, string)
Renders multiple pages from a PDF file and saves them as image files.
public static List<string> RenderToFiles(string inputPath, string outputDirectory, string pageRange = null, double zoom = 2, string format = "png", string fileNamePrefix = null)
Parameters
inputPathstringPath to the source PDF file.
outputDirectorystringDirectory where rendered images will be saved. Created if it does not exist.
pageRangestringA 1-based page range string (e.g., "1-5, 7"). Null, empty, or "*" renders all pages.
zoomdoubleZoom factor for rendering. Default is 2.0.
formatstringOutput image format:
"png","jpg", or"bmp". Default is"png".fileNamePrefixstringOptional prefix for output file names. Defaults to the input file name without extension. Files are named
{prefix}_page{N}.{format}where N is the 1-based page number.
Returns
Examples
using LMKit.Document.Pdf;
var files = PdfToImage.RenderToFiles(
"presentation.pdf",
"output/slides",
pageRange: "1-10",
zoom: 2.0,
format: "jpg");
foreach (string path in files)
{
Console.WriteLine($"Created: {path}");
}
Exceptions
- ArgumentNullException
Thrown when
inputPathoroutputDirectoryisnull.- FileNotFoundException
Thrown when
inputPathdoes not exist.
RenderToFiles(Attachment, string, string, double, string, string)
Renders multiple pages from a PDF attachment and saves them as image files.
public static List<string> RenderToFiles(Attachment source, string outputDirectory, string pageRange = null, double zoom = 2, string format = "png", string fileNamePrefix = null)
Parameters
sourceAttachmentThe source PDF attachment.
outputDirectorystringDirectory where rendered images will be saved. Created if it does not exist.
pageRangestringA 1-based page range string. Null, empty, or "*" renders all pages.
zoomdoubleZoom factor for rendering. Default is 2.0.
formatstringOutput image format:
"png","jpg", or"bmp". Default is"png".fileNamePrefixstringOptional prefix for output file names. Defaults to the source file name without extension.
Returns
Examples
using LMKit.Data;
using LMKit.Document.Conversion;
var source = new Attachment("slides.pdf");
var files = PdfToImage.RenderToFiles(
source,
"output/slides",
pageRange: "1-3",
format: "png",
fileNamePrefix: "deck");
Console.WriteLine($"Rendered {files.Count} pages.");
Exceptions
- ArgumentNullException
Thrown when
sourceoroutputDirectoryisnull.- ArgumentException
Thrown when the source attachment is not a PDF.