Xbasic

pdf_split_pages Function

Syntax

L pdf_split_pages(C Source_File [,C Result_File ])

Arguments

Source_FileCharacter

The PDF file to split into multiple files. Must include full path to the file.

Result_FileCharacter

If not specified, the source filename is used. The output filename to use. Must include full path to where you want to save the file. For example, "C:\Users\MyUserName\Documents\MyPDFs\output.pdf". Each output file will append the page number to the file name. E.g. "output_page1.pdf", "output_page2.pdf", etc.

Returns

ResultLogical

Returns .t. if the operation succeeds. Otherwise .f..

Description

Split pdf document into single file per page.

Discussion

The pdf_split_pages() function splits a PDF file into multiple files. Each page in the PDF is saved as a separate PDF file with the suffix "_page" plus the page number appended to the filename. For example:

fn = "c:\files\invoice.pdf"

?pdf_split_pages(fn,"c:\files\invoice_paginated.pdf")
= .T.

?filefind.get("c:\files\invoice_pag*.pdf",0,"pn")
= c:\files\invoice_paginated_page1.pdf
c:\files\invoice_paginated_page10.pdf
c:\files\invoice_paginated_page11.pdf
c:\files\invoice_paginated_page12.pdf
c:\files\invoice_paginated_page13.pdf
c:\files\invoice_paginated_page14.pdf
c:\files\invoice_paginated_page15.pdf
c:\files\invoice_paginated_page16.pdf
c:\files\invoice_paginated_page17.pdf
c:\files\invoice_paginated_page18.pdf
c:\files\invoice_paginated_page19.pdf
c:\files\invoice_paginated_page2.pdf
c:\files\invoice_paginated_page20.pdf
c:\files\invoice_paginated_page21.pdf
c:\files\invoice_paginated_page22.pdf
c:\files\invoice_paginated_page23.pdf
c:\files\invoice_paginated_page24.pdf
c:\files\invoice_paginated_page25.pdf
c:\files\invoice_paginated_page26.pdf
c:\files\invoice_paginated_page27.pdf
c:\files\invoice_paginated_page28.pdf
c:\files\invoice_paginated_page29.pdf
c:\files\invoice_paginated_page3.pdf
c:\files\invoice_paginated_page30.pdf
c:\files\invoice_paginated_page31.pdf
c:\files\invoice_paginated_page4.pdf
c:\files\invoice_paginated_page5.pdf
c:\files\invoice_paginated_page6.pdf
c:\files\invoice_paginated_page7.pdf
c:\files\invoice_paginated_page8.pdf
c:\files\invoice_paginated_page9.pdf

The Source and Result file names must use backslashes (\) when defining the path. The operation may not succeed if forward (/) slashes are used. If you encounter issues, you can use the a5_is_path_valid() function to test your Source and Result file path to ensure they are valid. For example:

dim path as c 
path = file.filename_parse(filename,"dp")
? a5_is_valid_path(path)