0
Я добавил текст в формате pdf. Но добавленный текст не отображается в браузере.Добавлен текст в pdf, не отображаемый в браузере, используя itextsharp
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);
}
}
}
}
Узнайте ответ. Внешний вид = PdfAppearance.CreateAppearance (stamper.Writer, rect_txt.Width, rect_txt.Height); внешний вид. Прямоугольник (0, 0, rect_txt.Width, rect_txt.Height); внешний вид.SetFontAndSize (helv, 12); внешний вид.SetColorFill (BaseColor.RED); ColumnText.ShowTextAligned (внешний вид, Element.ALIGN_LEFT, новая фраза (text_num), 0, 0, 0); – Karthik
Пожалуйста, напишите, что в качестве фактического ответа на ваш вопрос, а не просто комментарий. – mkl