We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How to split a PDF document and store it to custom folder in WinRT

How to split a PDF document and store it to custom folder in WinRT

To split a single PDF document into multiple PDF documents you can use ImportPage or ImportPageRange method of PdfDocument object. Use windows FolderPicker to choose custom folder and store all the split PDF files. The following code example explains the same.

C#:

        private async void Button_Click(object sender, RoutedEventArgs e)

        {

            

            Stream docStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("SplitPDF.Assets.sample.pdf");

            //load the existing document

            PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream);

 

            List<MemoryStream> ms = new List<MemoryStream>();

 

            for (int i = 0; i < ldoc.Pages.Count; i++)

            {

                //Create a new Pdf document

                PdfDocument doc = new PdfDocument();

 

                //import the page

                doc.ImportPage(ldoc, i);

 

                MemoryStream file = new MemoryStream();

 

                //save the document

                doc.Save(file);

 

                ms.Add(file);

 

                //Close the document

                doc.Close(true);

                

            }

            Save(ms);

        }

 

 

private async void Save(List<MemoryStream> stream)

        {

            //select the folder to store the PDF files.

            FolderPicker picker = new FolderPicker();

            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

            picker.FileTypeFilter.Add(".pdf");

            StorageFolder stFile = await picker.PickSingleFolderAsync();

            //save the PDF document

            for (int i = 0; i < stream.Count;i++)

            {

                StorageFile file = await stFile.CreateFileAsync("sample"+i+".pdf",Windows.Storage.CreationCollisionOption.ReplaceExisting);

                stream[i].Position = 0;

                var buffer = new byte[(int)stream[i].Length];

                await stream[i].ReadAsync(buffer, 0, buffer.Length);

                await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);

            }

       }

 

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/141966/ze/SplitPDF-1339784308

 

Article ID: Published Date: Last Revised Date: Platform: Control:
5827 11/30/2015 11/30/2015 WinRT PDF
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.