I changed it to use a stream and it works as far as replacing all of my
images with no error on the pdf. However, the imaging I am putting in place
shows with a black background. Not sure why or how to fix that. Any
suggestions?
Do While (i <= page_count)
Dim pg As PdfDictionary = reader.GetPageN(i)
Dim res As PdfDictionary =
CType(PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES)), PdfDictionary)
Dim xobj As PdfDictionary =
CType(PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT)), PdfDictionary)
If (Not (xobj) Is Nothing) Then
For Each name As PdfName In xobj.Keys
Dim obj As PdfObject = xobj.Get(name)
If obj.IsIndirect Then
Dim tg As PdfDictionary =
CType(PdfReader.GetPdfObject(obj), PdfDictionary)
Dim type As PdfName =
CType(PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE)), PdfName)
If PdfName.IMAGE.Equals(type) Then
If tg.GetAsNumber(pdf.PdfName.WIDTH).IntValue =
61 Then
Dim stream As PRStream =
CType(xobj.GetAsStream(name), PRStream)
Dim maskImage As Image = ImageSign.ImageMask
Dim image As PdfImage = New
PdfImage(maskImage, "", Nothing)
ReplaceStream(stream, image)
Exit For
End If
End If
End If
Next
End If
i = (i + 1)
Loop
Public Shared Sub ReplaceStream(ByVal oldimage As PRStream, ByVal
newstream As PdfStream)
oldimage.Clear()
Dim ms As MemoryStream = New MemoryStream
newstream.WriteContent(ms)
oldimage.SetData(ms.ToArray(), False)
For Each keyValuePair As KeyValuePair(Of PdfName, PdfObject) In
newstream
oldimage.Put(keyValuePair.Key, newstream.Get(keyValuePair.Key))
Next
End Sub
--
View this message in context:
http://itext.2136553.n4.nabble.com/Replace-images-in-pdf-tp4660966p4660972.html
Sent from the iText mailing list archive at Nabble.com.
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php