anonymous Log in
Search
Recents:
v3.0
gxenglish-l
Saving Blob from Database to .pdf file
10/02/14 08:16

Jannie Louw

Replies: 3

I am trying to read a blob (which is a .pdf blob) from the database and save
it in a .pdf file on the disk using the following program:
for each
where BlobLoadNo = &WIPNo
&BlobPath = BlobLoadBlob
// Defined as Path e.g. Character(200)
&i = dfropen(&BlobPath,8192,"")
// Opening the temporary file with length of 8192.
&i = dfrnext( )
&i = dfrgTxt(&ContentStr)
// Reading the Contents of the file in a LongVarChar(1M)
&i = dfrclose()

&i = dfwopen("C:\Temp\PDF1.pdf",,0) //
Saving the contents as a pdf file. In the real program this a variable
which fives the path and file name
&i = dfwptxt(&ContentStr)
// Saving the string
&i = dfwnext( )
&i = dfrclose()
when none
&Ind = "N"
Endfor

When I run the program I get an error -1 for the &i =
dfropen(&BlobPath,8192,"") statement. I suspect this is because the file is
a temporary file which is still open with the &BlobPath = BlobLoadBlob
statement.

I also tried to read the Blob in a blob variable and save it to the .pdf
file using:
for each
where BlobLoadNo = &WIPNo and BlobLoadDocTypeNo = &DocTypeNo
&fileblob = BlobLoadBlob

&FileName = 'C:\Temp\PDF1.pdf'
&i = dfwopen(&FileName,,,0)
&i = dfwptxt(&fileblob)
&i = dfwnext()
&i = dfrclose()
when none
&Ind = "N"
Endfor
I then get a "Object reference not set to an instance of an object" error
for the &i = dfwptxt(&fileblob) statement. I also get this error for the
first program if I step to the &i = dfwptxt(&fileblob) statement

I am able to read and display the blob using:
for each
where BlobLoadNo = &WIPNo
&fileblob = BlobLoadBlob
when none
&Ind = "N"
endfor
If &Ind = "Y"
&httpresponse.AddFile(&fileblob)
&httpresponse.AddHeader('Content-Type','application/pdf')
EndIf
Any help will be appreciated
Replies

leandro79337933

10/02/14 11:29
Hi Jannie, I'd recommend you to read this technical wiki first: http://wiki.gxtechnical.com/commwiki/servlet/hwiki?Blob+data+type, When you've done, getting a blob file to work is as simple as this: For each // TableWithBLOB Where BlobLoadNo = &WIPNo &BlobPath = BlobLoadBlob Endfor Where &BlobPath is longvarchar(9999). If you want to send an email with this BLOB as attachment: &msgMail.Attachments.Add(&BlobPath) Regards, On Mon, Feb 10, 2014 at 5:09 AM, Jannie Louw

Jannie Louw

11/02/14 13:34
Hi Leandro Thanks for the reply I did read the article I still do not know how to save the Blob as a pdf file, without displaying it. (I do know how to display it). I also do not want to send it as an attachment in an email. I want to save a series of Blobs in a specified folder, each with a specified name, without displaying the Blob in a web browser. I already have the ability to display a single blob in the web browser. I tried to the following: for each where BlobLoadNo = &WIPNo &BlobPath = BlobLoadBlob print printBlob // Name of printBlock where &Blobload is displayed endfor Where I display &BlobPath in the Layout of the procedure and I declare the procedure as a Main program (e.g. True) and the Call protocol as 'Internal' and the Report Output as 'Only to File'. The pdf file is created, but only the path to the temporary file in \Web folder is displayed. Any other suggestions? Regards

Jannie Louw

11/02/14 16:18
Hi Leandro Thanks. I got it to work with slight modifications e.g. &f.Copy("C:\temp\test.pdf") I really appreciate your help Regards Jannie Louw


Back to gxenglish-l