[Solved] [DRAW] searching image through pdf
Posted: Fri Jun 08, 2018 1:25 pm
Hello,
is it possible to do macro in DRAW that search images through PDF?
or maybe i the way to edit this macro written by Lupp in this forum?
PDF has many pages, on several pages is that image on rest is not. If on page is that image I'm searching for I want to insert new image. I know that on every page is only ONE image(that I'm searching for), I know the name of this image and position too if it could help. Is it possible?
Thanks!
is it possible to do macro in DRAW that search images through PDF?
or maybe i the way to edit this macro written by Lupp in this forum?
Code: Select all
REM ***** BASIC *****
Function listMatchingPages(Optional pDoc as Object, Optional pSearch As String, _
Optional pCtrl As Long) As String REM pCtrl=1 is CaseSensitive
listMatchingPages = "fail"
If IsMissing(pDoc) Then pDoc = ThisComponent
If IsMissing(pSearch) Then pSearch = "ex"
If IsMissing(pCtrl) Then pCtrl = 0
n = pDoc.DrawPages.Count
REM === From an unknown source. ===
REM I do not understand the working of this search procedure.
REM Drawings don't work with the XSearchable interface.
REM The UI and the dispatcher know a way to search the shapes of a drawing for text nonetheless.
REM The options are restricted, however.
dim ccF as object
dim dispatcher as object
ccF = pDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.SearchString"
args1(0).Value = pSearch
REM === End ===
h = ""
For j = 1 To n
On Error Goto nextj
dispatcher.executeDispatch(ccF, ".uno:ExecuteSearch", "", 0, args1())
k = 0
f = pDoc.CurrentSelection
If IsNull(f) Then Goto nextj
If (pCtrl=0) OR (f.String=pSearch) Then
k = f.Text.Parent.Number
h = h & k & ","
End If
nextj:
Next j
r = ""
For j = 1 To n
If Instr("," & h, "," & j & ",")>0 Then
r = r & j & ","
End If
Next j
If Len(r)>0 Then r = Left(r, Len(r) - 1)
listMatchingPages = r
End Function
Sub insertImage(pDoc as object, pPage As Long)
thePage = pDoc.DrawPages(pPage-1)
pDoc.CurrentController.Select(thePage)
Print "Insert here!"
End Sub
Sub doIt()
list = listMatchingPages(ThisComponent, "EX", 1)
Print list
splitList = Split(list, ",")
For j = 1 To Ubound(splitList)+1
insertImage(ThisComponent, CInt(splitList(j-1))
Next j
End Sub
Thanks!