Search code examples
pdflib

PDFlib - add SVG from string


Is it possible to add SVG graphics to PDF page from string when working with PDFlib?

Documentation states that load_graphics() takes file name on disc. Is there a way around it?


Solution

  • sure, you can use PVF (PDFlib Virtual Filesystem) for this task. See PDFlib 9.2 Tutorial, chapter 3.1.3 "The PDFlib Virtual File System (PVF)" for a detailed introduction.

    A sample for using this with a raster image is included in the PDFlib packages (starter_pvf.php) and also included in the PDFlib cookbook: starter_pvf.

        # We just read some image data from a file; to really benefit
        # from using PVF read the data from a Web site or a database instead
    
        $imagedata = read_file("../input/PDFlib-logo.tif");
    
        $p->create_pvf("/pvf/image", $imagedata, "");
    
        # Load the image from the PVF
        $image = $p->load_image("auto", "/pvf/image", "");