Art F
Art F

Reputation: 4202

Converting Excel, PowerPoint, PDF, and Word to Images in .NET using Aspose

so I am looking for a way to convert Excel, PowerPoint, PDF, and Word to Images. I was wondering if anyone has experience with the Aspose suite and knows if all of this can be done with the Aspose.PDF suite, or would I need to get Aspose.slides, and Aspose.word as well?

Upvotes: 4

Views: 5301

Answers (4)

codeshinobi
codeshinobi

Reputation: 114

I know it's 2019, but if anyone is still wondering, you can do this using Aspose.Words.

The following values (and more) in the SaveFormat enum are available:

    Tiff = 100,
    //
    // Summary:
    //     Renders a page of the document and saves it as a PNG file.
    Png = 101,
    //
    // Summary:
    //     Renders a page of the document and saves it as a BMP file.
    Bmp = 102,
    //
    // Summary:
    //     Renders a page of the document and saves it as a JPEG file.
    Jpeg = 104,
    //
    // Summary:
    //     Renders a page of the document and saves it as a GIF file.
    Gif = 105

You would use them like so:

    var fileContents = asposeDocument.GenerateDocument(Aspose.Words.SaveFormat.Png);

Upvotes: 0

Khadim Ali
Khadim Ali

Reputation: 2598

Conversion from office document to image could be done without using any third party component. Below code will convert specific range from an Excel worksheet to Image, for example.

IMPORTANT: Don't forget to mark the method with [STAThread] attribute.

Usings:

    using xls = Microsoft.Office.Interop.Excel;
    using System.IO;
    using System.Windows.Forms;

Conversion Code:

    [STAThread]
    static void Main(string[] args)
    {
        string fileNameToProcess = @"D:\Book2.xlsx";

        //Start Excel and create a new document.
        xls.Application oExcel = new xls.Application();
        xls.Workbook wb = null;
        try
        {
            wb = oExcel.Workbooks.Open(
                fileNameToProcess.ToString(), false, false, Type.Missing, "", "", true, xls.XlPlatform.xlWindows, "", false, false, 0, false, true, 0);
            //wb.RefreshAll();

            xls.Sheets sheets = wb.Worksheets as xls.Sheets;
            xls.Worksheet sheet = sheets[1];

            //Following is used to find range with data
            string startRange = "A1";
            string endRange = "P25";
            xls.Range range = sheet.get_Range(startRange, endRange);
            range.CopyPicture(xls.XlPictureAppearance.xlScreen, xls.XlCopyPictureFormat.xlBitmap);

            System.Drawing.Image imgRange = GetImageFromClipboard();

            imgRange.Save(@"d:\ExcelSheetImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

            wb.Save();
            Console.Write("Specified range converted to image successfully. Press Enter to continue.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            //throw;
        }
        finally 
        {
            wb.Close();
            oExcel.Quit();
            oExcel = null;
        }

        Console.ReadLine();
    }

    public static System.Drawing.Image GetImageFromClipboard()
    {
        System.Drawing.Image returnImage = null;

        // This doesn't work
        //if (Clipboard.ContainsImage())
        //{
        //    returnImage = Clipboard.GetImage();
        //}
        //return returnImage;

        // This works
        System.Windows.Forms.IDataObject d = Clipboard.GetDataObject();
        if (d.GetDataPresent(DataFormats.Bitmap))
        {
            returnImage = Clipboard.GetImage();
        }

        return returnImage;
    }

Upvotes: 2

codewarior
codewarior

Reputation: 441

My name is Nayyer and I am working as developer evangelist at Aspose.

  • Aspose.Words is provides the feature to create/manipulate MS word documents and it also offers the feature to convert word documents into Image format. You may check following link for more details on convert MS Word document to Image (simply select Jpeg, Png, Bmp from SaveFormat enumeration).
  • Similarly you can use Aspose.Cells to convert Excel worksheets into Image format. Converting worksheet into Image
  • Aspose.Slides can be used to convert PowerPoint presentations to Image format. Create Thumbnail image of slide.
  • Aspose.Pdf supports the feature to transform PDF pages into Image format. For further details, please visit Convert all PDF pages to JPEG format.

Upvotes: 1

Denis Palnitsky
Denis Palnitsky

Reputation: 18387

You will need Aspose.Slides, Aspose.Words, Aspose.Cells and Aspose.Pdf or you can use Web Api

Upvotes: 3

Related Questions