Schlingel Posted September 25, 2012 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 Quote
andersa@ellenshoej.dk Posted September 28, 2012 Posted September 28, 2012 Use TUniURLFrame and put the url to the pdf in the URL property. Quote
Schlingel Posted September 28, 2012 Author Posted September 28, 2012 Use TUniURLFrame and put the url to the pdf in the URL property. Thank you Quote
ogaere Posted April 3, 2013 Posted April 3, 2013 It works in VCL mode but does not work in Web Mode Quote
Ronak Posted April 4, 2013 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 Quote
Anachronox Posted May 21, 2013 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. Quote
leon220 Posted December 11, 2013 Posted December 11, 2013 Where can I adjust the UniServerModule.LocalCachePath value, if i run your code it cannot find the pdf file Quote
adragan Posted December 12, 2013 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 ! Quote
Jean-Marc Kiener Posted January 26, 2015 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."? " Quote
Administrators Farshad Mohajeri Posted January 26, 2015 Administrators 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.