Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpjasper da erro com o postgres e parametro #181

Closed
Danillosdd opened this issue Nov 11, 2019 · 27 comments
Closed

phpjasper da erro com o postgres e parametro #181

Danillosdd opened this issue Nov 11, 2019 · 27 comments

Comments

@Danillosdd
Copy link

Danillosdd commented Nov 11, 2019

Ao usar a bibliotca phpjasper no hello world foi com sucesso, mais ao tentar com conexão no banco e parametro dá este erro abaixo, estou utilizando o xampp e o postgres:

Fatal error: Uncaught PHPJasper\Exception\ErrorCommandExecutable: Your report has an error and couldn 't be processed!\ Try to output the command using the function output(); and run it manually in the console. in C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\src\PHPJasper.php:221 Stack trace: #0 C:\xampp\htdocs\relatorio\venda.php(29): PHPJasper\PHPJasper->execute() #1 {main} thrown in C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\src\PHPJasper.php on line 221

Meu Arquivo .php que chama a bilioteca está assim:

<?php

require __DIR__ . '/vendor/autoload.php';

use PHPJasper\PHPJasper;    

$input = '/vendor/geekcom/phpjasper/examples/venda.jasper';   
$output = '/vendor/geekcom/phpjasper/examples';
$options = [
    'format' => ['pdf'],
    'locale' => 'pt_BR',
    'params' => [5],
    'db_connection' => [
        'driver' => 'postgres',
        'username' => 'postgres',
        'password' => 'honeypot',
        'host' => 'localhost',
        'database' => 'nathusa',
        'port' => '5432'
    ]
];

$jasper = new PHPJasper;

$jasper->process(
        $input,
        $output,
        $options
)->output();
	
	
	
	
?>

@jadsonbr
Copy link
Contributor

Please use block code for a better view of your code so we can help you.

Option insert code in icon < >

@Danillosdd
Copy link
Author

alterei

@jadsonbr
Copy link
Contributor

Existe o relatório venda.jasper dentro no diretório informado ?

/vendor/geekcom/phpjasper/examples/venda.jasper

@Danillosdd
Copy link
Author

Sim,

ja tentei executar o .jrxml e com o .jasper tbm

@Danillosdd
Copy link
Author

Danillosdd commented Nov 11, 2019

Fiz a edição no texto do codigo pois com execute dava este erro, e verifiquei que a orientação era usar outuput, mais usando output ocorre o erro:

jasperstarter --locale pt_BR process "/vendor/geekcom/phpjasper/examples/venda.jasper" -o "/vendor/geekcom/phpjasper/examples" -f pdf -P 0="5" -t postgres -u postgres -p honeypot -H localhost -n nathusa --db-port 5432

@jadsonbr
Copy link
Contributor

jadsonbr commented Nov 11, 2019

Altere NOME_PARAMETRO para o nome do parâmetro correspondente no seu relatório.

E tente o seguinte:

<?php

require __DIR__ . '/vendor/autoload.php';

use PHPJasper\PHPJasper;    

$input = '/vendor/geekcom/phpjasper/examples/venda.jasper';   
$output = '/vendor/geekcom/phpjasper/examples';
$options = [
    'format' => ['pdf'],
    'locale' => 'pt_BR',
    'params' => [
         'NOME_PARAMETRO' => 5,
    ],
    'db_connection' => [
        'driver' => 'postgres',
        'username' => 'postgres',
        'password' => 'honeypot',
        'host' => 'localhost',
        'database' => 'nathusa',
        'port' => '5432'
    ]
];

$jasper = new PHPJasper;

$jasper->process(
        $input,
        $output,
        $options
)->execute();

?>

@Danillosdd
Copy link
Author

Ocorre o erro:

Fatal error: Uncaught PHPJasper\Exception\ErrorCommandExecutable: Your report has an error and couldn 't be processed!\ Try to output the command using the function output(); and run it manually in the console. in C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\src\PHPJasper.php:221 Stack trace: #0 C:\xampp\htdocs\relatorio\venda.php(31): PHPJasper\PHPJasper->execute() #1 {main} thrown in C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\src\PHPJasper.php on line 221

@Danillosdd
Copy link
Author

Obs.:

Ao visualizar no Irepot o .jrxml, pede a senha do database, talvez o erro seja porque o meu database tem senha, num sei...

@jadsonbr
Copy link
Contributor

jadsonbr commented Nov 11, 2019

Abra o seu prompt de comando e navegue até a pasta onde se encontra o jasperstarter.exe.
C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\bin\jasperstarter\bin

Execute o comando abaixo e nos mande o que retornou.

jasperstarter --locale pt_BR process "/vendor/geekcom/phpjasper/examples/venda.jasper" -o "/vendor/geekcom/phpjasper/examples" -f pdf -t postgres -u postgres -p honeypot -H localhost -n nathusa --db-port 5432

@Danillosdd
Copy link
Author

Danillosdd commented Nov 11, 2019

engraçado não está encontrado o arquivo.. ta buscando no diretorio errrado

Error: file not found: C:\vendor\geekcom\phpjasper\examples\venda.jasper

@Danillosdd
Copy link
Author

vou ter que colocar o endereço completo, está buscando neste diretorio, e nele não tem mesmo, o diretório completo seria:

C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\examples\venda.jasper

@jadsonbr
Copy link
Contributor

Correto.
Você estava tentando executar com a estrutura de diretório do linux mais você está no windows.
Terá que ajustar isso.

@Danillosdd
Copy link
Author

Danillosdd commented Nov 11, 2019

agora acusou

jasperstarter' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.

@Danillosdd
Copy link
Author

Danillosdd commented Nov 11, 2019

meu arquivo php ficou assim:

<?php

require __DIR__ . '/vendor/autoload.php';

use PHPJasper\PHPJasper;    

$input = 'C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\examples\venda.jasper';   
$output = 'C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\examples';
$options = [
    'format' => ['pdf'],
    'locale' => 'pt_BR',
    'params' => [
         'NOME_PARAMETRO' => 5,
    ],
    'db_connection' => [
        'driver' => 'postgres',
        'username' => 'postgres',
        'password' => 'honeypot',
        'host' => 'localhost',
        'database' => 'nathusa',
        'port' => '5432'
    ]
];

$jasper = new PHPJasper;

$jasper->process(
        $input,
        $output,
        $options
)->output();

?>

@Danillosdd
Copy link
Author

Danillosdd commented Nov 11, 2019

e o erro no browser ficou:

jasperstarter --locale pt_BR process "C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\examples\venda.jasper" -o "C:\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\examples" -f pdf -P NOME_PARAMETRO="5" -t postgres -u postgres -p honeypot -H localhost -n nathusa --db-port 5432

@Danillosdd
Copy link
Author

Danillosdd commented Nov 11, 2019

tinha executado o codigo no lugar errado

@Danillosdd
Copy link
Author

deu o erro no nome do parametro e corrigi

@Danillosdd
Copy link
Author

Danillosdd commented Nov 11, 2019

agora está dando:

Error filling reportByte data not found at: logo-nathusa2.jpg.

@Danillosdd
Copy link
Author

a imagem está no ireport, tem que passar parametro de imagem no arquivo php?

@jadsonbr
Copy link
Contributor

O diretório da imagem você deve definir no resources ou passar o caminho absoluto.

@Danillosdd
Copy link
Author

Danillosdd commented Nov 12, 2019

estava usando o windows passei pro linux ao ir na pasta do jasperstar e executar o comando:

./jasperstarter --locale pt_BR process "D:\Arquivos de Programas\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\examples\venda.jasper" -o "D:\Arquivos de Programas\xampp\htdocs\relatorio\vendor\geekcom\phpjasper\examples" -f pdf -P parametroprincipal="5" -t postgres -u postgres -p @Mega2019 -H localhost -n nathusa --db-port 5432

sudo: ./jasperstarter: comando não encontrado

como é a execução no linux?

@Danillosdd
Copy link
Author

Consegui resolver a situação acima, reinstalando o composer, e mandando instalar o phpjasper de novo.

@Danillosdd
Copy link
Author

Danillosdd commented Nov 12, 2019

Só que agora ao executar o comando

./jasperstarter --locale pt_BR process "D:\Arquivos de Programas\xampp\htdocs\relatorio2\vendor\geekcom\phpjasper\examples\venda.jasper" -o "D:\Arquivos de Programas\xampp\htdocs\relatorio2\vendor\geekcom\phpjasper\examples" -f pdf -P parametroprincipal="5" -t postgres -u postgres -p honeypot -H localhost -n nathusa --db-port 5432

Retorna:

Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
	at de.cenote.tools.classpath.ApplicationClasspath.add(ApplicationClasspath.java:75)
	at de.cenote.tools.classpath.ApplicationClasspath.add(ApplicationClasspath.java:65)
	at de.cenote.tools.classpath.ApplicationClasspath.addJars(ApplicationClasspath.java:134)
	at de.cenote.tools.classpath.ApplicationClasspath.addJarsRelative(ApplicationClasspath.java:151)
	at de.cenote.jasperstarter.App.processReport(App.java:178)
	at de.cenote.jasperstarter.App.main(App.java:109)

@Danillosdd
Copy link
Author

Reintalei o Java como sdkman, e deu certo agora, gerou o pdf

@Danillosdd
Copy link
Author

Danillosdd commented Nov 12, 2019

a dúvida agora.

creio que seja a última...rs..

porque pra conseguir gerar o pdf eu estou tendo que executar o comando na pasta jasperstarter pra gerar o relatório..

no arquivo.php com o comando execute da erro de output..
no arquivo.php com output ele gera este codigo:

./jasperstarter --locale pt_BR process "D:\Arquivos de Programas\xampp\htdocs\relatorio2\vendor\geekcom\phpjasper\examples\venda.jasper" -o "D:\Arquivos de Programas\xampp\htdocs\relatorio2\vendor\geekcom\phpjasper\examples" -f pdf -P parametroprincipal="5" -t postgres -u postgres -p honeypot -H localhost -n nathusa --db-port 5432

que tenho que executá-lo na pasta do

/opt/NetMake/v9/wwwroot/relatorio2/vendor/geekcom/phpjasper/bin/jasperstarter/bin

pra gerar o pdf pelo terminal.

Como faço pra gerar o pdf direto pelo arquivo.php

@Danillosdd
Copy link
Author

E Desde já te Agradeço @jadsonbr

@Danillosdd
Copy link
Author

Danillosdd commented Nov 12, 2019

Com as orientações do @jadsonbr deu certo, era questão de permissão das pastas...

Vlw... Demais.... Pela Força.....

*RESOLVIDO

Eu usava antes a bilioteca phpjaspexml, https://github.com/SIMITGROUP/phpjasperxml mais ela tinha muitos problemas de implementação e subreport, com essa via ficar bem melhor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants