Schlingel Posted September 25, 2012 Share Posted September 25, 2012 Hello I want to open some PDF files in the browser. Can someone give me an example-code? Is this possible with XE2 Prof. or do I need chargeable components? Thank you very much Link to comment Share on other sites More sharing options...
andersa@ellenshoej.dk Posted September 28, 2012 Share Posted September 28, 2012 Use TUniURLFrame and put the url to the pdf in the URL property. Link to comment Share on other sites More sharing options...
Schlingel Posted September 28, 2012 Author Share Posted September 28, 2012 Use TUniURLFrame and put the url to the pdf in the URL property. Thank you Link to comment Share on other sites More sharing options...
ogaere Posted April 3, 2013 Share Posted April 3, 2013 It works in VCL mode but does not work in Web Mode Link to comment Share on other sites More sharing options...
Ronak Posted April 4, 2013 Share Posted April 4, 2013 var fPdf:String;begin fPdf= 'abc.pdf'; URLFrame.URL := UniServerModule.LocalCacheURL +fPdf; // Display // or UniSession.SendFile(UniServerModule.LocalCachePath +fPdf); // open in browser (depends on browser settings)end Link to comment Share on other sites More sharing options...
Anachronox Posted May 21, 2013 Share Posted May 21, 2013 I have one alternative, not using other components, and opening PDF in new window automatically.Here is an example of my procedure (save data to stream, save stream to disk, publish PDF using localcache and open new browser window using javascript) : procedure OpenDocumentByURL(Data: TBytes; FileName: string); var Stream: TMemoryStream; begin if Length(Data) > 0 then begin Stream := TMemoryStream.Create; try FileName := UniServerModule.LocalCacheURL + FileName; Stream.WriteBuffer(Data[0], Length(Data)); Stream.SaveToFile(FileName); finally Stream.Free; end; UniSession.AddJS('window.open(' + QuotedStr(FileName) + ')'); end; end; But the principle is just opening required document from published folder by browser itself using javascript.You just have to allow opening new windows in browser for the first time. Link to comment Share on other sites More sharing options...
leon220 Posted December 11, 2013 Share Posted December 11, 2013 Where can I adjust the UniServerModule.LocalCachePath value, if i run your code it cannot find the pdf file Link to comment Share on other sites More sharing options...
adragan Posted December 12, 2013 Share Posted December 12, 2013 When you create the pdf you put it in UniServerModule.LocalCachePath + pdf_name.pdf When you send it or put it in a window you adress it with : UniServerModule.LocalCacheURL + pdf_name.pdf You don't adjust paths. Application deals with it automatically. All you can do is send the whole cache file ( for all users ) in the UniserverModule.CacheFolder:= .... somewhere To change it at application start use the UniserverModule.OnBeforeInit event. After application start you're done ! Link to comment Share on other sites More sharing options...
Jean-Marc Kiener Posted January 26, 2015 Share Posted January 26, 2015 I have one alternative, not using other components, and opening PDF in new window automatically. Here is an example of my procedure (save data to stream, save stream to disk, publish PDF using localcache and open new browser window using javascript) : procedure OpenDocumentByURL(Data: TBytes; FileName: string); var Stream: TMemoryStream; begin if Length(Data) > 0 then begin Stream := TMemoryStream.Create; try FileName := UniServerModule.LocalCacheURL + FileName; Stream.WriteBuffer(Data[0], Length(Data)); Stream.SaveToFile(FileName); finally Stream.Free; end; UniSession.AddJS('window.open(' + QuotedStr(FileName) + ')'); end; end; But the principle is just opening required document from published folder by browser itself using javascript. You just have to allow opening new windows in browser for the first time. Is there a possibelity to avoid the "You just have to allow opening new windows in browser for the first time."? " Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted January 26, 2015 Administrators Share Posted January 26, 2015 Is there a possibelity to avoid the "You just have to allow opening new windows in browser for the first time."? Probably no. If there was a way to bypass this, spammers could fill your desktop with all sort of ads and spams. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now