Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2010
    Posts
    20

    How do I convert Word Documents, Spreadsheets and PDF to Base 64?

    I need to file with a government agency who requires all filings to be done in XML. They require attachments to be encoded into Base 64 and then inserted as part of the XML. The application is in ACCESS 2007 so I am using VBA. I see snippets of code on the internet that lets me encode a string, but nothing about how to encode an XLS or PDF.



    I am open to importing and then encoding within the code inside the application.....or ......converting before importing into ACCESS. Any suggestions (other than "run away")? hints? solutions? Many thanks!

  2. #2
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    You won't be able to find anything about encoding an XLS or PDF file to Base 64 because it can't be done. At least not and still HAVE an XLS or PDF file.

    By converting something to Base 64, you're actually changing the contents of the file as it's stored on the hard drive (or, in this case, your database). Once a file becomes a Base 64 file, it's no longer the file type that it was before, even if you keep the same file extension.

    One thing you CAN do, however, is convert the file to Base 64 for storage, and then convert BACK to it's regular format when you want to open it. In my opinion though, this is pretty darn stupid since a Base 64 version of a file is, by it's very nature, at least 25% larger than a native file. This means that you're artificially inflating the size of a file just so you can store it, while deflating it back to it's smaller size for usage/modification. It would be FAR better in this kind of situation to simply store the file AS IS.

    Now that I've said that, however, I'll grant that you're dealing with a government agency and, as such, making sense rarely comes into the picture. So, I'd recommend this:

    Save the file as a Base 64 file. Then, whenever you need to open it up, convert it back to it's regular format. It will be slow and (most likely) difficult to code, but it can probably be done. Just remember, that by doing this kind of conversion, you're basically attempting to bypass both how your Operating System stores and accesses files - DO NOT EXPECT THIS TO BE EASY!

  3. #3
    Join Date
    Jul 2010
    Posts
    20
    The government wants the conversion to Base64 only so the file can be submitted in an XML. We also have to send a code telling them if the orginal of the attachment is a doc, PDF, Xls etc. so they can convert back to the original.

    You indicated to "Save the file as a Base 64 file". Is this something as simple as choosing an option from the "Save As" menu? for example, I see that Excel has a "Save As Binary Excel Workbook" but don't see anything similar for Word. I assume the PDF could be coverted as an image?

  4. #4
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    OK, after seeing this, I've come to the following conclusion: You're converting to Base 64 so the file can actually be embedded within an XML document. Previously, I was under the impression that the file would be saved separately and simply linked to in the XML document. Before I go further (and possibly give you more bad advice), I do have a (few) question(s):

    What is this XML file you're talking about? Can you show me some sort of example? Basically what I'm trying to determine is: Do you want the file embedded within a separate XML document (with it's own content as well) OR are you looking to store the file as a Base 64 encoded XML file?

    As for the Document conversion question: No, there are not going to be any "Save as" options for saving something as a Base 64 file. You will need to do the conversion yourself, either inside Access or through an outside program (which are fairly easy to find, and most are free).

    P.S.
    You can safely ignore my above post. I misunderstood what you were asking.

  5. #5
    Join Date
    Jul 2010
    Posts
    20
    My bad....I didn't explain it very well. I don't have an example, the customer has simply indicated that sometimes they will need to attach a word Doc, sometimes an XML and sometimes a PDF. It has to be embedded within the same document as all the other filing information (not a separate document). The only use of Base 64 is to convert the attachment to a string so it can be included in the XML document. The XML document itself does Not have to be Base 64.

    The requirement is like this in part
    <xs:sequence>
    <xs:element name="schema_version" type="xs:string" nillable="true"/>
    <xs:element name="company_id" type="xs:string" nillable="true"/>
    <xs:element name="tariff_id" type="xs:integer" nillable="true"/>
    <xs:element name="filing_type" type="xs:integer" nillable="true"/>
    <xs:element name="attachment_data" minOccurs="1" maxOccurs="unbounded">

    Then the Base64 string version of the attachment would follow.

    Obviously I have NO clue about Base 64 before last Friday, so I'm not sure if I'm giving the information you need or not.

  6. #6
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Ah-hah, this is exactly what I was looking for!

    OK, you're going to have to do a little research because, even though I've played around with Base 64, I've never worked with embedding them inside another document. I do know, there's some sort of "Header" string that will probably need to be stuck in there somewhere to denote when a file starts.

    What you'll want to do then, is use the Encoding function in the other thread to convert your attachments. Write the first part of your XML Document, the (Base 64 converted) attachments, and then the end of your XML Document all to a file on the hard drive.

    Then you can do whatever you want with the XML Document: Save it in the database, e-mail it, whatever.

  7. #7
    Join Date
    Jul 2010
    Posts
    20
    Thanks again Rawb! just an FYI, I just talked with my customer. Their previous submission process has been to upload the attachments via an FTP site. The new process is that we'll include the "attachment" in the XML and then the government apparently will use the identifier to decode the XML "attachment" back into the native format. Not sure how that's any better than the FTP since either way the attachments are on their computers and not having to be re-entered.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-16-2010, 11:54 PM
  2. Same Form, different base query
    By Goodge12 in forum Forms
    Replies: 3
    Last Post: 01-22-2010, 11:29 PM
  3. Replies: 0
    Last Post: 10-19-2009, 11:11 AM
  4. Multiple Mailmerge documents
    By sabbo64 in forum Access
    Replies: 0
    Last Post: 09-05-2009, 04:44 AM
  5. Categorizing Word documents with Access
    By radagast in forum Access
    Replies: 0
    Last Post: 06-14-2009, 12:06 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums