I have 2 Pdfs with annotations I've added through iTextSharp to highlight specific text. When I go to impose the first page of the 2 Pdfs together (pdf 1 page 1 side by side with pdf2 page 1), the highlighted text doesn't copy over.
My code for highlighting text is as follows:
private static void highlightDiff(PdfStamper stamper, Rectangle rectangle, int page, int rotation)
{
List<float> quadPoints = new List<float>() { rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Top, rectangle.Left, rectangle.Bottom, rectangle.Right, rectangle.Bottom };
PdfAnnotation highlight = PdfAnnotation.CreateMarkup(stamper.Writer, rectangle, null, PdfAnnotation.MARKUP_HIGHLIGHT, quadPoints.ToArray());
highlight.Color = BaseColor.YELLOW;
stamper.AddAnnotation(highlight, page);
}
And my code to combine the 2 files side by side:
public void inposeEobs(PdfReader reader1, PdfReader reader2, string outputPath)
{
Rectangle rectangle1 = reader1.GetPageSize(1);
Rectangle rectangle2 = reader2.GetPageSize(1);
float width = rectangle1.Width + rectangle2.Width;
float height = Math.Max(rectangle1.Height, rectangle2.Height);
FileStream fileStream = new FileStream(outputPath, FileMode.Create);
Document document = new Document(new Rectangle(width, height));
PdfWriter pdfWriter = PdfWriter.GetInstance(document, fileStream);
document.Open();
PdfImportedPage importedPage = pdfWriter.GetImportedPage(reader1, 1);
PdfContentByte contentByte = pdfWriter.DirectContentUnder;
contentByte.AddTemplate(importedPage, 0, 0);
importedPage = pdfWriter.GetImportedPage(reader2, 1);
contentByte.AddTemplate(importedPage, width, 0);
document.Close();
fileStream.Close();
}
The merge is perfect except for the fact that the annotation highlights from the 2 Pdfs disappear in the output file. Any idea what could be wrong? Thank you!