How read and show a pdf saved as varbinary into SQLServer db

Hello all,
I got a SQL Server db with PDF stored in varbinary column field.
I’ve tried to use Document database field assigning name and size . When I click on link of file name nothing happens.
This is a sample of content of one Sql Server pdf stored document as I found it stored on db.

Do you know how can open and show it on a SC form ?

The content is in Binary

0x255044462D312E340A25C7EC8FA20A352030206F626A0A3C 3C2F4C656E6774682036203020522F46696C746572202F466C 6174654465636F64653E3E0A73747265616D0A789CD55DDB8E 243772C5BEF657D48BE12A039DE2FDA2B7D6CC682463341AF5 B46441033FC8BAECDA18D9D0EEC27FE01FD017EDA739788F64 445565AB53B6560301992783C143F2900C3259D93F1FC422D5 41…

See attachment for complete content of a single pdf example

one_pdf_file.zip (15.8 KB)

Hi !

Perhaps a beginning of a solution here : http://stackoverflow.com/questions/18158031/display-pdf-from-database-using-php

Hello ,thanks Herveo

Giorgio B. has helped me on suggesting a SQLSERVER adaptation in order to show binary content.
This could be helpful for someone else that has to face the same issue.

ALTER TABLE Gare
ADD BandoDiGaraName VARCHAR(254) NULL, BandoDiGaraSize int ,
CapitolatoGaraName VARCHAR(254) NULL, CapitolatoGaraSize int ,
ProgettoInviatoName VARCHAR(254) NULL, ProgettoInviatoSize int ,
OffertaInviatatName VARCHAR(254) NULL, OffertaInviatatSize int ,
ContoEconomicoName VARCHAR(254) NULL, ContoEconomicoSize int ,
ComunicAggiudicazName VARCHAR(254) NULL, ComunicAggiudicazSize int ,
Mod701Name VARCHAR(254) NULL, Mod701Size int ,
LetteraInvitoName VARCHAR(254) NULL, LetteraInvitoSize int ,
CapitolatoTecnicoName VARCHAR(254) NULL, CapitolatoTecnicoSize int

UPDATE Gare set BandoDiGaraSize = LEN([BandoDiGara]),
BandoDiGaraName=‘BANDO_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [BandoDiGara] IS NOT NULL ;
UPDATE Gare set CapitolatoGaraSize = LEN([CapitolatoGara]),
CapitolatoGaraName=‘CAPITOLATO_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [CapitolatoGara] IS NOT NULL ;
UPDATE Gare set ProgettoInviatoSize = LEN([ProgettoInviato]),
ProgettoInviatoName=‘PRG_INV_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [ProgettoInviato] IS NOT NULL ;
UPDATE Gare set OffertaInviatatSize = LEN([OffertaInviatat]),
OffertaInviatatName=‘OFF_INV_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [OffertaInviatat] IS NOT NULL ;
UPDATE Gare set ContoEconomicoSize = LEN([ContoEconomico]),
ContoEconomicoName=‘CE_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [ContoEconomico] IS NOT NULL ;
UPDATE Gare set ComunicAggiudicazSize = LEN([ComunicAggiudicaz]),
ComunicAggiudicazName=‘COMUNIC_AGG_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [ComunicAggiudicaz] IS NOT NULL ;
UPDATE Gare set Mod701Size = LEN([Mod701]),
Mod701Name=‘M701_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [Mod701] IS NOT NULL ;
UPDATE Gare set LetteraInvitoSize = LEN([LetteraInvito]),
LetteraInvitoName=‘LETT_INV_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [LetteraInvito] IS NOT NULL ;
UPDATE Gare set CapitolatoTecnicoSize = LEN([CapitolatoTecnico]),
CapitolatoTecnicoName=‘CAPITOL_TECN_COD_’+LTRIM(RTRIM(STR(IdTrack)))+’.pdf’ WHERE [CapitolatoTecnico] IS NOT NULL ;

great !
If i understand you need the file size of the pdf file (either in folder or in binary) to code someting like this ?

header(‘Content-type: application/pdf’); header('Content-Length: );

For the moment it’s enough.

I need to understand how open directly the pdf once you click over the link. At the moment it starts directly to download it.

The second needing is about how , in a grid, to substitute the standard icon and file name link with an image of icon . Names of files are sometime very long and ugly to see .

How can I reach it in a easy way ?

aaa.jpg

Automatically downloading a file can only be done on certain browsers, for a pdf to be downloaded and opened (since that is what really happens) you need to alter the generated code.
So since this is normally not supported, only download is you need to make make changes as I have done in the past (for scriptcase 7).
See here: http://www.scriptcase.net/forum/forum/scriptcase-7/discussion/6817-how-to-correctly-open-files-of-any-extension-using-document-file-name-type

In scriptcase 8 it is a bit different but you need to use similar hacks. As I said before it wont work on all browsers, chrome for example NEVER opens a file but just downloads it. It works for firefox, ie, ipad safari and some others…
This is advanced stuff so be aware of that…

Thanks RR. I will have a look.

About inserting a icon instead of default name put by SC what do you suggest ? Also Delete this record is not so nice . It could be a garbage icon too… :wink:

You can afaik only replace that by using some javascript (jquery remove) to remove/change those parts. Grab firefox and firebug and you’ll find the elements. Alternatively you can (of course) hack in the generated code to remove/change the default name.

Thanks … not so easy for me … I’m not a programmer… that’s why I use SC … ;-)))