将两个PDF页面合并为一个页面?

这里的总体尝试是拥有两个PDF页面,其中一个页面“较小”,位于另一个PDF文档的右下角。我在网上看过,但是到目前为止,找到的所有解决方案都无法对我起作用。

这是我尝试的几种解决方案:

    PdfReader reader = new PdfReader(@"C:\temp\pdfFolder\mainPDF.pdf");

    iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate(), 10, 10, 10, 10);
    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@"C:\temp\pdfFolder\secondaryPDF.pdf", FileMode.Append));

    doc.Open();
    PdfImportedPage page;

    PdfPTable table = new PdfPTable(2);
    table.WidthPercentage = 100;

    for(int i = 1; i <= reader.NumberOfPages; i++)
    { 
      page = writer.GetImportedPage(reader, i);
      table.AddCell(iTextSharp.text.Image.GetInstance(page));
      doc.Add(table);
    }

    MemoryStream finalStream = new MemoryStream();
    PdfCopyFields copy = new PdfCopyFields(finalStream);

    PdfManager pdfMan = new PdfManager();
    Persits.PDF.PdfDocument docOne = pdfMan.OpenDocument(@"C:\temp\pdfFolder\mainPDF.pdf");
    Persits.PDF.PdfDocument docTwo = pdfMan.OpenDocument(@"C:\temp\pdfFolder\secondaryPDF.pdf");

    MemoryStream docOneMem = new MemoryStream(docOne.SaveToMemory());
    MemoryStream docTwoMem = new MemoryStream(docTwo.SaveToMemory());

    docOneMem.Position = 0;
    copy.AddDocument(new PdfReader(docOneMem));
    docOneMem.Dispose();

    docTwoMem.Position = 0;
    copy.AddDocument(new PdfReader(docTwoMem));
    docTwoMem.Dispose();
    copy.Close();

    Persits.PDF.PdfDocument finalDoc = pdfMan.CreateDocument();
    Persits.PDF.PdfPage finalDocPage = finalDoc.Pages.Add();

    finalDocPage.Equals(finalStream);

    finalDoc.Save(@"C:\temp\pdfFolder\finalpdf.pdf");

任何帮助或指导将不胜感激。

评论