We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How I can convert Pdf to images and insert all image into docx file?

Dear
I have a docx file and set of PDF files that I need to convert all the PDF files to images and append them to a DOCX file using Aspose.NET word with the same style, order, width, and height.

I need example for above senior
please advice

HI @JassarMahmoud

We have several examples , I will show you two with which you can do what you require

  1. Convert PDF to Images
    https://docs.aspose.com/pdf/net/convert-pdf-to-images-format/#convert-pdf-using-imagedevice-class
 public static class ExampleConvertPdfToImage
 {
      private static readonly string _dataDir = @"C:\Samples\";
     // BMP, JPEG, GIF, PNG, EMF
     public static void ConvertPDFusingImageDevice()
     {
         // Create Resolution object            
         Resolution resolution = new Resolution(300);
         BmpDevice bmpDevice = new BmpDevice(resolution);
         JpegDevice jpegDevice = new JpegDevice(resolution);
         GifDevice gifDevice = new GifDevice(resolution);
         PngDevice pngDevice = new PngDevice(resolution);
         EmfDevice emfDevice = new EmfDevice(resolution);
 
         Document document = new Document(_dataDir + 
             "ConvertAllPagesToBmp.pdf");
             
         ConvertPDFtoImage(bmpDevice, "bmp", document);
         ConvertPDFtoImage(jpegDevice,"jpeg", document);
         ConvertPDFtoImage(gifDevice, "gif", document);
         ConvertPDFtoImage(pngDevice, "png", document);
         ConvertPDFtoImage(emfDevice, "emf", document);
             
     }
 }
 
 public static void ConvertPDFtoImage(ImageDevice imageDevice, 
         string ext, Document pdfDocument)
 {
     for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
     {
         using (FileStream imageStream = 
         new FileStream($"{_dataDir}image{pageCount}_out.{ext}", 
         FileMode.Create))
         {
             // Convert a particular page and save the image to stream
             imageDevice.Process(pdfDocument.Pages[pageCount], imageStream);
 
             // Close stream
             imageStream.Close();
         }
     }
 }
  1. Load the DOCX file using Aspose.NET WORD
    https://docs.aspose.com/words/net/create-or-load-a-document/#load-from-a-file

  2. add Images to DOCX
    https://kb.aspose.com/words/net/how-to-add-image-in-word-document-using-c-sharp/

you can use API reference for change or mantain same style in document
https://docs.aspose.com/words/net/programming-with-documents/

hope that help

Regards
LC