Results 1 to 12 of 12
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PDF saveAS text? (Acrobat)

    The code below is my best attempt to dat to convert a PDF file to a text-based (DOC, RTF, TXT etc) form.
    In Acrobat I can open a PDF file and choose File, SaveAs, selecting text.
    I can't work out the integer value to plop in the <font color=red>pdCodeFile.Save</font color=red> statement, and would appreciate help.
    My little TEST macro was attempting to try all reasonable values. a.k.a. the shotgun approach.

    <pre>Function DumpMyFile(lng As Long, strFile As String)
    Dim AcroApp As Acrobat.CAcroApp
    'Start Acrobat in the background
    Set AcroApp = CreateObject("AcroExch.App")
    AcroApp.Show

    Dim avCodeFile As CAcroAVDoc
    Set avCodeFile = CreateObject("AcroExch.AVDoc") 'This is the code file
    Dim avFormCapture As CAcroAVDoc
    Set avFormCapture = CreateObject("AcroExch.AVDoc") 'This will be each jpg in turn

    'Open the already created code file
    avCodeFile.Open "e:PDFer011.pdf", "Code File"
    Dim pdCodeFile As CAcroPDDoc
    Set pdCodeFile = avCodeFile.GetPDDoc

    <font color=red>pdCodeFile.Save</font color=red> lng, strFile
    pdCodeFile.Close
    avCodeFile.Close 0

    'Exit Acrobat
    AcroApp.Exit
    Set AcroApp = Nothing
    Set avCodeFile = Nothing
    Set pdCodeFile = Nothing
    Set avFormCapture = Nothing
    End Function
    Sub TESTDumpMyFile()
    Dim lng As Long
    For lng = 1 To 255
    Call DumpMyFile(lng, "e:erase" & Trim(Str(lng)))
    Next lng
    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: PDF saveAS text? (Acrobat)

    The Save method is not intended for save as a text file. The available constants can be looked up in the Object Browser (F2):
    0 = PDSaveIncremental (Write changes only)
    1 = PDSaveFull (Write the entire file)
    2 = PDSaveCopy (Write a copy of the file into the file)
    4 = PDSaveLinearized (Save the file in a linearized fashion)
    8 = PDSaveWithPSHeader (Writes a PostScript header as part of the saved file)
    16 = PDSaveBinaryOK (Specifies that it's OK to store in binary file)
    32 = PDSaveCollectGarbage (Remove unreferenced objects, often reducing file size)

    As far as I can tell, saving as a text file is not exposed in the VBA object model, you'll probably need JScript to do that.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF saveAS text? (Acrobat)

    > the Object Browser (F2):
    Thanks, Hans. I saw these but Object Browser is not my strong point.

    I had not contemplated that the various saveAs options available to the end user would NOT be available in the appliaction object. Can this mean that MSoft/VBA is actually better than i had at first thought? (grin!)

    I guess I should follow the thread at <post:=397,949>post 397,949</post:>?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: PDF saveAS text? (Acrobat)

    I still don't have the slightest idea what Windows Management Instrumentation (WMI) is <img src=/S/grin.gif border=0 alt=grin width=15 height=15>, but I doubt it has any bearing on saving PDF files as text files.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF saveAS text? (Acrobat)

    > I doubt it has any bearing on saving PDF files as text files.

    Mebbe not, but I have this vague feeling that your helpful reference to Script Center might give me enough power to automate the batch process of converting PDF to text, something I was struggling to achieve in my sample of VBA code.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF saveAS text? (Acrobat)

    These two little scripts tell me that I might be able to achieve my goals next time I meet Acrobat (Wednesday)
    <pre>Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Add()
    objWord.FileSearch.FileName = "*.doc"
    objWord.FileSearch.LookIn = "H:"
    objWord.FileSearch.SearchSubfolders = True
    objWord.FileSearch.Execute
    For Each objFile in objWord.FileSearch.FoundFiles
    Wscript.Echo objFile
    Next
    objWord.Quit</pre>


    and

    <pre>Set objWord = CreateObject("Word.Application")
    objWord.Caption = "Test Caption"
    objWord.Visible = True

    Set objDoc = objWord.Documents.Add()
    Set objSelection = objWord.Selection

    objSelection.Font.Name = "Arial"
    objSelection.Font.Size = "18"
    objSelection.TypeText "Network Adapter Report"
    objSelection.TypeParagraph()

    objSelection.Font.Size = "14"
    objSelection.TypeText "" & Date()
    objSelection.TypeParagraph()
    objSelection.TypeParagraph()

    objSelection.Font.Size = "10"

    strComputer = "."

    objSelection.Font.Bold = True
    objSelection.TypeText "ARP Always Source Route: "
    objDoc.SaveAs("H:testdoc.doc")
    objWord.Quit</pre>


  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: PDF saveAS text? (Acrobat)

    I'm afraid I don't see how this is going to help you convert PDF files to another format...

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF saveAS text? (Acrobat)

    I'm not certain either, but I've never had success with Sendkeys, so somehow I was optimistic that scripting might achieve what VBA can not. You're possibly going to tell me that it is the same object exposed in both cases, in which case I've just treated myself to a bit of free R&D (well, actually I amassed a dozen or so useful examples of scripts ....)

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: PDF saveAS text? (Acrobat)

    VBScript is basically the same as VBA, it won't let you do more with a PDF file than VBA.

  10. #10
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,947
    Thanks
    0
    Thanked 204 Times in 185 Posts

    Re: PDF saveAS text? (Acrobat)

    Hi Chris,

    Perhaps you should consider using Ghostscript, which has procedures for converting pdfs to postscript and postscript to ascii, via the simple expedient of batch files. Doubtless vba could be coaxed to run those, or ghostscript directly with a similar syntax to that of the batch files.

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF saveAS text? (Acrobat)

    > VBScript is basically the same as VBA,
    (SIGH)
    So my only home-grown hope appears to be that Sendkeys will function as advertised on the client system.

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF saveAS text? (Acrobat)

    > Perhaps you should consider using Ghostscript,
    Thanks, I have d/l a copy and will check it out Wednesday.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •