![]() |
|
|
|
#1
|
|||
|
|||
|
Hi all! Is it possible for VBA to extract the contents from every page's header and footer and then insert them to the first and the last line of that page respectively? I used Acrobat to convert a PDF (actually, a PPT in PDF format) into word, but some pages' headings turn into headers for pages in Word and they're all different.
I cannot use the export function of powerpoint to avoid this issue since I don't have the original PPT file. Additionally, I can't let Acrobat export the text into the plain text because it lost Greek letters in the original PDF. I searched a lot, but most examples only add content into headers, not the opposite direction. Additionally, if VBA can do this, one major problem might be that adding contents from headers/footers changes how the contents arrange on every page--contents will move backward and get onto latter pages. Could someone help me out on this? I also appreciate any other better ideas on extracting PDF text. |
|
#2
|
||||
|
||||
|
Headers and footers are constituent parts of Sections rather than Pages and there are potentially three headers and three footers for each section. Undoubtedly if there is more information added than will fit on the page, then text flow will cause the text to create new pages within the sections. Without access to the document, it will inevitably be a tad hit or miss, but the following should be close, given the nature of the document - however process a copy of the document! :
Code:
Sub Macro2()
Dim oSection As Section
Dim oHeader As Range
Dim oFooter As Range
Dim oRng As Range
Dim i As Integer
For i = 1 To ActiveDocument.Sections.Count
Set oSection = ActiveDocument.Sections(i)
Set oHeader = oSection.Headers(wdHeaderFooterPrimary).Range
oHeader.End = oHeader.End - 1
Set oFooter = oSection.Footers(wdHeaderFooterPrimary).Range
oFooter.End = oFooter.End - 1
Set oRng = oSection.Range
oRng.Collapse 1
oRng.Text = oHeader.Text & vbCr
Set oRng = oSection.Range
oRng.End = oRng.End - 1
oRng.Collapse 0
oRng.Text = vbCr & oFooter.Text
oSection.Headers(wdHeaderFooterPrimary).Range.Delete
oSection.Footers(wdHeaderFooterPrimary).Range.Delete
Next i
lbl_Exit:
Set oRng = Nothing
Set oFooter = Nothing
Set oHeader = Nothing
Set oSection = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Have you tried importing the pdf into Powerpoint rather than Word?
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to insert page break when copying Excel table into PP? How set headers/footers in PP like Word? | proja | PowerPoint | 0 | 09-16-2015 12:36 PM |
Headers and Footers
|
Kingsmoss | Word | 3 | 04-28-2014 02:43 PM |
Odd and Even Headers/Footers
|
sarineochaos | Word | 1 | 02-04-2014 06:15 PM |
Headers and Footers
|
teza2k06 | Word | 1 | 05-14-2013 11:07 AM |
| Headers and Footers | OverAchiever13 | Word | 1 | 05-27-2010 01:30 PM |