Jump to content

Recommended Posts

Posted

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

  • 6 months later...
Posted

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

  • 1 month later...
Posted

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.

  • 6 months later...
Posted

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 !

  • 1 year later...
Posted

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."?

 

"

  • Administrators
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...