• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4587
  • Last Modified:

Loading Blob field from database to PDF using stream.

Hi,

       I have a blob field in MS SQL 2005 database. In that field i store pdf files. I want these PDF files to be viewed by the users.  When i load these files from database 0 DO NOT WANT TO SAVE THEM to disk and then viewed.  I want these files to be viewed by the users directly from the database without saving to disk.(Using steams will work for me)
        I want working examples that shows me how to accomplish this.
        I use BDS 2006, Win XP and SDAC Component to access SQL Server 2005.
        Thans in advance...
0
mhanefitel
Asked:
mhanefitel
1 Solution
 
Qosai_DBACommented:
Hi mhanefitel,
  The Example below Show how to load a BLOB (Picture) from Oracle database to a Delphi form
  It may help you ....

procedure TfrmMain.vtTreeFocusChanged(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex);
var NodeData: ptrStdNode;
    bS  : TADOBlobStream;
    Pic : TJpegImage;

    v_PicsPath: String;
begin
  try
    NodeData:= Sender.GetNodeData(Node);

    frmMain.Image1.Visible:= True;

    dmfConn.qrImage.Close;
    dmfConn.qrImage.SQL.Clear;
    dmfConn.qrImage.SQL.Add(
      'SELECT STUDNUM, STUDIMAGE     ' + #13 +
      'FROM   k_StdImages            ' + #13 +
      'WHERE  STUDNUM = :StdNum      ');
    dmfConn.qrImage.Parameters[0].Value:= NodeData.StdNo;
    dmfConn.qrImage.Open;

    if(dmfConn.qrImage.RecordCount = 0)then
      begin
        v_PicsPath:= Copy(ParamStr(0), 1, Length(ParamStr(0)) - 13) + 'Pics\';
        frmMain.Image1.Picture.LoadFromFile(v_PicsPath + 'NoImage.jpg');
      end
    else
      begin
        bS := TADOBlobStream.Create(TBlobField(dmfConn.qrImage.Fields[1]), bmRead);
        try
          bS.Seek(JpegStartsInBlob(TBlobField(dmfConn.qrImage.Fields[1])), soFromBeginning);
          Pic:=TJpegImage.Create;
          try
            Pic.LoadFromStream(bS);
            frmMain.Image1.Picture.Graphic:=Pic;
          finally
            Pic.Free;
          end;
        finally
          bS.Free
        end;
      end;
  except
  end;
end;

Regards,
Khalid.
0
 
mhanefitelAuthor Commented:
You are using TJpegImage component but there is no any pdf component in delphi like TJpegImage. I need to use olecontainer to do this but 1 do not know how to do this
Thanks in advance...
0
 
bogdan_iulyCommented:
Hello,

You could go to Component -> Import ActiveX Control and select Acrobat Control for ActiveX (or something like this, it depends on you Adobe Reader version) to import a TPdf component, but with no use because it doesn't work with streams.

The only solution would be to save your blob to a FileStream and then open the file with TPdf or ShellExecute.
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now