Changing text color not working

The PDF Creator .NET Library enables you to create secure PDF documents on the fly and to view, print and process existing PDF documents. If you have any questions about PDF Creator .Net, please post them here.
Post Reply
Klamartin
Posts: 1
Joined: Wed Jul 17 2013

Changing text color not working

Post by Klamartin »

I am working with OCR formated PDF files created by a different process than Amyuni. They open and display propery in other systems, includeing Adobe. I want to search for, and change the text color of, certain text objects. I can find the text objects, and in the code, change their atribute color and text value, but the screen display in Pdfcreater console control does not update. All I can get to change in the console control is the bachgroung color attribute, which ends up covering the text I want to highlight to the user. (I can do this using reachtext and PdfCreator.Document.SetAttributeForMultipleSelection("BackColor", "0x00FFFF", True))

Dim stream As New FileStream(gsfilename, FileMode.Open, FileAccess.ReadWrite)
PdfCreator.Visible = True
PdfCreator.Document.Open(stream, "")
PdfCreator.Document.MinimumGap = 1
PdfCreator.Document.DoCommandTool(Amyuni.PDFCreator.IacCommandTool.acCommandToolDesignMode)
PdfCreator.Document.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateDesign
Dim intPageCount As Integer = PdfCreator.Document.PageCount
'Loop through all the Pages
For counter As Integer = 1 To intPageCount
Try
Dim arList As ArrayList = DirectCast(PdfCreator.Document.GetPage(counter).Attribute("Objects").Value, ArrayList)
For Each obj As Amyuni.PDFCreator.IacObject In arList
'Check if it an text object
If obj.Attribute("ObjectType").Value.ToString() = "5" Then
Dim Text As IacAttribute = obj.Attribute("Text")
Text.Value = "new text"
obj.Attribute("TextColor").Value = 255
obj.Redraw()
obj.Refresh()
End If
Next
Catch ev As Exception
MessageBox.Show(ev.Message)
End Try
PdfCreator.Document.DrawCurrentPage(counter, True)
Next
PdfCreator.Document.Refresh()
Jose
Amyuni Team
Posts: 553
Joined: Tue Oct 01 2002
Contact:

Re: Changing text color not working

Post by Jose »

Hello,

We ran a quick test using the code snippet (based on your code) below and this code changed the text value and text colour of the object. Can you please test this on your end?

Dim gsfilename As String = "c:\\temp\\pdf1.pdf"

Dim stream As New FileStream(gsfilename, FileMode.Open, FileAccess.ReadWrite)
pdfCreator.Document.Open(stream, "")

pdfCreator.Document.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateDesign

Dim intPageCount As Integer = pdfCreator.Document.PageCount

'Loop through all the Pages
For counter As Integer = 1 To intPageCount
Try
'Get ArrayList of objects on page
Dim arList As ArrayList = DirectCast(pdfCreator.Document.GetPage(1).AttributeByName("Objects").Value, ArrayList)

For Each obj As IacObject In arList
'you can access all properties of each object
'MessageBox.Show ( obj.Attribute("ObjectType").Value.ToString() );

Dim attr As IacAttribute = obj.Attribute("ObjectType")

'check if field object
If CInt(attr.Value) = CInt(IacObjectType.acObjectTypeText) Then

'get value in field object
Dim Text As IacAttribute = obj.Attribute("Text")
Text.Value = "new text"
obj.Attribute("TextColor").Value = 0 'Black

End If
Next

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Next
pdfCreator.Document.Refresh()
pdfCreator.Document.ReportState = Amyuni.PDFCreator.IacReportState.acReportStateRun
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite
Post Reply