PDF SplitDocumentPages

2 Answers 61 Views
PdfProcessing
stafil
Top achievements
Rank 1
stafil asked on 10 Oct 2024, 04:01 PM | edited on 10 Oct 2024, 07:10 PM

Hi,

I have: Telerik UI for ASP.NET AJAX

I test SplitDocumentPages from PDF example. from https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/ManipulatePages/Program.cs

net.framework: 4.8

test pdf is: https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/ManipulatePages/InputFiles/MultipageDocument.pdf

Not working well. see picture split1.pdf, only large rectangle without any data.

Please help.

Thx

2 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 15 Oct 2024, 09:10 AM

Hi,

Judging by the screenshot, the PDF File was generated with the Trial message "This document was generated by a trial version of Telerik Document Processing". This means the PDF Processing library is working. Since there is no other content in the PDF document, that indicates that the code that is supposed to split the document is incorrect.

The code from the Example will not work in without making changes as it was written for Windows applications. Write a code specific to ASP.NET:

Please make sure that the Paths pointing to the MultiPage and destination directory are correct. In ASP.NET, you can use the Server.MapPath method to convert relative path absolute path.

Here is an example:

const string MultiPageDocument = "~/MultipageDocument.pdf";
const string ResultsDireName = "~/Documents";
private void SplitDocumentPages()
{
    string documentToSplit = Server.MapPath(MultiPageDocument);

    using (PdfFileSource fileToSplit = new PdfFileSource(File.OpenRead(documentToSplit)))
    {
        for (int i = 0; i < fileToSplit.Pages.Length; i++)
        {
            PdfPageSource page = fileToSplit.Pages[i];
            string splitDocumentName = Path.Combine(Server.MapPath(ResultsDireName), string.Format("{0}.pdf", i + 1));

            using (PdfStreamWriter fileWriter = new PdfStreamWriter(File.OpenWrite(splitDocumentName)))
            {
                fileWriter.WritePage(page);
            }
        }
    }
}

protected void Button1_Click(object sender, EventArgs e)
{
    SplitDocumentPages();
}

I hope this will help resolve the issue.

Regards,
Attila Antal
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
stafil
Top achievements
Rank 1
commented on 15 Oct 2024, 09:36 AM

Hi, thanks for answer.

I try with payed Telerik ASP.NET AJAX.

In source pdf:

 

 

This is the result.

 

Attila Antal
Telerik team
commented on 15 Oct 2024, 10:42 AM

Hi, 

Can you please try the code I shared to split the following MultiPage PDF file to Multiple PDF files and tell me how it goes?: 

MultiPage Pdf Document: https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/ManipulatePages/InputFiles/MultipageDocument.pdf 

You should get this result:

stafil
Top achievements
Rank 1
commented on 15 Oct 2024, 11:14 AM | edited

yes 21 files is created.

my result is:

 

 

and your result (content) in pdf is?

 

thx

Attila Antal
Telerik team
commented on 15 Oct 2024, 11:23 AM

Maybe there's is something missing in your app.

Do you have all the Assemblies included in the Project for this to happen?

  • Telerik.Windows.Documents.Core.dll
  • Telerik.Windows.Documents.Fixed.dll
  • Telerik.Windows.Zip.dll

Are you using the same exact code I showed you?

 

This is what I get. Each page from 1 through 21 has content.

stafil
Top achievements
Rank 1
commented on 15 Oct 2024, 11:29 AM | edited

Yes, I have:

 

Attila Antal
Telerik team
commented on 15 Oct 2024, 11:41 AM

I'm afraid I am out of ideas. It seem you have everything set, yet the results show differently.

To be able to help, I will need some more information so I can replicate the issue. Can you share the WebForms page (ASPX and ASPX.cs files) so I can review the code you are using to split the PDF contents?

stafil
Top achievements
Rank 1
commented on 15 Oct 2024, 11:48 AM

I create console application. Then write results, and share application.

 

thx

stafil
Top achievements
Rank 1
commented on 15 Oct 2024, 12:16 PM

Same result.

stafil
Top achievements
Rank 1
commented on 15 Oct 2024, 12:44 PM | edited

I send zip file. Pass:ManipulatePages

 

[ attachment removed by Admin ]

Attila Antal
Telerik team
commented on 15 Oct 2024, 02:00 PM

Thanks for sharing the sample. I have tested it and it works as expected. See the screenshots with the directory "Demo results" containing the PDF files and the contents of the first file that I opened. I believe at this point the issue is with something other than the Document Processing library. Please make sure that the application has enough permissions to write to the disk.

Note: I have removed the sample from your response as it contains the non-trial assemblies and sharing this in a public website is forbidden and carries legal consequences.

Screenshot

stafil
Top achievements
Rank 1
commented on 15 Oct 2024, 02:03 PM | edited

Did it work for you with my dlls?

licx is not needed?

 

I don't understand why it doesn't work. I'm disappointed with that. I don't know what else to set to make it work.

Attila Antal
Telerik team
commented on 16 Oct 2024, 10:31 AM | edited

Yes, I ran the sample you shared with the included assemblies and worked flawlessly. Try running Visual Studio as Administrator then load this solution into it. Run the application and see if that makes a difference.

The license.licx file is generated by Visual Studio automatically for licensed assemblies. You can delete this file without any problems. VS will generate another one automatically.

stafil
Top achievements
Rank 1
commented on 16 Oct 2024, 10:44 AM

I tried it but it doesn't work even under admin. I also tried to run the exe as an administrator, but to no avail (still an empty rectangle). license.licx was not created for me at all. I have referenced dlls from another directory where I have telerik dlls (not nuget).
0
Richard
Top achievements
Rank 1
Iron
answered on 16 Oct 2024, 03:08 PM

We are doing something wrong.

As i try any pdf to split in Demos - Telerik UI for ASP.NET Core 2024 Q3 installed on my competer it works ok.

 

But if i try the code above in Telerik UI for ASP.NET AJAX 2024 Q3 project, then i get correct amount of pages but with no content or the content is cropped. It looks like splitting pages gives me wrong page size and not take properties from original documents.

Where is tha hack?

 


 

Yoan
Telerik team
commented on 21 Oct 2024, 08:09 AM

Hello,

My name is Yoan, from the Document Processing team. I am joining this conversation to verify whether or not this case is PdfProcessing-related. I hope you don't mind, but I am opening a separate support ticket 1667995 on your behalf with the corresponding PdfProcessing product, so we can have a separate isolated discussion. If you have any questions or feedback you would like to follow up with, please feel free to do so in the newly open thread (1667995) for the time being.

Thank you for your understanding.

Regards,

Yoan

Richard
Top achievements
Rank 1
Iron
commented on 21 Oct 2024, 02:11 PM

OK, thanks. But i cannot see a support ticket in my account yet. There might be a bug in Telerik.Windows.Document.Fixed library version v4.0.30319. As i tried before, .net core project is splitting correct way, but asp.net ajax is ignoring dimennsions of page.
Yoan
Telerik team
commented on 21 Oct 2024, 02:19 PM

Hello Richard,

Please excuse me for the misunderstanding. The newly created support ticket is under the following number - 1668051.

Regards,

Yoan

Tags
PdfProcessing
Asked by
stafil
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Richard
Top achievements
Rank 1
Iron
Share this question
or