Everything
I insert text into an existing PDF file using iTextSharp Library several times, if any image is at the position where I write text on the PDF page, it hides the written text, like writing text to an existing image.
Dim iNumOfPages As Integer = 0, iFile As Integer = 0, iRotation As Integer Dim objPdfReader As PdfReader Dim objDoc As Document = Nothing Dim objPdfWriter As PdfWriter = Nothing Dim objContentByte As PdfContentByte Dim objPage As PdfImportedPage Dim objFileStream As FileStream = Nothing objFileStream = New FileStream(sDestFile, FileMode.Create) objPdfReader = New PdfReader(slSourceFiles.Item(iFile)) iNumOfPages = objPdfReader.NumberOfPages objDoc = New Document(objPdfReader.GetPageSizeWithRotation(1)) objPdfWriter = PdfWriter.GetInstance(objDoc, objFileStream) objDoc.Open() objContentByte = objPdfWriter.DirectContent Dim objTempCB As PdfContentByte = objPdfWriter.DirectContent objPDFStamper = New PdfStamper(objPdfReader, objFileStream) While i < iNumOfPages i = i + 1 objDoc.SetPageSize(objPdfReader.GetPageSizeWithRotation(i)) objDoc.NewPage() objPage = objPdfWriter.GetImportedPage(objPdfReader, i) iRotation = objPdfReader.GetPageRotation(i) Dim bf As BaseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.EMBEDDED) Dim bc As BaseColor = BaseColor.BLUE objContentByte.BeginText() objContentByte.SetTextMatrix(400, 765) 'objContentByte.SetTextMatrix(400, 765) objContentByte.SetFontAndSize(bf, 9) objContentByte.SetColorFill(bc) objContentByte.ShowText("Mytext................") objContentByte.EndText() If (iRotation = 90 Or iRotation = 270) Then objContentByte.AddTemplate(objPage, 0, -1.0F, 1.0F, 0, 0, objPdfReader.GetPageSizeWithRotation(i).Height) Else objContentByte.AddTemplate(objPage, 1.0F, 0, 0, 1.0F, 0, 0) End If End While
Any help for writing the text above for existing images ...
Thanks, Senthil
source share