How can we display Word/Text Document
How can we display Word/Text Document
I had tried to open the Word document into the GDPicture .Net viewer, I had got the Error like
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt. "
Can anybody have the solution for this..
Thanks,
Hasan
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt. "
Can anybody have the solution for this..
Thanks,
Hasan
Re: How can we display Word/Text Document
Hi,
Word is a closed format. Therefore, if you want to display a doc you have to use the Microsoft automation.
here a sample:
Kind regards,
Loïc
Word is a closed format. Therefore, if you want to display a doc you have to use the Microsoft automation.
here a sample:
Code: Select all
Dim oWord As New Microsoft.Office.Interop.Word.Application
oWord.Documents.Open("c:\mydoc.doc", False, True, False)
oWord.Documents(1).Activate()
Clipboard.Clear()
oWord.Documents(1).Select()
oWord.Selection.CopyAsPicture()
oWord.Application.Documents(1).Close(False)
oWord.Quit()
Call GdViewer1.DisplayFromClipboard()
Loïc
Re: How can we display Word/Text Document
Thanks for your Explanation/code.
Loïc wrote:Hi,
Word is a closed format. Therefore, if you want to display a doc you have to use the Microsoft automation.
here a sample:Kind regards,Code: Select all
Dim oWord As New Microsoft.Office.Interop.Word.Application oWord.Documents.Open("c:\mydoc.doc", False, True, False) oWord.Documents(1).Activate() Clipboard.Clear() oWord.Documents(1).Select() oWord.Selection.CopyAsPicture() oWord.Application.Documents(1).Close(False) oWord.Quit() Call GdViewer1.DisplayFromClipboard()
Loïc
- kketterman
- Posts: 32
- Joined: Tue Apr 21, 2009 6:55 pm
Re: How can we display Word/Text Document
I used this code in my project and it seems to only get some of the Word document.
Other times I get invalid clipboard operation messages.
Other times I get invalid clipboard operation messages.
Re: How can we display Word/Text Document
Another way is to create a pdf from word
here's c# code (tested with word 2007 / 2010 beta)
this code needs the try/catch/finally stuff ... but works
Oli
here's c# code (tested with word 2007 / 2010 beta)
Code: Select all
using Outlook = Microsoft.Office.Interop.Outlook;
using WinWord = Microsoft.Office.Interop.Word;
...
object file = Listtodo.SelectedItem.ToString();
object nullobj = System.Reflection.Missing.Value;
object doNotSaveChanges = WinWord.WdSaveOptions.wdDoNotSaveChanges;
string paramExportFilePath = @"C:\Test.pdf";
WinWord.WdExportFormat paramExportFormat = WinWord.WdExportFormat.wdExportFormatPDF;
bool paramOpenAfterExport = false;
WinWord.WdExportOptimizeFor paramExportOptimizeFor = WinWord.WdExportOptimizeFor.wdExportOptimizeForPrint;
WinWord.WdExportRange paramExportRange = WinWord.WdExportRange.wdExportAllDocument;
int paramStartPage = 0;
int paramEndPage = 0;
WinWord.WdExportItem paramExportItem = WinWord.WdExportItem.wdExportDocumentContent;
bool paramIncludeDocProps = true;
bool paramKeepIRM = true;
WinWord.WdExportCreateBookmarks paramCreateBookmarks = WinWord.WdExportCreateBookmarks.wdExportCreateWordBookmarks;
bool paramDocStructureTags = true;
bool paramBitmapMissingFonts = true;
bool paramUseISO19005_1 = false;
WinWord._Application myWinWord = new WinWord.Application();
WinWord._Document mydoc = myWinWord.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj);
mydoc.ExportAsFixedFormat(paramExportFilePath,
paramExportFormat,
paramOpenAfterExport,
paramExportOptimizeFor,
paramExportRange,
paramStartPage,
paramEndPage,
paramExportItem,
paramIncludeDocProps,
paramKeepIRM,
paramCreateBookmarks,
paramDocStructureTags,
paramBitmapMissingFonts,
paramUseISO19005_1,
ref nullobj);
mydoc.Close(ref doNotSaveChanges, ref nullobj, ref nullobj);
myWinWord.Quit(ref doNotSaveChanges, ref nullobj, ref nullobj);
gdViewer1.DisplayFromFile(paramExportFilePath);
Oli
Re: How can we display Word/Text Document
Oli thank you very much !
I think your code is the best option !
Kind regards,
Loïc
I think your code is the best option !
Kind regards,
Loïc
Who is online
Users browsing this forum: No registered users and 1 guest