I am trying to create a web service that will convert a doc/docx to png format.
The problem I seem to have is I can't find any library or something close to it that will do what I need, considering I am looking for something free and not Office dependent (the server where the app will run does not have Office installed).
Is there anything that can help me in obtaining this? Or must I choose between using something office dependant (like Interop - which btw I read is really bad to be used on server) or something that isn't free?
Thanks
I know this is most likely not what you want, since it is not free.
But Aspose can do what you need.
Spire.doc too. Again, not free.
Aspose:
string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;
// Open the document.
Document doc = new Document(dataDir + "SaveAsPNG.doc");
//Create an ImageSaveOptions object to pass to the Save method
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
options.Resolution = 160;
// Save each page of the document as Png.
for (int i = 0; i < doc.PageCount; i++)
{
options.PageIndex = i;
doc.Save(string.Format(dataDir+i+"SaveAsPNG out.Png", i), options);
}
Spire.doc (WPF):
using Spire.Doc;
using Spire.Doc.Documents;
namespace Word2Image
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Document doc = new Document("sample.docx", FileFormat.Docx2010);
BitmapSource[] bss = doc.SaveToImages(ImageType.Bitmap);
for (int i = 0; i < bss.Length; i++)
{
SourceToBitmap(bss[i]).Save(string.Format("img-{0}.png", i));
}
}
private Bitmap SourceToBitmap(BitmapSource source)
{
Bitmap bmp;
using (MemoryStream ms = new MemoryStream())
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(source));
encoder.Save(ms);
bmp = new Bitmap(ms);
}
return bmp;
}
}
}