How to generate firemonkey android PDF report?

Asked

Viewed 3,378 times

0

I need to generate a PDF report on firemonkey android, I would like component suggestions or ways to do it.

  • 1

    I indicated a component in the answer, anyway I suggest you read the rules for publishing questions on Sopt. This is because, request for suggestions or very general questions are not the focus of the site. But what you need (technically), we are there!

3 answers

2

One way to work with mobile reports is to leave everything to the server. By the way, this is good practice for everything in the mobile world.

Whenever you need something that requires processing, send it to your server to do and get the return ready.

In the case of reports, you can create a webservice. For example:

Monta_report(starting date, final date)

You call this webservice from your app... it mounts the report, saves it in PDF and returns a URL (e.g., your system.com.br/report?id=2121212) to be opened in mobile.

Another benefit of working like this is that you don’t depend on the platform the user is using (Android or iOS)... always works!

I hope I’ve helped.

0

I suggest the Fastreport, because a basic version already accompanies the Delphi and the complete (paid) versions are spectacular.
Fastreport FMX

-1


One option I’ll find is this.

Necessary uses

Androidapi.JNI.JavaTypes,
Androidapi.JNI.Net,
Androidapi.Helpers,
System.IOUtils,
Androidapi.JNI.GraphicsContentViewText;

to process that generate the pdf

procedure gerar_pdf;
var
    Document: JPdfDocument;
    PageInfo: JPdfDocument_PageInfo;
    Page: JPdfDocument_Page;
    Canvas: JCanvas;
    Paint: JPaint;
    FileName: string;
    OutputStream: JFileOutputStream;
    Intent: JIntent;
begin

    //cria o documento
    Document := TJPdfDocument.JavaClass.init;

    try

        //cria a página  
        PageInfo := TJPageInfo_Builder.JavaClass.init(100, 150, 1).create;
        Page := Document.startPage(PageInfo);

        Canvas := Page.getCanvas;
        Paint := TJPaint.JavaClass.init;

        Paint.setARGB($FF, 0, 0, $FF);
        Canvas.drawText(StringToJString('Página 1'), 10, 50, Paint);

        Document.finishPage(Page);

        //gera o arquivo  pdf
        FileName := TPath.Combine(TPath.GetSharedDocumentsPath, 'arquivo.pdf');
        OutputStream := TJFileOutputStream.JavaClass.init(StringToJString(FileName));

        try
        Document.writeTo(OutputStream);
        finally
            OutputStream.close;
        end;

    finally
        Document.close;
    end;

    // inicia a visualização do pdf
    Intent := TJIntent.JavaClass.init;
    Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
    Intent.setDataAndType(FileNameToUri(FileName), StringToJString('application/pdf'));
    Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NO_HISTORY or TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP);
    SharedActivity.StartActivity(Intent);

end;

this function is also required

function FileNameToUri(const FileName: string): Jnet_Uri;
var
    JavaFile: JFile;
begin
    JavaFile := TJFile.JavaClass.init(StringToJString(FileName));
    Result := TJnet_Uri.JavaClass.fromFile(JavaFile);
end;

In the link there is an example in practice.

https://github.com/AlessandroMartini/Delphi-Android-GeraPDF

Browser other questions tagged

You are not signed in. Login or sign up in order to post.