0

I require your help because, I want execute a FPDF php file from my local files in Angular 8 directory,

My file I search to execute is pdf.php, this file is inside the directory make-bulettin in my asset files

For now I try to execute this file with a POST request made form a service in Angular, but it's not working, I get a 404 for all the .php in this directory, (and this is the good name), but not for picture example, weird...

My question is: How can I execute this FPDF script in PHP and see my PDF with Angular 8 ?

I try to add also this header but same...

Header to the POST:

headers: {
   'Content-Type': 'application/json',
   'Access-Control-Allow-Origin': '*',
}

My services:

public makeBulletin(ville: string, pollution: string, date: string) {
    return this.http.request("POST", "http://localhost:4200/assets/make-bulletin/pdf.php", {
      params: {
        Ville: ville,
        Pollution: pollution,
        Date: date,
      },
    })
  }

My .ts for execute the script:

public onSubmit() {
    console.log("toto")
    this.bs.makeBulletin("Lyon", "Atmospherique", "2019-06-01").subscribe(
      resp => {
        // How print PDF to the user after get the PDF ?
      },
      error => {
       // get error
      }
    )

PS: The PHP file work very well, and don't have spelling error, because I just import it form a other OLD website, where it working very well.

Thanks in advance

Sime
  • 153
  • 13
  • 1
    You can't use Angular to execute PHP files. Angular is a client-side program, while PHP is a server side service provided by a webserver such as Apache. When a user of your program visits your website there will be nothing running at `localhost:4200`. During development you most likely use `ng serve` to test your code right? This starts a webserver (without PHP) at `localhost:4200` but this won't be the case in your production environment. – Robin De Schepper Oct 19 '19 at 17:49
  • If this is some sort of local thing you just want to hack together, you'll have to set up a webserver at another port and make your HTTP calls to that PHP competent webserver. – Robin De Schepper Oct 19 '19 at 17:51
  • Also, don't use Angular 2 in 2019... Angular is on version 8. – Robin De Schepper Oct 19 '19 at 17:52
  • @RobinDeSchepper, I see what you, want to say, it's possible I, give you a misunderstanding..., I use "Angular 8" actually, i just say "Angular 2 "because, I don't talk about AngularJS..., PS: i edit may post about that :) – Sime Oct 19 '19 at 22:32
  • 1
    So, if I well understand, my code actually work but "ng serve" don't support PHP ?, i will try tomorrow to run it in nginx with PHP – Sime Oct 19 '19 at 22:35
  • @RobinDeSchepper, Ok it's work, thanks, I tried to configure a new nginx server with PHP, so now i don't have a 404, but the responce is "null", I get nothing about the PDF generate with the output() function in FPDF, someone can help me with that, ?, **Why my FPDF script respond 'null' to me in Angular ?** – Sime Oct 19 '19 at 22:57
  • I don't know how your PHP script works but make sure that it returns the PDF file content with the proper HTTP headers set `header("Content-type:application/pdf");`. You can check the contents of the response through the Developer Tools in Chrome for example (F12). Also take a look at this post: https://stackoverflow.com/questions/50332447/how-to-get-pdf-through-api-in-angular-service for the Angular side – Robin De Schepper Oct 20 '19 at 12:38

0 Answers0