Link to home
Start Free TrialLog in
Avatar of mhanefitel
mhanefitelFlag for Türkiye

asked on

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...
Avatar of Qosai_DBA
Qosai_DBA
Flag of Palestine, State of image

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.
Avatar of mhanefitel

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of bogdan_iuly
bogdan_iuly

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin