在pdf中添加的文本未使用itextsharp在浏览器中显示

时间:2016-05-11 09:08:09

标签: c# pdf itextsharp

我在pdf中添加了文字。但添加的文本不会显示在浏览器中。

  using (FileStream fs = new FileStream(highLightFile, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
        {
            using (PdfStamper stamper = new PdfStamper(reader, fs))
            {
                for (int x = 1; x < reader.NumberOfPages; x++)
                {
                    cb = stamper.GetUnderContent(x);
                    myLocationTextExtractionStrategy strategy = new myLocationTextExtractionStrategy();
                    strategy.UndercontentCharacterSpacing = cb.CharacterSpacing;
                    strategy.UndercontentHorizontalScaling = cb.HorizontalScaling;
                    string currentText = PdfTextExtractor.GetTextFromPage(reader, x, strategy);
                    foreach (iTextSharp.text.Rectangle rect in MatchesFound)
                    {
                         //----------Annotation ----------------
                         iTextSharp.text.Rectangle rect_txt = rect;
                         BaseFont helv = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                         rect_txt.Bottom = rect_txt.Top - 2;
                         rect_txt.Top = rect_txt.Top + 8;
                         rect_txt.Right = rect_txt.Right - ((rect_txt.Width) - Convert.ToInt32(text_num.ToString().Length) * 5);
                         rect_txt.Left = rect_txt.Left - 3.0f;
                         PdfAnnotation comment = PdfAnnotation.CreateFreeText(stamper.Writer, rect_txt, text_num.ToString(), cb);
                         comment.PlaceInPage = x;
                         comment.Put(PdfName.RC, new PdfString("<?xml version=\"1.0\"?><body xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/xfa-data/1.0/\" xfa:APIVersion=\"Acrobat:11.0.13\" xfa:spec=\"2.0.2\" style=\"font-size:9.0pt;text-align:left;color:#FF0000;font-weight:bold;font-style:normal;font-family:'helvetica';font-stretch:normal\"><p dir=\"ltr\"><span style=\"font-family:helvetica\">" + text_num.ToString() + "</span></p></body>", PdfObject.TEXT_UNICODE));
                         comment.BorderStyle = new iTextSharp.text.pdf.PdfBorderDictionary(0, 0);
     stamper.AddAnnotation(comment, x); 
                    }
                }
           }
      }

1 个答案:

答案 0 :(得分:1)

textInputLatout.getEditText().addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() < 1) {
               textInputLayout.setErrorEnabled(true);
                textInputLayout.setError("Please enter a value");
            }

            if (s.length() > 0) {
                textInputLayout.setError(null);
                textInputLayout.setErrorEnabled(false);
            }

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });