Skip to content

mobius1qwe/classes-uteis

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xPlat.OpenPDF

xPlat.OpenPDF

Class for easy downloading and viewing of PDF files on Android and iOS.

Installation

Just register in the Library Path of your Delphi the path of the SOURCE folder of the library, or if you prefer, you can use Boss (dependency manager for Delphi) to perform the installation:

boss install github.com/adrianosantostreina/xPlat.OpenPDF

⚠ Requirements

Android: It is necessary to adjust the permissions in the app so that it is possible to read and write files on the device

AndroidManifest.xml
      android:grantUriPermissions="true"
      android:requestLegacyExternalStorage="true"
Like this
    <application android:persistent="%persistent%"
      android:restoreAnyVersion="%restoreAnyVersion%"
      android:label="%label%"
      android:debuggable="%debuggable%"
      android:largeHeap="%largeHeap%"
      android:icon="%icon%"
      android:theme="%theme%"
      android:hardwareAccelerated="%hardwareAccelerated%"
      android:resizeableActivity="false"

      android:grantUriPermissions="true"
      android:requestLegacyExternalStorage="true">

and this permissions

ReadExternalStorage
WriteExternalStorage

It's recommend using MobilePermissions component Mobile Permissions

or install by Get It Package Manager into your Delphi IDE.

Mark Secure File Sharing on Project > Options > Application > Entitlement List like a image below. (Android Profile)

xPlat.OpenPDF

⚡️ Quickstart

Create a new project

  • Drag a TButtom onto form
  • Drag a TMobilePermissions onto form
  • In the OnCreate event of the Form type
procedure TForm1.FormCreate(Sender: TObject);
begin
  MobilePermissions1.Dangerous.ReadExternalStorage  := True;
  MobilePermissions1.Dangerous.WriteExternalStorage := True;

  MobilePermissions1.Apply;
end;

If you don't using then MobilePermissions component, don't forget to setting a permissions to ReadExternalStorage and WriteExternalStorage using your method.

It may be necessary to add the source path of the MobilePermissions component to the Library Path under Project > Options.

Use

Declare xPlat.OpenPDF in the Uses section of the unit where you want to make the call to the class's method.

uses
  xPlat.OpenPDF,
procedure TForm1.Button1Click(Sender: TObject);
var
  LFile : string;       //File that will be open
begin
  LFile  := 'Your_PDF_File.pdf';
  TOpenPDF.Open(LFile);
end;

Other use

In this example we are using a Switch component to set if we go to download file or use a local file (Project > Deployment)

procedure TForm1.Button1Click(Sender: TObject);
var
  LStream        : TStringStream;
  LSharedPath    : String;       //Shared path on Android
  LPathDocs      : string;       //Documents path on Android
  LFile          : string;       //File that will be open
  LCompletePath  : string;
begin
  LFile  := 'printid.pdf';

  {$IFDEF MSWINDOWS}
    //It's possible set size and position for form
    TOpenPDF.FormHeight   := 800;
    TOpenPDF.FormWidth    := 600;
    TOpenPDF.FormPosition := TFormPosition.DesktopCenter;

    //If you are going to use it on Windows, you need to set the full path
    LSharedPath := 'C:\Temp' + PathDelim + 'tmp' + PathDelim;
    ForceDirectories(LSharedPath);
    LCompletePath := Format('%s%s', [LSharedPath, LFile]);
  {$ENDIF}

  {$IFDEF IOS}
    TOpenPDF.FormHeight   := Self.ClientHeight;
    TOpenPDF.FormWidth    := Self.ClientWidth;
    TOpenPDF.FormPosition := TFormPosition.ScreenCenter;
  {$ENDIF}

  if not swtOpenLocalFile.IsChecked then
  begin
    //Download file
    LStream  := TStringStream.Create;
    idHttp.Get(Format('%s%s',['https://www.controlid.com.br/userguide/', LFile]), LStream);

    LStream.Position := 0;
    {$IFDEF MSWINDOWS}
      LStream.SaveToFile(LCompletePath);
    {$ELSE}
      LStream.SaveToFile(Format('%s%s', [TPath.GetSharedDownloadsPath + '/', LFile]));
    {$ENDIF}
    LStream.DisposeOf;
  end;

  {$IFDEF MSWINDOWS}
    TOpenPDF.Open(LCompletePath);
  {$ELSE}
    TOpenPDF.Open(LFile);
  {$ENDIF}
end;

Documentation Languages

English (en)
Português (ptBR)

⚠️ License

xPlat.OpenPDF is free and open-source library licensed under the MIT License.

About

Classes Úteis

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Pascal 100.0%