How can we display Word/Text Document

Example requests & Code samples for GdPicture Toolkits.
Post Reply
Hasan
Posts: 2
Joined: Wed Jul 08, 2009 7:15 am

How can we display Word/Text Document

Post by Hasan » Wed Jul 08, 2009 7:26 am

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

User avatar
Loïc
Site Admin
Posts: 5603
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: How can we display Word/Text Document

Post by Loïc » Thu Jul 09, 2009 2:41 pm

Hi,

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()
Kind regards,

Loïc

Hasan
Posts: 2
Joined: Wed Jul 08, 2009 7:15 am

Re: How can we display Word/Text Document

Post by Hasan » Fri Jul 10, 2009 12:04 pm

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:

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()
Kind regards,

Loïc

User avatar
kketterman
Posts: 32
Joined: Tue Apr 21, 2009 6:55 pm

Re: How can we display Word/Text Document

Post by kketterman » Wed Jul 22, 2009 7:59 pm

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.

boXer14
Posts: 1
Joined: Tue Mar 09, 2010 12:52 pm

Re: How can we display Word/Text Document

Post by boXer14 » Fri Apr 23, 2010 10:26 am

Another way is to create a pdf from word

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);

this code needs the try/catch/finally stuff ... but works

Oli

User avatar
Loïc
Site Admin
Posts: 5603
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: How can we display Word/Text Document

Post by Loïc » Fri Apr 23, 2010 11:13 am

Oli thank you very much !

I think your code is the best option !

Kind regards,

Loïc

william19
Posts: 1
Joined: Tue Nov 27, 2018 8:55 am

Re: How can we display Word/Text Document

Post by william19 » Tue Nov 27, 2018 9:09 am

Hello Guys,

So for what reason would you ever need to shroud message in a Word archive? All things considered, one reason would be on the off chance that you needed to print out two unique adaptations of a similar record, however, would not like to make two separate documents. For this situation, you could shroud some content, print the record and after that print the archive once more, yet print concealed content in the printing choices exchange.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests