使用 Basic 将图像插入 Open Office Draw 文档

Inset an image into an Open Office Draw document using Basic

我想使用 Basic 将图像插入到 LibreOffice Draw 文档中。我创建了一个 Draw 文档,然后向该文档添加了一个页面,然后重命名了这些页面。我想在 Page1 中插入一个图像,然后将另一个图像添加到 Page2。我根据需要创建了页面,但无法将图像插入页面。下面是我的代码

    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

我一直在阅读 Andrew Pitonyak 的书,但无法找到我正在尝试做的事情的来源。 FillStyle 破解代码。

我已经让程序运行了。

我创建了两个 pdf 并将它们保存在一个文件夹中。我 运行 宏 MergePDF 和子打开 Draw,创建两个页面,将 pdf 复制到每个页面上。该文档已准备好导出到 PDF,这是我的下一个任务。必须关闭绘制才能工作。

    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

非常基本但有效。感谢其他论坛成员一路上的指点。