LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert Documents (like PDF) to Image DOCX
#1
Posted
:
Thursday, December 31, 2020 2:14:16 PM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
The following code uses LEADTOOLS .NET classes to convert any supported input document (such as PDF) to image-based DOCX.
The code uses the Leadtools.Codecs.RasterCodecs class to load the input file as raster image pages, the uses the Leadtools.Document.Writer.DocumentWriter class to create a DOCX document and add all the pages as images.
NOTE: To convert to document-based instead of image-based DOCX, use the Leadtools.Document.Converter.DocumentConverter class.Code:static void PdfToImageDocx(string pdfFileName, string docxFileName)
{
RasterCodecs codecs = new RasterCodecs();
// load all PDF pages as images
RasterImage pagesImage = codecs.Load(pdfFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);
codecs.Options.RasterizeDocument.Load.Resolution = 300;
DocumentWriter docWriter = new DocumentWriter();
// Begin a new DocX document
docWriter.BeginDocument(docxFileName, DocumentFormat.Docx);
// Add the pages
for (int i = 1; i <= pagesImage.PageCount; i++)
{
pagesImage.Page = i; // loop through the images from input PDF
DocumentWriterRasterPage pageR = new DocumentWriterRasterPage();
pageR.Image = pagesImage.Clone(); // copy the current image page into the new Docx page
docWriter.AddPage(pageR);
if (pageR.Image != null)
pageR.Image.Dispose();
}
// Finalize document to disk
docWriter.EndDocument();
pagesImage.Dispose();
}
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Convert Documents (like PDF) to Image DOCX
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.