public void Process(Stream outputStream, Stream[] inputStreams, PageLayout pageLayout) { using (var buffer1 = new MemoryStream()) { using (var doc = new Document(pageLayout.PageSize)) using (var writer = PdfWriter.GetInstance(doc, buffer1)) { writer.CloseStream = false; doc.Open(); var cb = writer.DirectContent; for (var i = 0; i < inputStreams.Length; ++i) { using (var buffer2 = new MemoryStream()) { TrimPDFFile(buffer2, inputStreams[i], pageLayout); var reader = new PdfReader(buffer2.ToArray()); var page = writer.GetImportedPage(reader, 1); var offset = pageLayout.GetLabelRect(i); cb.AddTemplate(page, 1.0f, 0, 0, 1.0f, offset.Left, offset.Bottom); } } } buffer1.Position = 0; OptimizePDFFile(outputStream, buffer1); } }