private System.IO.MemoryStream reorderSaddleStitchBrief(System.IO.MemoryStream orig_stream)
        {
            System.IO.MemoryStream dest_stream = null;
            try
            {
                dest_stream = new System.IO.MemoryStream();



                var reader = new iTextSharp.text.pdf.PdfReader(orig_stream.ToArray());
                var order  = new SaddleStitchPageOrder(reader.NumberOfPages);
                reader.SelectPages(order.PageOrder);
                var pdfdoc           = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1));
                var pdfcopy_provider = new iTextSharp.text.pdf.PdfCopy(pdfdoc, dest_stream);
                pdfdoc.Open();
                iTextSharp.text.pdf.PdfImportedPage importedPage;
                for (int i = 1; i <= reader.NumberOfPages; i++)
                {
                    importedPage = pdfcopy_provider.GetImportedPage(reader, i);
                    pdfcopy_provider.AddPage(importedPage);
                }
                pdfdoc.Close();
                reader.Close();
            }
            catch (Exception excpt)
            {
                System.Diagnostics.Debug.WriteLine(excpt);
            }
            return(dest_stream);
        }
示例#2
0
        public static bool SaddleStitch_ReorderPagesForLayout(string src)
        {
            string dest = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(src), "ss brief reordered.pdf");

            try
            {
                using (var stream = new System.IO.FileStream(dest, System.IO.FileMode.Create))
                {
                    iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(src);
                    SaddleStitchPageOrder         order  = new SaddleStitchPageOrder(reader.NumberOfPages);
                    reader.SelectPages(order.PageOrder);
                    iTextSharp.text.Document    pdfdoc           = new iTextSharp.text.Document(reader.GetPageSizeWithRotation(1));
                    iTextSharp.text.pdf.PdfCopy pdfcopy_provider = new iTextSharp.text.pdf.PdfCopy(pdfdoc, stream);
                    pdfdoc.Open();
                    iTextSharp.text.pdf.PdfImportedPage importedPage;
                    for (int i = 1; i <= reader.NumberOfPages; i++)
                    {
                        importedPage = pdfcopy_provider.GetImportedPage(reader, i);
                        pdfcopy_provider.AddPage(importedPage);
                    }
                    pdfdoc.Close();
                    reader.Close();
                }
                System.IO.File.Delete(src);
                System.IO.File.Move(dest, src);
                return(true);
            }
            catch (Exception excpt) { System.Diagnostics.Debug.WriteLine(excpt); return(false); }
        }