Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Sun Jul 07, 2024 3:30 am
have pdf file 980 pages how to split from 0 to 100 and from 101 to 200 and from 201 to 300
how to get total page and split to 10 parts
The number of pages is calculated and divided pdf into a group of pages based on the total number
my code :VB.NET
'Specify the input file path
Dim op As New OpenFileDialog()
op.ShowDialog()
Dim inputFile As String = op.FileName
'Specify the output directory
Dim outputDirectory As String = "D:\\Output\\"
'Load the source PDF file while initialing the PdfDocument object
Dim Pdf As PdfDocument = New PdfDocument(inputFile)
'Insert the rest pages of source file to the second document
Dim Index As Integer = Pdf.Pages.Count / 10 ' split part pdf
For i As Integer = 0 To Pdf.Pages.Count - 1
Pdf.InsertPageRange(Pdf, Index, Pdf.Pages.Count - 1)
'Save the split documents as PDF files
Pdf.SaveToFile(outputDirectory + "output-" & i & ".pdf")
Next
MsgBox("تمت عملية التقسيم بنجاح")
-
alqadhidata
-
- Posts: 1
- Joined: Tue Nov 07, 2023 6:53 pm
Mon Jul 08, 2024 3:26 am
Hi,
Thank you for your inquiry.
Please refer to code below to split PDF. If there's still any issue, please provide your PDF document for our investigation, thanks in advance!
- Code: Select all
Dim inputFile As String = "sample.pdf"
'Specify the output directory
Dim outputDirectory As String = "D:\\Output\\"
'Load the source PDF file while initialing the PdfDocument object
Dim Pdf As PdfDocument = New PdfDocument(inputFile)
If Pdf.Pages.Count > 9 Then
'Insert the rest pages of source file to the second document
Dim Index As Integer = Pdf.Pages.Count / 10 ' split part pdf
Dim Start As Integer = 0
For i As Integer = 0 To 10
Dim newPdf As PdfDocument = New PdfDocument()
If i = 10 Then
newPdf.InsertPageRange(Pdf, Start, Pdf.Pages.Count - 1)
newPdf.SaveToFile(outputDirectory + "output-" + i.ToString() + ".pdf")
Return
End If
newPdf.InsertPageRange(Pdf, Start, Start + Index - 1)
Start = Start + Index
newPdf.SaveToFile(outputDirectory + "output-" + i.ToString() + ".pdf")
Next i
End If
Sincerely,
Doris
E-iceblue support team
-
Doris.Liu
-
- Posts: 330
- Joined: Mon Nov 07, 2022 8:10 am