Ok, I mostly have it, just where it says see detail m-5.1 for example is a little off, but I can live with it.
Sub Open() Handles Open
Dim pdf As New MyDynapdfMBS
pdf.SetLicenseKey "Pro" // For this example you can use a Pro or Enterprise License
Dim outfile As FolderItem=SpecialFolder.Temporary.Child("Temp" + UniqueID + ".pdf")
call pdf.CreateNewPDF outfile
Dim filepath As FolderItem=SpecialFolder.Desktop.Child("MECHANICAL.pdf")
// We import the contents only without conversion of pages to templates
Call pdf.SetImportFlags(BitwiseOr(pdf.kifImportAll, pdf.kifImportAsPage))
if pdf.OpenImportFile(filePath, pdf.kptOpen, "")<>0 then
MsgBox "Input file """+ filePath.name+""" not found!"
quit
end if
Call pdf.ImportPDFFile(1, 1.0, 1.0)
call pdf.CloseImportFile
Dim editor As New MyDynaPDFEditTextMBS(pdf)
editor.pdf = pdf
//bookmarks & pagefound
Dim found As Integer
Dim pageCount As Integer = pdf.GetPageCount
Var PageNumbers() As String
Var BookMarkCount As Integer = pdf.GetBookmarkCount - 1
For i As Integer = 0 To BookMarkCount
Var B As DynaPDFBookmarkMBS = pdf.GetBookmark(i)
Var bname As String = b.Title
System.DebugLog(bname)
Var parts() As String = bname.Split(" ")
If PageNumbers.IndexOf(parts(0).Trim) = -1 Then
PageNumbers.Add(parts(0).Trim)
End If
Next i
For Each PageNumber As String In PageNumbers
System.DebugLog(PageNumber)
ReferenceSheetNumber = PageNumbers.IndexOf(PageNumber) + 1
For i As Integer = 1 To pageCount
If i = ReferenceSheetNumber Then
Continue For i
End If
CurrentSheetNumber = i
// DynaPDF error messages are already handled in the error callback function!
If pdf.EditPage(i) Then
// disable font errors while editing. The class handles them
pdf.IgnoreFontWarnings = True
'The function FindPattern() searches for a string.
found = editor.FindPattern(PageNumber)
'ReplacePattern() replaces the text with a new one or deletes it if the new string
'is an empty string. The new text is written in red color so that you can better
'find it. Take a look into the event PrepareWrite if you want to
'write the text in the orignal color...
editor.ReplacePattern(PageNumber)
pdf.IgnoreFontWarnings = False
Call pdf.EndPage
End If
Next
Next PageNumber
Call pdf.CloseFile
outFile.Delete
outfile = SpecialFolder.Desktop.Child(filepath.NativePath.Replace(".pdf", UniqueID) + ".pdf")
pdf = Nil
pdf = New MyDynapdfMBS
pdf.SetLicenseKey "Pro" // For this example you can use a Pro or Enterprise License
Call pdf.CreateNewPDF outfile
//filepath = SpecialFolder.Desktop.Child("MECHANICAL.pdf")
// We import the contents only without conversion of pages to templates
Call pdf.SetImportFlags(BitwiseOr(pdf.kifImportAll, pdf.kifImportAsPage))
If pdf.OpenImportFile(filePath, pdf.kptOpen, "")<>0 Then
MsgBox "Input file """+ filePath.name+""" not found!"
Quit
End If
Call pdf.ImportPDFFile(1, 1.0, 1.0)
Call pdf.CloseImportFile
For Each dic As Dictionary In LinksToBeAdded
pdf.IgnoreFontWarnings = True
Var x As Double = dic.Value("x")
Var y As Double = dic.Value("y")
Var w As Double = dic.Value("w")
Var h As Double = dic.Value("h")
Var RefSheet As Integer = dic.Value("RefSheet")
Var txt As String = dic.Value("Text")
Var page As Integer = dic.Value("page")
If pdf.EditPage(page) Then
Call pdf.HighlightAnnot(pdf.katHighlight, x, y, w, h, pdf.RGB(205, 0, 205), "", "", "")
Call pdf.PageLink(x, y, w, h, RefSheet)
Call pdf.EndPage
End If
pdf.IgnoreFontWarnings = False
Next dic
Call pdf.CloseFile
outfile.Open
Quit
End Sub
Function PrepareWrite(M as DynaPDFMatrixMBS, text as string, FillCS as Integer, FillColor as UInt32, StrokeCS as Integer, StrokeColor as UInt32, FontSize as double, x as double, y as double, w as double, h as double, font as DynaPDFFontMBS) Handles PrepareWrite as boolean
Transform(m, x, y)
//use text heights and widths
w = FontSize/10
h = 30
y = y - 20
x = x - (w/2)
Call pdf.HighlightAnnot(pdf.katHighlight, x, y, w, h, pdf.RGB(205, 0, 205), "", "", "")
Call pdf.PageLink(x, y, w, h, ReferenceSheetNumber)
Var Dic As New Dictionary
dic.Value("x") = x
dic.Value("y") = y
dic.Value("w") = w
dic.Value("h") = h
dic.Value("RefSheet") = ReferenceSheetNumber
dic.Value("text") = Text
dic.Value("page") = CurrentSheetNumber
LinksToBeAdded.Add(dic)
System.DebugLog "found: "+Str(x)+"/"+Str(y)+" "+Str(w)+" "+Str(h)
Return False
End Function
Public Function RemoveSpecialCharacters(extends txt as String, AllowSpaces as Boolean = False) As String
Var Results As String
for x as integer = 1 to txt.Len
Var tst as integer = asc(txt.Mid(x,1))
Var addChar as Boolean = False
if tst > 47 and tst < 58 then
addChar = True
elseif tst > 64 and tst < 91 then
addChar = True
elseif tst > 96 and tst < 122 then
addChar = True
elseif tst = 32 then
addChar = AllowSpaces
end if
if addChar then
if Results = "" then
Results = txt.Mid(x, 1)
else
Results = Results + txt.Mid(x, 1)
end if
end if
next x
Return Results
End Function
Public Function UniqueID() As String
Var Results As String
Results = UUIDMBS.randomUUID.ValueFormattedString.RemoveSpecialCharacters
Return Results
End Function
Public Sub Transform(m as DynaPDFMatrixMBS, byref x as Double, byref y as double)
Dim tx As Double = x
Dim tx2 As Double = y
x = tx * M.a + x * M.c + M.x
y = tx2 * M.b + y * M.d + M.y
End Sub