Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, December 31, 2020 2:14:16 PM(UTC)

Amin  
Amin

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.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.035 seconds.