2011-07-19 4 views
0

すべてiTextSharpはどのように、書かれたテキストを隠して書き込み

私はiTextSharpライブラリを使用して、既存のPDFファイル内のテキスト、いくつかの回私は、PDFのページにテキストを書く位置にある任意の画像の場合を挿入していたときに、それは続けるテキストを隠します既存のイメージにテキストを書き込む。

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 

既存のイメージに上記の文章を書くためのいずれかの助け...

おかげで、 Senthilさんラインで

答えて

0

objContentByte.AddTemplate(objPage, 0, -1.0F, 1.0F, 0, 0, objPdfReader.GetPageSizeWithRotation(i).Height) 

objContentByte.AddTemplate(objPage, 1.0F, 0, 0, 1.0F, 0, 0) 

あなたはPDFWriterのからDirectContentUnderへの書き込みを試みることができます:返信用

objContentByte = objPdfWriter.DirectContent 
    Dim objContentByteUnder as PdfContentByte = objPdfWriter.DirectContentUnder 
      ..... 
      objContentByte.BeginText() 
      ..... 
      objContentByteUnder.AddTemplate(objPage, 0, -1.0F, 1.0F, 0, 0, objPdfReader.GetPageSizeWithRotation(i).Height) 
      objContentByteUnder.AddTemplate(objPage, 1.0F, 0, 0, 1.0F, 0, 0) 
+0

こんにちはおかげで、私はobjContentByte = objPdfWriter.DirectContentUnderと試みたが、それはまだ画像が現れた場合に、テキストを隠し続けます。 – Senthil

+0

objPdfWriter.DirectContentにテキストを、objPdfWriter.DirectContentUnderに画像を書き込む必要があります。 – Peter

+0

こんにちは、お返事いただきありがとうございます。objContentByte.BeginText()を置き換えて、動作しています。 ..... objContentByte.EndText() 'End If'ステートメントの次のコード.. – Senthil

関連する問題