Ejemplo n.º 1
0
        public byte[] MergePdfDocuments(List <byte[]> files)
        {
            if (files == null)
            {
                return(null);
            }
            if (files.Count == 1)
            {
                return(files[0]);
            }
            using (var dest = new org.pdfclown.files.File(new org.pdfclown.bytes.Buffer(files[0])))
            {
                var document = dest.Document;
                var builder  = new org.pdfclown.tools.PageManager(document);
                foreach (var file in files.Skip(1))
                {
                    using (var src = new org.pdfclown.files.File(new org.pdfclown.bytes.Buffer(file)))
                    { builder.Add(src.Document); }
                }

                using (var output = new org.pdfclown.bytes.Buffer())
                {
                    dest.Save(output, SerializationModeEnum.Incremental);
                    return(output.ToByteArray());
                }
            }
        }
Ejemplo n.º 2
0
        public void MergePdfDocuments(string destFile)
        {
            var list = Directory.GetFiles(Path.GetFullPath(_src));

            if (string.IsNullOrWhiteSpace(_src) || string.IsNullOrWhiteSpace(destFile) || list.Length <= 1)
            {
                return;
            }
            var files = list.Select(File.ReadAllBytes).ToList();

            using (var dest = new org.pdfclown.files.File(new org.pdfclown.bytes.Buffer(files[0])))
            {
                var document = dest.Document;
                var builder  = new org.pdfclown.tools.PageManager(document);
                foreach (var file in files.Skip(1))
                {
                    using (var src = new org.pdfclown.files.File(new org.pdfclown.bytes.Buffer(file)))
                    { builder.Add(src.Document); }
                }

                dest.Save(destFile, SerializationModeEnum.Incremental);
            }
        }