I want to replace the OCR text with my own on a document. I dont see this in the worklfow toolbox. Has anyone accomplished this. I want to query another database on the server and write the results of that query into the document text.
Question
Question
Replies
To write to the documents text layer, you will need to use an SDK Script activity.
Collect the desired new text to add to page 1's text layer into a token named "TextToAdd". Then add a SDK Script activity and set its default entry to be the entry you want to add the text to. Then in the code, use the following:
' Get the new text to add to the first page
Dim TextToWrite As String = GetTokenValue("TextToAdd")
' Create object to hold existing text on first page
Dim DocText As String = Nothing
' Only process if entry is a Document
If BoundEntryInfo.EntryType = EntryType.Document Then
Try
'Get DocumentInfo object from EntryInfo
Using Doc As DocumentInfo = TryCast(BoundEntryInfo, DocumentInfo)
' Only process if the document has at least 1 page
If Doc.PageCount > 0 Then
' Get PageInfo for the first page
Dim PI As PageInfo = Doc.GetPageInfo(1)
' Read page text into streamreader
Using sr as System.IO.StreamReader = PI.ReadTextPagePart()
' Only process if the streamreader has data
If sr.Peek >= 0 Then
' Get the existing page text
DocText = sr.ReadToEnd()
End If
End Using
' check if existing text is present
If Not String.IsNullOrEmpty(DocText) Then
' add new text to the end of existing text
TextToWrite = DocText & Environment.NewLine & TextToWrite
End If
' Write text to first page
PI.WriteTextPagePart(TextToWrite)
End If
End Using
Catch ex As Exception
' Report errror back to Workflow
WorkflowApi.TrackError(ex.Message)
End Try
End If
This will add your desired text to the end of the existing text layer for the first page of the document that it is run on.
Worked like a charm Bert. You saved me a ton of time.
Is there a way to save this off to reuse. I can see needing this a lot.
Bert, this sounds like something I need for a project I'm currently working on, but I can't get the script to be valid. I am retrieving the text of a file in the repository and assigning it to a token in my workflow. I then search the repository for another entry that I want to replace the text of with the first entry. Then in my SDK script I have pasted your code, but it won't let me save and doesn't give me any errors. Any idea what I'm missing?