0

Greetings Im relative new with the use of ItextSharp and have this code where I merge one existing file to the document I'm creating, the source file have hyperlinks but when I add them to the new document the hyperlinks arent working and im not sure if it's posible or not to keep the hyperlink or if I need to use another way to merge them together and keep the hyperlink, thanks for your help.

        PdfReader test_reader = new PdfReader(info_document.file_data);

        for (int i = 1; i <= test_reader.NumberOfPages; i++)
        {
            PdfImportedPage test_page = writer.GetImportedPage(test_reader, i);
            if (test_page.Rotation != 90)
            {
                Rectangle test = test_reader.GetPageSize(i);
                Rectangle test2 = new Rectangle(test.Width, test.Height);
                doc.SetPageSize(test2);
                doc.NewPage();
                PdfPTable mergeTable = new PdfPTable(1);
                mergeTable.WidthPercentage = 100;
                Image image = Image.GetInstance(test_page);
                PdfPCell mergeCell = new PdfPCell(image, true);
                mergeCell.Border = 0;
                mergeCell.BorderWidth = 0;
                mergeTable.AddCell(mergeCell);
                doc.Add(mergeTable);
            }
        }
  • For actual merging of documents with iText you should use a `PdfCopy` based approach, not a `PdfWriter` based one. For some background see [this answer](https://stackoverflow.com/a/15945467/1729265). – mkl Oct 22 '20 at 06:27
  • Thanks a lot, i reviewed this answer, like I told I'm not an expert with Itextsharp but this solved my issue – Flame Knight Oct 23 '20 at 16:02
  • OK. I marked your question as a duplicate of that other question as its answer resolved your issue. – mkl Oct 23 '20 at 17:20

0 Answers0