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. Image for the cookie policy date

Split a pdf file

Is there any sample code available on how to split pdf files in winrt c# ?

28 Replies

CM Chinnu Muniyappan Syncfusion Team June 18, 2015 08:42 AM UTC

Hi kranthi,
Thank you for using syncfusion products.

We have created a sample for splitting PDF file in WinRT platform, Please find the sample available in the link below,

Sample link:
http://www.syncfusion.com/downloads/support/directtrac/139016/ze/SplitPDF-484838269

Please let us know if you need any further assistance.
Regards,
Chinnu


KK kranthi kumar June 18, 2015 12:01 PM UTC

Thanx a lot!! , can i use the same concept in windows phone 8 too ??


CM Chinnu Muniyappan Syncfusion Team June 19, 2015 12:51 PM UTC

Hi Kranthi.

Yes, we can use the same concept for splitting PDF documents in window phone 8 also, we have created  a simple sample for splitting PDF document in windows phone 8 for your reference, please refer the below sample.

Sample link:
http://www.syncfusion.com/downloads/support/forum/119414/ze/WinPhoneApp-1572264448
Please let us know if you have any further assistance.
Regards,
Chinnu


KK kranthi kumar June 23, 2015 07:30 AM UTC

Can u please provide me a sample for windows phone 8.1 where user picks a pdf file using file picker , i am unable to use pickandcontinue() method correctly during the process.


CM Chinnu Muniyappan Syncfusion Team June 24, 2015 07:08 AM UTC

Hi Kranthi,

As per your requirement we have created a windows phone 8.1 sample to pick a file using FilePicker to spilt the PDF document, please find the sample available in the link below.
Sample link:
http://www.syncfusion.com/downloads/support/directtrac/139704/ze/WinPhoneApp745632063

Please let us know if you need any further assistance.

Regards,
Chinnu


KK kranthi kumar June 24, 2015 12:48 PM UTC

Thanx for your support, the sample u provided is working great!! but when i modified it in a way that user can save the resultant file, i am getting ACESS DENIED error, i used a folder in my pc as sd card for windows phone emulator, here is the code part that i have changed

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;
using Windows.Storage.Pickers;
using Windows.Storage;
using Windows.Storage.Provider;
using System.Reflection;
using Syncfusion.Pdf.Interactive;
using Windows.UI.Popups;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.Activation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641

namespace WinPhoneApp
{

    public sealed partial class MainPage : Page
    {
        CoreApplicationView view;
        CoreApplicationView sview;
        string filePath = string.Empty;
        MemoryStream ms = new MemoryStream();
        public MainPage()
        {
            this.InitializeComponent();
            view = CoreApplication.GetCurrentView();
            sview = CoreApplication.GetCurrentView();
            this.NavigationCacheMode = NavigationCacheMode.Required;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
 
        }
        
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            filePath = string.Empty;
            FileOpenPicker filePicker = new FileOpenPicker();
            filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            filePicker.ViewMode = PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types
            filePicker.FileTypeFilter.Clear();
            filePicker.FileTypeFilter.Add(".pdf");

            filePicker.PickSingleFileAndContinue();
            
            view.Activated += viewActivated;

        }
        private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

            if (args != null)
            {
                if (args.Files.Count == 0) return;

                view.Activated -= viewActivated;
                StorageFile storageFile = args.Files[0];
                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
                Stream docStream = stream.AsStreamForRead();

                //loaded the Pdf file
                PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream);

                //Creating a new PDF document
                PdfDocument doc = new PdfDocument();
                doc.ImportPageRange(ldoc, 0, 1);

                doc.Save(ms);

                //trying to save file to user stated location
                var savepicker = new FileSavePicker();
                savepicker.FileTypeChoices.Add("Pdf", new List<string>() { ".pdf" });
                savepicker.SuggestedFileName = "Result";
                savepicker.PickSaveFileAndContinue();
                sview.Activated += sviewActivated;

                //Close the PDF document
                doc.Close(true);
                ldoc.Close(true);
            }
        }

        private async void sviewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            FileSavePickerContinuationEventArgs args = args1 as FileSavePickerContinuationEventArgs;
            ms.Position = 0;

            if (args != null)
            {
                sview.Activated -= sviewActivated;
                StorageFile stFile = args.File;
                if (stFile != null)
                {
                    Windows.Storage.Streams.IRandomAccessStream fileStream = await stFile.OpenAsync(FileAccessMode.ReadWrite);
                    Stream st = fileStream.AsStreamForWrite();
                    st.SetLength(0);
                    st.Write((ms as MemoryStream).ToArray(), 0, (int)ms.Length);
                    st.Flush();
                    st.Dispose();
                    fileStream.Dispose();
                }

                MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully.");
                UICommand yesCmd = new UICommand("Yes");
                msgDialog.Commands.Add(yesCmd);
                UICommand noCmd = new UICommand("No");
                msgDialog.Commands.Add(noCmd);
                IUICommand cmd = await msgDialog.ShowAsync();
                if (cmd == yesCmd)
                {
                    // Launch the retrieved file
                    bool success = await Windows.System.Launcher.LaunchFileAsync(stFile);
                }

            }
        }

    }
}   


CM Chinnu Muniyappan Syncfusion Team June 25, 2015 01:16 PM UTC

Hi Kranthi,
Thanks for your update.

It is not possible to trigger both open file picker and save file picker in a single button click event and it is a windows limitation. So we have created a sample with two buttons to open and save, Please find the sample available in the link below,

Sample link:
http://www.syncfusion.com/downloads/support/directtrac/133987/ze/WindowPhoneApp1593253692

Please let us know if you need any further assistance.
Regards,
Chinnu


KK kranthi kumar June 25, 2015 04:15 PM UTC

Your sample is working great!! thanx.


RJ Rilfanayasmin Jamal Nasar Syncfusion Team June 26, 2015 06:13 AM UTC

Hi Kranthi,
Thank you for your update.
Please let us know if you need any further assistance on this.
Regards,
Yasmin


KK kranthi kumar June 27, 2015 04:13 PM UTC

Is there any property available for PDF page rotation, can i rotate a given page range or all of the pages in a given pdf document?


CM Chinnu Muniyappan Syncfusion Team June 29, 2015 10:57 AM UTC

Hi Kranthi,
Yes, it is possible to Rotate a pages using PageSetting properties, we have created a sample for page rotation, please refer the sample and also find the below code snippet.

C#:

       //Set rotation angle
       doc.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle180;

Sample Link:
http://www.syncfusion.com/downloads/support/forum/119414/ze/RotatePages-1560152297

Please let us know if you need any further assistance.
Regards,
Chinnu



KK kranthi kumar June 30, 2015 10:53 AM UTC

I am using pdfviewer lo load & display the pdf, how can i rotate the page which the viewer is viewing currently ?, is it possible?


SS Sathish Sivakumar Syncfusion Team July 1, 2015 01:11 PM UTC

Hi Kranthi,
Thanks for your update.
Yes, it is possible to rotate the PDF Document being viewed in SfPdfViewer control.
We have created a sample for illustrating rotation being performed in the PDF Document when it is viewed using SfPdfViewer control. Please find the sample in the link below.
Sample:
http://www.syncfusion.com/downloads/support/forum/119414/ze/RotationWinRT-574447116
We have created a new incident for your query regarding “PDF Viewer Control to view PDF Documents in windows phone application”.
Kindly logon to your account to know further details about the new incident in following link.
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents
Please let us know if you need any other assistance.
Regards,
Sathish Sivakumar


KK kranthi kumar July 1, 2015 01:30 PM UTC

Now u got my point, ur sample is working great thanx!!


SS Sathish Sivakumar Syncfusion Team July 2, 2015 10:23 AM UTC

Hi Kranthi,
Thanks for your feedback.
We are glad to hear that the sample provided by us for rotating PDF Document when it is viewed using SfPdfViewer Control in Windows RT platform is working for you.
Please let us know if you need further assistance.
Regards,
Sathish Sivakumar.


KK kranthi kumar July 2, 2015 02:56 PM UTC

How can i open pdf file protected with owner password (not user password) to change file permissions in a pdfviewer ?


KK Karthik Krishnaraj Syncfusion Team July 3, 2015 11:01 AM UTC

Hi Kranthi,
On analyzing of your requirement for “Need to change permission for pdf document” we faced an issue and have logged defect report regarding this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents
 Please let me know if you have any questions.
Thanks,
Karthik.


KK kranthi kumar July 3, 2015 11:51 AM UTC

I am getting this error while stamping a pdf in winrt app, am i doing anything wrong ? Error Link


KK Karthik Krishnaraj Syncfusion Team July 6, 2015 10:35 AM UTC

Hi Kranthi,

We are glad to inform you that rotation support is added in Essential PDF for WinRT platform in the upcoming release, which is expected to be rolled out within end of this week. Please let us know if you have any other queries.

Thanks,

Karthik.



KK kranthi kumar July 6, 2015 11:01 AM UTC

I asked about PDF stamping issue but u gave me reply regarding pdf rotation ?


KK Karthik Krishnaraj Syncfusion Team July 7, 2015 11:46 AM UTC

Hi Kranthi,
Thank you for your update,
As per your error snapshot which shows “System.NotImplementedException”, while rotating the text .We used to throw this error message manually, since we have not provided support for rotation of text until the last release(13.1.0.21). Whereas now we have implemented rotation support for winRT platform in upcoming release which is expected to be rolled out within end of the week. If you do not want to rotate the text then you can remove the highlighted code used for rotation.  I have attached a code snippet and a simple sample for your reference below, please have a look through it and let us know if you need any further assistance.

Code Snippet:

PdfGraphics g = lPage.Graphics;

PdfGraphicsState state = g.Save();

g.SetTransparency(0.25f);

g.RotateTransform(-40); //Rotation of text not implemented yet.
g.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, new PointF(50,g.ClientSize.Height/2));

Sample Link:
http://www.syncfusion.com/downloads/support/forum/119414/ze/StampPdf-1839118842
Thanks,
Karthik.



KK kranthi kumar July 9, 2015 05:39 AM UTC

Your solution is working great!! thanx, when can i expect to download the updated release which supports text rotation?


KK Karthik Krishnaraj Syncfusion Team July 10, 2015 04:37 AM UTC

Hi Kranthi,

We are glad to announce that our Essential Studio 2015 Volume 2 Final release version 13.2.0.29 is rolled out and it’s available for download under the following link.

http://www.syncfusion.com/forums/119549/essential-studio-2015-volume-2-final-release-v13-2-0-29-available-for-download

Here in this release we provided support for text rotation in winRT platform.We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

Regards,
Karthik.


KK kranthi kumar July 10, 2015 07:37 AM UTC

As you said i downloaded the latest version of essential studio, i uninstalled the previous version & to my surprise during the uninstall procedure of previous essential studio version all of my Documents folder got wiped out for no good reason!! , how ridiculous is this! , don't u test your products prior to their release??, i am using windows 8.1 pro 64 bit.


MS Manivannan Sundararajan Syncfusion Team July 13, 2015 11:13 AM UTC

Hi Kranthi,

We deeply regret for the inconvenience caused.

If you have installed the Binaries or Samples in Documents folder directly, while uninstalling the setup, immediate root folder will be removed.

We have logged this issue and we will create the parent folder with Syncfusion Version under your root directory. Also it will be included in our upcoming 2015 Vol 2 Service Pack 1 release.

As of now, if you install the setup in Documents or any root directory, please create a subfolder under the root directory and then install the Syncfusion Essential Studio setup.

Please let us know if you need any further assistance on this.

Regards,
Manivannan S.


MS Manivannan Sundararajan Syncfusion Team July 13, 2015 11:13 AM UTC

Hi Kranthi,

We deeply regret for the inconvenience caused.

If you have installed the Binaries or Samples in Documents folder directly, while uninstalling the setup, immediate root folder will be removed.

We have logged this issue and we will create the parent folder with Syncfusion Version under your root directory. Also it will be included in our upcoming 2015 Vol 2 Service Pack 1 release.

As of now, if you install the setup in Documents or any root directory, please create a subfolder under the root directory and then install the Syncfusion Essential Studio setup.

Please let us know if you need any further assistance on this.

Regards,
Manivannan S.


MA Mootaz Abdellatif July 4, 2019 02:22 PM UTC

Is there any sample code available on how to split pdf files in asp.net mvc5 ?


SK Surya Kumar Syncfusion Team July 5, 2019 09:15 AM UTC

Hi Mootaz, 

Greetings from Syncfusion. 
Kindly refer the below mentioned KB link to split PDF document: 
You can refer the below UG documentation link to importing pages from multiple PDF: 

Let us know if you need any further information. 

Regards, 
Surya Kumar 


Loader.
Live Chat Icon For mobile
Up arrow icon