组合2个Pdfs时注释不复制

时间:2016-04-22 02:00:54

标签: c# pdf annotations itext

我有2个带有注释的Pdfs我已通过iTextSharp添加以突出显示特定文本。当我将2个Pdfs的第一页拼写在一起时(pdf 1第1页与pdf2第1页并排),突出显示的文本不会复制。

我突出显示文字的代码如下:

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);
}

我的代码将两个文件并排组合:

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();
}

合并是完美的,除了2 Pdfs中的注释高亮显示在输出文件中消失。知道什么可能是错的吗?谢谢!

0 个答案:

没有答案