none
By using Microsoft.Office.Interop.OneNote.Application() We are required to extract the printout image (all the inserted prinout images) in iny image format(jpg,png,bmp) just like there is an option when right click and "save as". Is it possible? Please RRS feed

  • Question

  • By using Microsoft.Office.Interop.OneNote.Application() We are required to extract the printout image (all the inserted prinout images) in iny image format(jpg,png,bmp) just like there is an option when right click and "save as". Is it possible? 

    Or

     in C# how to achieve this task.

    

    Wednesday, April 2, 2014 5:45 PM

Answers

  • Hi,

    According to your description, you want to save all images from OneNote. Yes, it is possible. You can follow steps below to achieve the goal:
    1. Open a section or section group via OpenHierarchy
    2. Gets the notebook node hierarchy structure via GetHierarchy
    3. After get the hierarchy structure you can loop all pages by analysing xml
    4. Loop all images on one page (like steps 3)
    5. Save the specific images
    Here is a simple sample to save the specific image from OneNote:

    public void Main()
            {
                Note.Application noteApp = new Note.Application();
                         
                String strID = "",strXML="",base64ImageData="";
                noteApp.OpenHierarchy(@"C:\Users\UserName\Desktop\CopyImages.one",System.String.Empty, out strID, Note.CreateFileType.cftSection);
    
                noteApp.GetBinaryPageContent("{B5C13F73-FA2F-46BE-B3ED-A4F44BFEBBED}{1}{E19550520808587255244120104970444674282075421}", "{1CA338C5-2B10-41DD-9468-BFF471E11D51}{32}{B0}", out base64ImageData);
                byte[] bytes = Convert.FromBase64String(base64ImageData);
    
                Image image;
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    image = Image.FromStream(ms);
                    using (Bitmap bm2 = new Bitmap(image))
                    {
                        bm2.Save(@"C:\Users\UserName\Desktop\OneNotePic1.png",System.Drawing.Imaging.ImageFormat.Png);
                    }
                }
               
            }
    

    Note: when you automate the OneNote, you need to set the property Embed Interop Types of Microsoft.Office.Interop.OneNote.dll to false.

    In addition, you can get more detail from link below about OneNote object:
    Application interface (OneNote 2013)

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 3, 2014 7:32 AM
    Moderator

All replies

  • Hi,

    According to your description, you want to save all images from OneNote. Yes, it is possible. You can follow steps below to achieve the goal:
    1. Open a section or section group via OpenHierarchy
    2. Gets the notebook node hierarchy structure via GetHierarchy
    3. After get the hierarchy structure you can loop all pages by analysing xml
    4. Loop all images on one page (like steps 3)
    5. Save the specific images
    Here is a simple sample to save the specific image from OneNote:

    public void Main()
            {
                Note.Application noteApp = new Note.Application();
                         
                String strID = "",strXML="",base64ImageData="";
                noteApp.OpenHierarchy(@"C:\Users\UserName\Desktop\CopyImages.one",System.String.Empty, out strID, Note.CreateFileType.cftSection);
    
                noteApp.GetBinaryPageContent("{B5C13F73-FA2F-46BE-B3ED-A4F44BFEBBED}{1}{E19550520808587255244120104970444674282075421}", "{1CA338C5-2B10-41DD-9468-BFF471E11D51}{32}{B0}", out base64ImageData);
                byte[] bytes = Convert.FromBase64String(base64ImageData);
    
                Image image;
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    image = Image.FromStream(ms);
                    using (Bitmap bm2 = new Bitmap(image))
                    {
                        bm2.Save(@"C:\Users\UserName\Desktop\OneNotePic1.png",System.Drawing.Imaging.ImageFormat.Png);
                    }
                }
               
            }
    

    Note: when you automate the OneNote, you need to set the property Embed Interop Types of Microsoft.Office.Interop.OneNote.dll to false.

    In addition, you can get more detail from link below about OneNote object:
    Application interface (OneNote 2013)

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 3, 2014 7:32 AM
    Moderator
  • Hi Fei Xue

    Thanks It worked.

    Now I am facing some another issue as I want to create a page in a section of a notebook in OneNote. For this I am writing the following line

    onenoteApp.CreateNewPage(sectionId, out pageId, NewPageStyle.npsBlankPageWithTitle);

    At this line an exception is occured like

    Exception from HRESULT: 0x8004200B

    Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x8004200B

    Which means the 'section is readonly' while I can edit anything in Application manually. I tried so many time but no success. Please help me out to get it resolved. Thanks

     

    Wednesday, April 9, 2014 5:00 PM
  • Hi,

    Since the original issue was fixed, I suggest you reopening a new thread. It will involve more comuunities to the issue, and you will get more quick response.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, April 14, 2014 8:51 AM
    Moderator