LifeAstroAPILifeAstroAPI

PDF reports (PHP SDK)

The PHP SDK (composer require lifeastroapi/lifeastroapi:1.3.0) turns the JSON from $client->reports->... into branded, print-ready PDFs: cover page, charts, planet and dasha tables and narrative sections, white-labelled with your logo, colours, footer and optional watermark.

Where the PDF is made

The API returns JSON only. The PDF is made on your server, by the SDK:

  1. Your code requests a report, for example $client->reports->kundliDetailed(...). That call costs the report's credits, as usual.
  2. The SDK turns the JSON into HTML, then prints it to PDF with a browser engine on your side.

Step 2 costs no credits and sends nothing to LifeAstroAPI. Your branding and your customers' reports stay with you.

Two layers

LayerMethodsNeeds
HTMLReports::render*Html($report, $branding)Nothing. Plain PHP, no browser.
PDFReports::*Pdf($report, $branding, $options, $engine), Reports::htmlToPdf($html)A PDF engine: Chrome on your server, or a Gotenberg service you run.

The HTML is the same document the Node.js SDK produces, so a report looks the same whichever SDK you use.

What you need: pick one setup

SetupInstall on your sideWhen to use
1. Chrome on your server (default)Chrome, Chromium or Edge, plus Noto fontsA VPS, dedicated server, VM or Docker container.
2. GotenbergNothing on the PHP server; run Gotenberg (a Docker image) anywhere you controlShared hosting, or servers where you cannot install a browser.
3. HTML onlyNothingYou cannot run either. Your user saves the HTML as PDF from their browser.

The SDK itself needs PHP 8.1+ with ext-curl, ext-json and ext-mbstring. No other Composer package and no Node.js are needed for PDFs.

Setup 1: Chrome on your server

# Debian / Ubuntu (also inside a php:8.x Docker image)
apt-get install -y chromium fonts-noto-core fonts-noto-extra

On macOS and Windows an installed Google Chrome or Microsoft Edge is found automatically. Elsewhere the SDK looks in LIFEASTRO_CHROME, CHROME_PATH, PUPPETEER_EXECUTABLE_PATH, then the usual install locations; or pass the path yourself.

use LifeAstroApi\LifeAstro;
use LifeAstroApi\Lang;
use LifeAstroApi\Pdf\Reports;
 
$client = new LifeAstro(); // reads LIFEASTRO_API_KEY
 
$report = $client->reports->kundliDetailed(
    date: '1990-01-15', time: '10:30', tz: 'Asia/Kolkata', lat: 19.076, lon: 72.8777,
    name: 'Arjun Mehta', place: 'Mumbai', lang: Lang::Hi,
);
 
$pdf = Reports::kundliDetailedPdf($report, [
    'companyName' => 'Acme Astro',
    'logoUrl' => 'https://cdn.acme.example/logo.png',
    'primaryColor' => '#6b21a8',
]);
file_put_contents('kundli.pdf', $pdf);

With no engine given, each *Pdf() call starts Chrome and closes it again (about a second). For more than one PDF, start one engine and reuse it:

use LifeAstroApi\Pdf\Engine\ChromePdfEngine;
 
$engine = ChromePdfEngine::launch(); // or launch(executablePath: '/usr/bin/chromium')
try {
    foreach ($reports as $id => $report) {
        file_put_contents("{$id}.pdf", Reports::kundliLitePdf($report, engine: $engine));
    }
} finally {
    $engine->close();
}

ChromePdfEngine::connect('ws://...') uses a browser that is already running, for example in a separate container.

Setup 2: Gotenberg

Gotenberg is an open-source PDF service that runs Chromium in Docker. Run it on any machine you control, then point the SDK at it:

docker run --rm -p 3000:3000 gotenberg/gotenberg:8
use LifeAstroApi\Pdf\Engine\GotenbergPdfEngine;
 
$engine = new GotenbergPdfEngine('http://your-gotenberg-host:3000');
$pdf = Reports::matchMakingPdf($report, engine: $engine);

Pass headers (for example basic auth) as the second argument if you protect the service.

Setup 3: HTML only

// Laravel
return response(Reports::renderKundliLiteHtml($report, ['companyName' => 'Acme Astro']))
    ->header('Content-Type', 'text/html; charset=utf-8');

The HTML sets A4 pages and margins in its own print CSS. Your user opens it and uses the browser's Print → Save as PDF, or you convert it with any tool you already use.

Available reports

ReportAPI methodHTMLPDF
Kundli (lite)reports->kundliLiterenderKundliLiteHtmlkundliLitePdf
Kundli (detailed)reports->kundliDetailedrenderKundliDetailedHtmlkundliDetailedPdf
Brihad Kundlireports->kundliBrihadrenderKundliBrihadHtmlkundliBrihadPdf
Match-makingreports->matchMakingrenderMatchMakingHtmlmatchMakingPdf
Mangal Doshareports->mangalDosharenderMangalDoshaHtmlmangalDoshaPdf
Dasha analysisreports->dashaAnalysisrenderDashaAnalysisHtmldashaAnalysisPdf
Numerologyreports->numerologyrenderNumerologyHtmlnumerologyPdf
Sade Satireports->sadeSatirenderSadeSatiHtmlsadeSatiPdf
Varshaphalreports->varshaphalrenderVarshaphalHtmlvarshaphalPdf
Horoscope (daily / weekly / monthly)reports->horoscopeDaily …renderHoroscopeHtmlhoroscopePdf

All methods are static on LifeAstroApi\Pdf\Reports. A report is printed in the language you requested it in (lang); nothing else is needed for Hindi, Tamil, Bengali and the other languages.

Brihad Kundli is long. kundliBrihadPdf prints it twice so the table of contents shows the real page of every section, and adds a running header and footer and PDF bookmarks. Make it in a queued job, not inside a web request, and give it a longer timeout:

use LifeAstroApi\Pdf\Engine\PdfOptions;
 
$pdf = Reports::kundliBrihadPdf($report, $branding, new PdfOptions(timeout: 120), $engine);

Names and places on the cover

Pass name and place (or boyName / girlName / boyPlace / girlPlace for match-making) when you request the report. Without them the cover reads "Subject" / "Boy" / "Girl" and shows the birth coordinates. place is display text only; the chart is always computed from lat / lon.

Branding

use LifeAstroApi\Pdf\Branding;
 
$branding = new Branding(
    companyName: 'Acme Astro',
    logoUrl: 'https://cdn.acme.example/logo.png', // or a data:image/... URI
    primaryColor: '#6b21a8',
    secondaryColor: '#9333ea',
    footerText: 'Acme Astro · www.acme.example',
    watermarkText: 'SAMPLE',
);
// An array with the same keys works too.
FieldEffect
companyNameShown on the cover (and in the Brihad running header).
logoUrlCover logo. http(s), data:image/... or a relative URL.
primaryColor / secondaryColorHeadings, table headers, accents.
footerTextLine printed in the bottom margin of every page.
watermarkTextOptional diagonal watermark.

The branding you pass overrides the per-account branding embedded in the report JSON, which falls back to neutral defaults.

Laravel

use LifeAstroApi\LifeAstro;
use LifeAstroApi\Pdf\Reports;
 
public function download(Request $request, LifeAstro $astro)
{
    $report = $astro->reports->kundliLite(
        ...$request->validate([/* date, time, tz, lat, lon */]),
        lang: 'hi',
    );
 
    return response(Reports::kundliLitePdf($report, ['companyName' => config('app.name')]), 200, [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'attachment; filename="kundli.pdf"',
    ]);
}

Register LifeAstro once in a service provider with the key from .env; see the PHP SDK README.

Docker

FROM php:8.3-cli
RUN apt-get update && apt-get install -y --no-install-recommends \
      chromium fonts-noto-core fonts-noto-extra \
    && rm -rf /var/lib/apt/lists/*

When PHP runs as root inside the container, Chrome needs --no-sandbox; the SDK adds it in that case. Prefer running as a non-root user.

Fonts

The templates use the Noto Sans families. The machine that prints the PDF (your server, or the Gotenberg container) must have fonts for the scripts you use, or Indic text prints as empty boxes. On Debian / Ubuntu install fonts-noto-core and fonts-noto-extra. macOS and Windows already include them.

Options

use LifeAstroApi\Pdf\Engine\PaperFormat;
use LifeAstroApi\Pdf\Engine\PdfMargin;
use LifeAstroApi\Pdf\Engine\PdfOptions;
 
Reports::numerologyPdf($report, options: new PdfOptions(
    format: PaperFormat::A4,                       // A3, A4, A5, Letter, Legal, Tabloid
    landscape: false,
    margin: new PdfMargin(top: '18mm', bottom: '22mm'),
    scale: 1.0,
    timeout: 60,                                   // seconds to load and print
));

Security

Branding inputs are sanitized: colours are checked against a safe pattern, the watermark and footer are CSS-escaped, and logoUrl is limited to http(s), data:image/... and relative URLs. The browser fetches logoUrl while printing, so if your end users can set a logo URL, restrict the printing machine's network access to avoid requests to internal hosts.

Troubleshooting

SymptomCause and fix
no Chrome, Chromium or Edge foundInstall one (see Setup 1), pass executablePath:, or set CHROME_PATH. Without a browser, use Gotenberg.
The browser exited in DockerRunning as root without the sandbox flag, or missing libraries. Use the Dockerfile above; pass noSandbox: true if you start PHP as root another way.
Hindi or other Indic text shows as boxesNo Noto fonts on the printing machine. See Fonts.
Gotenberg returned 4xx/5xxCheck the Gotenberg URL and that the service is running (curl http://host:3000/health).
Timeouts on Brihad KundliIt is a large document printed twice. Raise timeout in PdfOptions and make it in a queued job.
Cover says "Subject"Pass name (and place) when requesting the report.

Using Node.js instead? See PDF reports (Node SDK).