Resize images in a doc file

NetMaster

New member
Joined
Feb 11, 2011
Messages
3
Programming Experience
1-3
Hello,

I would like to resize all the images in a doc file. The images are all small and I need to make them as big as the A4 paper. Thus, one image per page.

Any help how to get me started? I have no clue.

See attached pictures to understand better what I would like to do

Thank you in advance for your help.

A.
 

Attachments

  • A.png
    A.png
    311.1 KB · Views: 30
  • B(page1).png
    B(page1).png
    893.6 KB · Views: 26
  • B(page2).png
    B(page2).png
    789.1 KB · Views: 25
  • B(Page3).png
    B(Page3).png
    713.7 KB · Views: 26

Estuardo

Well-known member
Joined
Nov 27, 2004
Messages
45
Location
Portugal
Programming Experience
5-10
G'd evening,
I don't know about OpenOffice, but you may want to find documentation about Automation for that specific product.
G'd luck
 

NetMaster

New member
Joined
Feb 11, 2011
Messages
3
Programming Experience
1-3
G'd evening,
I don't know about OpenOffice, but you may want to find documentation about Automation for that specific product.
G'd luck

Hello,

Finally an answer, thank you. I will use Microsoft Office and not open office. I have tried to look for some tutorial online but could not find anything :(
 

Estuardo

Well-known member
Joined
Nov 27, 2004
Messages
45
Location
Portugal
Programming Experience
5-10
Hello my friend,
I'm glad you get to start with well known product, so more people can help. About tutorials... Automation is a huge subject, most of the times you'll find pieces of code but no complete tutorials. Being said that, you may want to start with Google then MS and a shortcut for the part you're interested Shape Interface and MSDN Search.
About the code:
  • Well as you can see are a few lines just for you to have a grasp of what you'll need to do. It does what you need IF and a big "IF" all your pictures are in "Square" layout mode, it may work with others except "InLine" mode. The reason to choose this mode is to avoid calculate each Picture's size and resize accordingly. In square mode they "push" each other to next available empty space
  • The size i'd set, is for my current page size A4, you'll need to set yours.
  • Even when in my pc it performs fast, to improve a little bit i'd set in both (Application and Document) the visible property to false.
  • You can remove the 4 relative properties, i used them to not let MS Word to make any assumption when positioning, but it seems they're not needed.
  • The Anchor property is important. If you don't set that property to false your pictures may overlap.
  • The lockAspectToRatio was a test to see if pictures loose or not quality. In my case it made no difference.
  • In order to make any change you must keep the "Select" method before you begin to manipulate the object. Other wise it will crash MS Word and you'll need to kill the process.
  • Finally, avoid the temptation to turn the Option Strict Off.

That's it. I hope it help you.
Option Strict On
Imports Microsoft.Office.Interop

Public Class frmMain

    Private Sub btnOpen_Click(sender As System.Object, e As System.EventArgs) Handles btnOpen.Click
        Dim dlg As New OpenFileDialog
        With dlg
            .Filter = "MS Word Files|*.docx|*.adp|*.accdb"
            .InitialDirectory = Me.txtFilePath.Text
            .Title = "Open File"
            .Multiselect = False
            .RestoreDirectory = True
            If dlg.ShowDialog = DialogResult.OK Then
                Me.txtFilePath.Text = dlg.FileName
                Call LoadWDocx()
            Else
                '  Return String.Empty
            End If
        End With
    End Sub

    Private Sub LoadWDocx()
        Dim oWord As Word._Application
        Dim oDoc As Word._Document
        Dim oShape As Word.Shape

        oWord = New Word.Application()
        oWord.Visible = False
        oDoc = oWord.Documents.Open(CType(Me.txtFilePath.Text, Object), Visible:=False)

        Try
            For Each oShape In oDoc.Shapes
                With oShape
                    .Select()
                    .Width = oDoc.Application.CentimetersToPoints(20.21)
                    .Height = oDoc.Application.CentimetersToPoints(28.02)
                    .RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage
                    .RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage
                    .RelativeHorizontalSize = Word.WdRelativeHorizontalSize.wdRelativeHorizontalSizePage
                    .RelativeVerticalSize = Word.WdRelativeVerticalSize.wdRelativeVerticalSizePage
                    .Left = oDoc.Application.CentimetersToPoints(0)
                    .Top = oDoc.Application.CentimetersToPoints(0)
                    .LockAnchor = False
                    .LayoutInCell = False
                    .LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoCTrue
                    .Rotation = 0.0#
                End With
               
            Next
            oDoc.Save()
            oDoc.Close()
            oWord.Quit()
            MsgBox("done!")
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            oDoc = Nothing
            oWord = Nothing
        End Try

    End Sub

  
End Class



G'd luck
 
Last edited:
Top Bottom