Splitting PDFs within a page

User avatar
John Gray
PlatinumLounger
Posts: 5403
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Splitting PDFs within a page

Post by John Gray »

I have a number of (almost) identical PDF pages, in separate one-page files, where I want just the top third (or so) of each page.

All the PDF splitters I've come across seem to split at page boundaries.

I don't have Adobe Acrobat, and the PDFs seem to have been set to prevent cut-and-paste.

Can anyone point me at an online method of extracting just the section I want from every page, please?

Otherwise I shall have to do something messy with Print Screen and Paint -> Crop...
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Splitting PDFs within a page

Post by HansV »

Can you open the PDF file in Microsoft Word?
Best wishes,
Hans

User avatar
John Gray
PlatinumLounger
Posts: 5403
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Splitting PDFs within a page

Post by John Gray »

Not in Word 2010, I'm afraid, otherwise that would be ideal, since I want to put each third-page into a 2 x 4 Word table to reduce printing...
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Splitting PDFs within a page

Post by HansV »

Time to upgrade to a recent version of Office...
Or use LibreOffice Writer (free)
Best wishes,
Hans

User avatar
DaveA
GoldLounger
Posts: 2599
Joined: 24 Jan 2010, 15:26
Location: Olympia, WA

Re: Splitting PDFs within a page

Post by DaveA »

Have you tried a screen shot and then OCR that?
I am so far behind, I think I am First :evilgrin:
Genealogy....confusing the dead and annoying the living

User avatar
John Gray
PlatinumLounger
Posts: 5403
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Splitting PDFs within a page

Post by John Gray »

Then I will probably use LibreOffice on one of my Linux distros.
Each PDF contains a bar code, which I need to preserve.
Thanks!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Splitting PDFs within a page

Post by HansV »

John Gray wrote:Do I seem more unusual than usual?
You seem unusually usual to me...
Best wishes,
Hans

User avatar
John Gray
PlatinumLounger
Posts: 5403
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Splitting PDFs within a page

Post by John Gray »

HansV wrote:
24 Jan 2022, 18:37
John Gray wrote:Do I seem more unusual than usual?
You seem unusually usual to me...
Thank you!
Or maybe not...
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
HansV
Administrator
Posts: 78378
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Splitting PDFs within a page

Post by HansV »

It's not unusual...
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Splitting PDFs within a page

Post by StuartR »

John Gray wrote:
24 Jan 2022, 14:30
I don't have Adobe Acrobat, and the PDFs seem to have been set to prevent cut-and-paste.
It is trivially easy to remove password protection from a PDF file. I won't describe how here, but a quick internet search should show you how.
StuartR


jolas
3StarLounger
Posts: 204
Joined: 02 Feb 2010, 23:58

Re: Splitting PDFs within a page

Post by jolas »

You may like to try NAPS2.

Just drag and drop your pdf on the application. Crop out the areas you don't need and save.

You may want to duplicate the page before editing in case you need the other areas of the page.

There are other neat features like OCR (different languages) as well as pdf settings that you may want to implement when you want to share a pdf.

It is a freeware scanning software.

User avatar
John Gray
PlatinumLounger
Posts: 5403
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Splitting PDFs within a page

Post by John Gray »

Thanks, Stuart and especially jolas!

The NAPS2 PDF software, although not entirely intuitive and with some scaling annoyances, enabled me to crop each single PDF page and save the resultant "top third" of the page as a JPEG, and insert it into a Word 2010 2x4 table cell, for subsequent printing!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

Priyantha
StarLounger
Posts: 86
Joined: 10 Oct 2022, 02:52

Re: Splitting PDFs within a page

Post by Priyantha »

Dear All,

I received a merge file including payslips. I tried to split payslips using below VBA code & there is a specific number in a particular place on every payslip. I hope to use this exact number as the file name (Eg. 37224.pdf) can anyone help me.

Option Explicit
Sub pdf()

Dim Acro_app As Acrobat.AcroApp
Dim Acro_PDDoc As Acrobat.AcroPDDoc
Dim Acro_NewPDDoc As Acrobat.AcroPDDoc

Set Acro_app = New Acrobat.AcroApp
Set Acro_PDDoc = New Acrobat.AcroPDDoc

Acro_PDDoc.Open "C:\Users\User\Desktop\PDF\Slip.pdf"

Dim i As Integer

For i = 0 To Acro_PDDoc.GetNumPages() - 1
Set Acro_NewPDDoc = New Acrobat.AcroPDDoc
Acro_NewPDDoc.Create
Acro_NewPDDoc.InsertPages -1, Acro_PDDoc, i, 1, 1
Acro_NewPDDoc.Save 1, "C:\Users\User\Desktop\PDF\S" & i & ".pdf"

Next i

End Sub

Thanks,

Priyan
You do not have the required permissions to view the files attached to this post.

User avatar
Jay Freedman
Microsoft MVP
Posts: 1316
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Splitting PDFs within a page

Post by Jay Freedman »

Priyantha wrote:
20 Feb 2023, 12:16
Dear All,

I received a merge file including payslips. I tried to split payslips using below VBA code & there is a specific number in a particular place on every payslip. I hope to use this exact number as the file name (Eg. 37224.pdf) can anyone help me.
I know almost nothing about the Acrobat object model, but I was able to follow the example in the first reply to https://stackoverflow.com/questions/297 ... -using-vba and got this to work.

The main thing that was missing was the AcroAVDoc object, which is used to open the PDF file. Then the AcroPDDoc object is assigned the result of the .GetPDDoc function of the AcroAVDoc. (I have no idea why it works this way.)

Code: Select all

Sub pdf()
    Dim strPath As String
    Dim Acro_app As Acrobat.AcroApp
    Dim acro_AVDoc As Acrobat.AcroAVDoc
    Dim Acro_PDDoc As Acrobat.AcroPDDoc
    Dim Acro_NewPDDoc As Acrobat.AcroPDDoc
    
    strPath = "C:\Users\User\Desktop\PDF\"
    
    Set Acro_app = New Acrobat.AcroApp
    Set acro_AVDoc = New Acrobat.AcroAVDoc
    
    If acro_AVDoc.Open(strPath & "Slip.pdf", "") = True Then
        Set Acro_PDDoc = acro_AVDoc.GetPDDoc
        Dim i As Integer
        
        For i = 0 To Acro_PDDoc.GetNumPages - 1
            Set Acro_NewPDDoc = New Acrobat.AcroPDDoc
            Acro_NewPDDoc.Create
            Acro_NewPDDoc.InsertPages -1, Acro_PDDoc, i, 1, 1
            Acro_NewPDDoc.Save 1, strPath & "S" & i & ".pdf"
            Acro_NewPDDoc.Close
        Next i
        
        Acro_PDDoc.Close
    Else
        MsgBox "Open failed"
    End If
    acro_AVDoc.Close wdDoNotSaveChanges
    Set Acro_PDDoc = Nothing
    Set acro_AVDoc = Nothing
    Set Acro_app = Nothing
End Sub

Priyantha
StarLounger
Posts: 86
Joined: 10 Oct 2022, 02:52

Re: Splitting PDFs within a page

Post by Priyantha »

Dear Jay Freedman,

Thanks your guidance,

I want to capture the number or text at a specific position in each separated pdf page (Eg. Like the third word in the second line) and name the separated file based on it. For that, is there a possibility to capture the number or text in the relevant position by using a method of Finding the exact X and Y coordinates and then refer it to a variable?

Thanks,

Priyantha

User avatar
Jay Freedman
Microsoft MVP
Posts: 1316
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Splitting PDFs within a page

Post by Jay Freedman »

Using XY coordinates to locate specific text is not appropriate for PDF documents of the type in your sample Split.pdf file. That approach would be necessary if the PDF was created by scanning a paper document, because that kind of PDF contains only a picture of the original text. Extracting readable text from that picture would require optical character recognition (OCR) software.

Fortunately, Split.pdf and files like it are created from text generated by a program such as Word or a database, and the PDF contains readable text in addition to non-readable formatting information. That means the text can be extracted directly from the PDF -- for example, the document can be opened in Word (any version from 2013 onward) and a macro can "read" it.

I found that opening Split.pdf itself in Word doesn't start new pages in the same way that Acrobat Reader does, so you do need to split the file into separate files, one per page, before opening each resulting file in Word or another editor. (By the way, what Office program are you using to run the macro you posted?) The macro can then continue by searching the open document for the line's label, such as EMP. NO., followed by a tab and the employee number, and using the employee number to rename the file.
1.png
You do not have the required permissions to view the files attached to this post.

Priyantha
StarLounger
Posts: 86
Joined: 10 Oct 2022, 02:52

Re: Splitting PDFs within a page

Post by Priyantha »

Dear Jay Freedman,

I am using office 2016