Jump to content

Open PDF in the Browser Window


Schlingel

Recommended Posts

  • 6 months later...

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

  • 1 month later...

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

  • 6 months later...

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

  • 1 year later...

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...