How to convert PDF to BLOB datatype

tutorial
uiautomation
studio
uipath

#1

Hi ,

I want to insert PDF to database table. Can anyone suggest a way to convert PDF to BLOB datatype to insert into database.

Thanks and Regards,
M.Srikanth


#2

@srikanth999, if you can live with Base64 as an encoding for your PDF, please see the attached workflow.

You will have to adapt it for your purposes. Although there is a Select File dialog, I have not split the file name from its extension, which you will probably want to do if you use any other file type besides PDF (which you can).

This workflow simply displays the Base64-encoded file in a Message Box, so you will have to process it yourself.

For testing purposes, I’ve included a compiled AutoHotKey script ‘base64decFile.exe’ to decode the result. I have uncommented the line as directed in ‘base64decFile.ahk’ so there will be file called ‘file_encoded’ (no extension). Run the .exe file, and you will see a file called ‘give_me_the_correct_extension’. If you’re encoding a PDF, just change the name to ‘give_me_the_correct_extension.pdf’, or rename it as you see fit.

WARNING: Although the attached ‘64Test.docx’ processes just fine, as you can see by examining or testing ‘file_encoded’, the Message Box activity chokes on it. Write it to a file instead, or add it to your database, or whatever needs to be done.

Or, you can simply copy the contents of ‘file_encoded’ to the input box at https://www.base64decode.org/. Try it with the included ‘ahk.png’, and you will get ‘decoded.png’.

This uses Crypt32.dll. I’m sure this can easily be done in VB.NET, but, well, here it is.

Also included are a ‘64Test.docx’ (see warning above) and ‘ahk.pdf’ for testing.

If this proves useful, I’ll add some functionality to deal with the file extension/type.

Please let me know if anything doesn’t work as I describe.
Base64Enc_Dec.zip (628.1 KB)

EDIT: If there is interest, I can try to come up with encrypt/decrypt functionality for the following types, using libcrypt.ahk:

ASCII85
Base64
BinHex
Caesar
CRC32
Div2
HMAC
MD2
MD4
MD5
nnnik21
RC4
ROT
RSHash
SecureSalted
SHA-1
SHA-256
SHA-384
SHA-512
TEA
URI
Vigenere
VxE
XOR

Regards,
burque505


#3

#burque505,
Thank you so much for your response . But when I am trying to load the file that you uploaded it is showing the following error


#4

@srikanth999, it appears from the output that you may not have UiPath.Script.Activities installed. In my experience you may have difficulty finding them in the package sources, especially after a recent update. You will need to have “Run Auto Hot Key Script” available from your ‘Activities’ panel, i.e.:

ScriptActivities

or it isn’t ever going to run.

I’m attaching several versions of UiPath.Script.Activities, as one or more of them is liable not to function with your setup.
Regards,
burque505

ScriptActivities.zip (1.1 MB)


#5

For me that package is not showing. Can you suggest a way of fixing it.


#6

@srikanth999, package management is not always straightforward. You will need to unzip the archive from my post above. You may have to try several folders or sources before it works.
It appears you have not installed UiPath.Script.Activities.

  1. See ddpadil’s link regarding package management, and the post below it.
    2( There may or may not be a ‘packages folder as shown’:
    “C:\Users\<username>\AppData\Local\UiPath\packages”. Try to put the packages in there, and find one that works when you install it.
  2. However, you may get the package from nuget (see ddpadil’s post) after you configure your sources, and then it may show up in C:\Users\\AppData\Local\Temp\nuget\UiPath.Script.Activities\<some number>.
  3. You may also try making a Packages folder somewhere in your Documents directory, put the packages in there, and configure that as a source.
    Obviously, put your own user name in the path where <yourusername> is, and the actual nupkg filename where <some number> is.
    I have had to try all of these at one time or another to get Script.Activities to install.
    Regards,
    burque505

#7

Hi Burque505,

Is there any way we can read pdf image(scanned image) and convert the same into base64 string data…

Thanks,
Sreeman.


#8

Hi Sreeman,

Here’s a workflow that functions. Let me know if you have trouble
adapting it.

For now, you can pick any PDF in the same directory as the script, but
the encoded and then decoded file is going to be decoded.pdf.

The AHK script can easily be converted to a single file, calling
different functions at different times in the workflow.

You can look at file_encoded during processing to show that it is, in
fact, base64 encoded.

Please note I have had a great deal of trouble with scripts that
aren’t in their location of creation. If I were you I’d extract the ZIP
file to a directory called PDFencode for best possible results. If you
get errors related to file location, you’ll have to fiddle with the
directory structure.

No guarantees here, of course. It works fine for me, however.

Regards,

Winter

PDFencode.zip (9.56 KB)


#9

@sreekolluri, here’s a more practical workflow.

  1. I advise extracting the workflow to a directory with the same name is the zip archive (your mileage may vary).
  2. Select any file type from the dialog box.
  3. The AHK script will split the extension from the file, and use it later.
  4. The file you selected will be encoded as base64 (there is a message box that will stop the thread and allow you to examine the encoded file).
  5. Then, the same file will be decoded from base64 so you can compare it. The file will be output as “decoded.” & the file extension. So, if you encode ahk.png, which is included, the output will be “decoded.png”. Likewise, if you choose “Anyfile.pdf”, the output will be “decoded.pdf”.
  6. Careful! The script will remove any decoded.(chosen extension) files, so process them before re-running the script!

The included AutoHotkey script has the functions “Split(SPLITFILE)”, “Base64encode(File)”, and “FileRead(FILEDATA, file_encoded)”. The last function is the decoder.

Although the same AHK script is called three times here, a different function is called each time. You can of course split the script into several if it suits your purposes. You don’t have to use all the functions of the script, just whatever one you need.

Regards,
burque505

64EncDec.zip (11.8 KB)


#10

Thank you very much burque505…

I will take a look at it and let you know if i need any clarifications…

Thanks,
Sreeman.