Skip to content

Embedded raster images in pdf plotting output #22251

@vvolkl

Description

@vvolkl

Feature description

I was making this nice VIOLIN6 in ROOT:

Image

But the icons I added don't show up in the pdf I tried to save from the script:

violin_bundle.pdf

with the script telling me:

   Warning in <TASImage::Paint>: PDF not implemented yet

I ended up postprocessing the pdf, which is a minor annoyance (also I hit a few more ROOT quirks while doing it). It'd be nice to implement drawing bitmaps to pdf too. I have an (untested, unreviewed) AI-generated patch here: https://github.com/vvolkl/root/tree/tasimage-draw-pdf

I'm happy prepare a proper PR from that branch if that's OK from the maintainer side.

Previous discussions:

https://root-forum.cern.ch/t/tasimage-not-implemented-for-pdf/10476
https://root-forum.cern.ch/t/warning-in-tasimage-paint-pdf-not-implemeted-yet/20122

Minimal reproducer


// Minimal ROOT repro for TASImage PDF output.
// Run:
//   root -l -b -q minimal_tasimage_pdf_warning.C

void minimal_tasimage_pdf_warning() {
    gROOT->SetBatch(kTRUE);

    // Create a tiny PNG asset using ROOT itself so the repro is self-contained.
    auto *src = new TCanvas("src", "src", 64, 64);
    auto *box = new TBox(0.15, 0.15, 0.85, 0.85);
    box->SetFillColor(kRed + 1);
    box->SetLineColor(kRed + 2);
    box->Draw();
    src->SaveAs("minimal_icon.png");

    // Re-open the PNG through TImage/TASImage and draw it on a second canvas.
    auto *c = new TCanvas("c", "c", 400, 300);
    auto *img = TImage::Open("minimal_icon.png");
    if (!img) {
        Error("minimal_tasimage_pdf_warning", "could not open minimal_icon.png");
        return;
    }

    auto *pad = new TPad("imgpad", "", 0.35, 0.25, 0.65, 0.75);
    pad->SetFillStyle(4000);
    pad->SetFrameFillStyle(0);
    pad->SetBorderMode(0);
    pad->SetBorderSize(0);
    pad->SetTopMargin(0);
    pad->SetBottomMargin(0);
    pad->SetLeftMargin(0);
    pad->SetRightMargin(0);
    pad->Draw();
    pad->cd();
    img->Draw("X");
    c->cd();

    c->SaveAs("minimal_tasimage_pdf_warning.pdf"); // empty
    c->SaveAs("minimal_tasimage_pdf_warning.png"); // shows box
}

ROOT version:

root --version
ROOT Version: 6.38.04
Built for macosxarm64 on Mar 11 2026, 21:39:24
From tags/6-38-04@6-38-04

Alternatives considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

Status

PR is open

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions