locked
Using VB to Open a PDF file RRS feed

  • Question

  • We are using an Access 2010 database with Windows 7.  What I need to do is to open a pdf file, select all in the pdf file and copy the contents. Then I want to paste that information into a notepad file and save it.  We have about 70 files that I need to loop through and perform this operation.  Any assistance would be greatly appreciated.
    Monday, March 12, 2018 9:33 PM

All replies

  • Hi,

    Are you talking about fillable PDF forms? If so, are you saying you just want to copy the field data?

    Monday, March 12, 2018 9:58 PM
  • Hi Arkansas Lady,

    I try to check your requirement and find that your requirement is more related with VBA instead of Access Database.

    You may try to refer the example below and create your own modified code to fulfil your requirement.

    Sub convertpdf2()
    
    Dim AcroXApp As Acrobat.AcroApp
    Dim AcroXAVDoc As Acrobat.AcroAVDoc
    Dim AcroXPDDoc As Acrobat.AcroPDDoc
    Dim Filename As String
    Dim jsObj As Object
    Dim NewFileName As String
    
    Filename = "C:\Documents and Settings\xxx\Desktop\file01.pdf"
    NewFileName = "U:\file.txt"
    
    Set AcroXApp = CreateObject("AcroExch.App")
    'AcroXApp.Show
    
    Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
    AcroXAVDoc.Open Filename, "Acrobat"
    
    Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
    
    
    Set jsObj = AcroXPDDoc.GetJSObject
    
    
    jsObj.SaveAs NewFileName, "com.adobe.acrobat.plain-text"
    
    
    AcroXAVDoc.Close False
    AcroXApp.Hide
    AcroXApp.Exit
    
    End Sub 

    Reference:

    VBA to convert .pdf to .txt

    Let me know, If I misunderstand something in your above description, I will try to correct myself and try to provide further suggestions.

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 13, 2018 1:46 AM
  • If you can use VB .Net instead of VBA then use empira/PDFsharp: A .NET library for processing PDF. It is very popular.

    Note that technically speaking there is no such thing as a "Notepad file". Notepad reads and writes plain text files but Notepad does nothing special to the files.



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, March 13, 2018 4:52 AM
  • Hi Arkansas Lady,

    The following MSDN Sample might be of help, its based on a free pdf library that supports vb.net, c#, asp.net etc., you can have a check. I attach the example code here for your reference, it's in c#, I think you can manage to convert it to vb.net.

    //Create a pdf document. 
                PdfDocument doc = new PdfDocument(); 
                doc.LoadFromFile(@"../../New Zealand.pdf"); 
     
                StringBuilder buffer = new StringBuilder(); 
                IList<Image> images = new List<Image>(); 
     
                foreach (PdfPageBase page in doc.Pages) 
                { 
                    buffer.Append(page.ExtractText()); 
                    foreach (Image image in page.ExtractImages()) 
                    { 
                        images.Add(image); 
                    } 
                } 
     
                doc.Close(); 
     
                //save text 
                String fileName = @"../../TextInPdf.txt"; 
                File.WriteAllText(fileName, buffer.ToString()); 
     
                //save image 
                int index = 0; 
                foreach (Image image in images) 
                { 
                    String imageFileName 
                        = String.Format(@"../../Image-{0}.png", index++); 
                    image.Save(imageFileName, ImageFormat.Png); 
                } 
     

    Check the sample here for more information:

    https://code.msdn.microsoft.com/Extracting-text-and-image-d47ac957

    Tuesday, March 13, 2018 9:05 AM