Пример #1
0
        public static void SplitDocumentToPages(string docName)
        {
            string folderName    = Path.GetDirectoryName(docName);
            string fileName      = Path.GetFileNameWithoutExtension(docName);
            string extensionName = Path.GetExtension(docName);
            string outFolder     = Path.Combine(folderName, "Out");

            Console.WriteLine("Processing document: " + fileName + extensionName);

            Document doc = new Document(docName);

            // Create and attach collector to the document before page layout is built.
            LayoutCollector layoutCollector = new LayoutCollector(doc);

            // This will build layout model and collect necessary information.
            doc.UpdatePageLayout();

            // Split nodes in the document into separate pages.
            DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);

            // Save each page to the disk as a separate document.
            for (int page = 1; page <= doc.PageCount; page++)
            {
                Document pageDoc = splitter.GetDocumentOfPage(page);
                pageDoc.Save(Path.Combine(outFolder, string.Format("{0} - page{1} Out{2}", fileName, page, extensionName)));
            }

            // Detach the collector from the document.
            layoutCollector.Document = null;
        }
Пример #2
0
        public static void SplitDocumentToPages(string docName)
        {
            string folderName = Path.GetDirectoryName(docName);
            string fileName = Path.GetFileNameWithoutExtension(docName);
            string extensionName = Path.GetExtension(docName);
            string outFolder = Path.Combine(folderName, "_out_");

            Console.WriteLine("Processing document: " + fileName + extensionName);

            Document doc = new Document(docName);

            // Create and attach collector to the document before page layout is built.
            LayoutCollector layoutCollector = new LayoutCollector(doc);

            // This will build layout model and collect necessary information.
            doc.UpdatePageLayout();

            // Split nodes in the document into separate pages.
            DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);

            // Save each page to the disk as a separate document.
            for (int page = 1; page <= doc.PageCount; page++)
            {
                Document pageDoc = splitter.GetDocumentOfPage(page);
                pageDoc.Save(Path.Combine(outFolder, string.Format("{0} - page{1} Out{2}", fileName, page, extensionName)));
            }

            // Detach the collector from the document.
            layoutCollector.Document = null;
        }