0

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!

Matze
  • 5,100
  • 6
  • 46
  • 69
peacefullearner
  • 81
  • 1
  • 10
  • If you are a true peaceful learner, you read the documentation! For instance [Chapter 6 of my book](https://manning-content.s3.amazonaws.com/download/d/3645210-8560-4e6d-9b03-3f9aca1921a5/samplechapter6.pdf), because learners read documentation! – Bruno Lowagie Apr 22 '16 at 07:16
  • @BrunoLowagie I was able to create a pdf of the 2 files side by side, their positioning is not the problem. The problem I'm facing is the annotations disappear in the combined output file. – peacefullearner Apr 22 '16 at 17:50

0 Answers0