0

I am wanting to insert an image into a LibreOffice Draw document using Basic. I create a Draw document and then I add a page to the document and then rename the pages. I want ti insert an image into Page1 and then add another Image to Page2. I have the pages created as I want but I am unable to insert the image into the page. Below is my code

    sub InsertImage()
    Dim Doc As Object
    Dim Page1 as Object
    Dim Page2 as Object

    Dim DocPath1 as String
        DocPath1 = ConvertToURL("MyImage1.jpg")
    Dim DocPath2 as String
        DocPath2 = ConvertToURL("MyImage2.jpg")

    Dim noArgs() 'An empty array for the arguments
    Dim sURL As String

        sURL = "private:factory/sdraw"

        Doc = StarDesktop.LoadComponentFromUrl(sURL, "_blank", 0, noArgs())
        Page1 = Doc.DrawPages(0)
        Page1.Name = "Image1"

        Page2 = Doc.Drawpages.insertNewByIndex(2)
        Page2.Name = "Image2"

       '    Page1.FillStyle = com.sun.star.drawing.FillStyle.BITMAP
       '    Page1.FillBitmapURL = DocPath1
        
    End sub

I have been reading Andrew Pitonyak's book but unable to find a source for what I am trying to do. FillStyle breaks the code.

hemis
  • 45
  • 1
  • 2
  • 11

1 Answers1

0

I have got the program to work.

I created two pdf's and saved them in a folder. I run the macro MergePDF and the sub opens Draw, creates the two pages, copes the pdf's onto each page. The document is ready to ExportToPDF which is my next task. Draw must be closed for this to work.

    sub MergePDF()

    Dim Doc As Object 'This workbook

    Dim NewWorkBookURL As String

    NewWorkBookURL = "private:factory/sdraw"
 
    Dim noArgs() 'An empty array for the arguments

    Dim Point As New com.sun.star.awt.Point
    Dim Size As New com.sun.star.awt.Size

    Point.x = 0
    Point.y = 0
    'A4
    Size.Width = 21000
    Size.Height = 29700

    Dim Page1 As Object 'Excel sheet
    Dim Page2 As Object 'AutoCAD sheet

    Dim Image1 As Object 'PDF1
    Dim Image2 As Object 'PDF2

    Dim DocPath1 As String
    Dim DocPath2 As String
    Dim DocPath3 As String

    DocPath1 = ConvertToURL("C:\Users\pdf1.pdf")
    DocPath2 = ConvertToURL("C:\Users\\pdf2.pdf")

    Doc = StarDesktop.LoadComponentFromUrl(NewWorkBookURL, "_blank", 0, noArgs())

    Page1 = Doc.DrawPages(0)
    Page1.Name = "PDF1"

    Page2 = Doc.Drawpages.insertNewByIndex(2)
    Page2.Name = "PDF2"

   'Page 1  
    Image1 = Doc.createInstance("com.sun.star.drawing.GraphicObjectShape")
    Image1.GraphicURL = DocPath1
    
    Image1.Size = Size
    Image1.Position = Point
    Page1.add(Image1)

    'Page 2 
    Image2 = Doc.createInstance("com.sun.star.drawing.GraphicObjectShape")
    Image2.GraphicURL = DocPath2
    
    Image2.Size = Size
    Image2.Position = Point
    Page2.add(Image2)

    'ExportToPDF

    'To Do

    msgbox "Done"

    End sub

Very basic but works. Thanks for the other forum members for the advice on the way.

hemis
  • 45
  • 1
  • 2
  • 11