KDK_PRINTE...LOCAL_FILE(3)

📦 version 3.0.1.4, in arch rolling, ubuntu resolute, ubuntu stonking

🌸 kdk_printer_print_local_file — KDK_PRINTE...LOCAL_FILE(3) 💅

okay bestie, sit down, hydrate, because we're learning a library function from the Linux Programmer's Manual and it's genuinely so good. this one lives in the <libkyprinter.h> cinematic universe and its whole personality is: print a local file. that's it. that's the job. main character energy fr fr 🖨️✨


✨ NAME ✨

kdk_printer_print_local_file — 打印本地文件 🌈


🎀 SYNOPSIS 🎀

#include <libkyprinter.h>

extern int kdk_printer_print_local_file(const char *printername, const char *filepath);

Link with -lkyprinter. 🫶

not me reminding you that you literally have to link with -lkyprinter or nothing works, iykyk 💀

💖 Detailed Description 💖

the main function of the interface is to print a local file. like, that's the whole vibe. no cap.

the argument printername is the printer name — specifically, the value that kdk_printer_get_list returned. so like, don't just make one up bestie, get it from the list first 🥰

the argument filepath is the absolute path to the file. absolute. not "somewhere near my downloads folder". absolute. 👑


⭐ RETURN VALUE ⭐

  • On success, returns the id of the print job of type int. 🎉 (a whole job id!! she's employed!!)
  • On error, return 0. 😭
so like, if you get 0 back, that's not a job id, that's a heartbreak. check for it.

🦋 EXAMPLES 🦋

here's the full demo, verbatim, every line, because we don't skip:

#include "libkyprinter.h"
#include <stdio.h>

int main()
{
    int index = 0;
    //获取打印机列表
    char **printers = kdk_printer_get_available_list();
    while (printers[index])
    {
        printf("%zd: %s0, index + 1, printers[index]);

        //取消当前打印机所有打印任务
        kdk_printer_cancel_all_jobs(printers[index]);

        //获取url对应的文件名
        char *url = "http://www.cztouch.com/upfiles/soft/testpdf.pdf";
        int res = -1;
        char *filename = kdk_printer_get_filename(url); //从完整路径名中解析出文件名称,例如:/home/test/abc.txt,解析完成后为abc.txt
        printf("filename = %s0, filename);

        //设置打印参数
        kdk_printer_set_options(2, "A4", "lrtb", "two-sided-long-edge");

        //下载
        res = kdk_printer_print_download_remote_file(url, filename);
        printf("[%s] res = %d0, __FUNCTION__, res);
        printf("[%s] filepath = %s0, __FUNCTION__, filename);

        //打印
        int job_id = kdk_printer_print_local_file(printers[index], filename);
        if (job_id == 0)
        {
            //打印失败
            printf("[%s] create print job fail0, __FUNCTION__);
        }
        else
        {
            //打印成功,等待一会获取任务状态
            sleep(10);
            int status = kdk_printer_get_job_status(printers[index], job_id);
        }

        index++;
        free(filename);
    }
    kdk_printer_freeall(printers);
    return 0;
}

see how the print call is the payoff? kdk_printer_print_local_file(printers[index], filename) — printer name from the list, filename that was parsed out of the url, boom. and then she checks job_id == 0 for the fail case and otherwise waits sleep(10) before asking for the job status. queen behavior. 👑


🌈 CONFORMING TO 🌈

These functions are as per the withdrawn POSIX.1e draft specification. (withdrawn!! we still love her though 💜)

The following functions are Linux extensions: kdk_printer_get_list(), kdk_printer_get_available_list(), kdk_printer_set_options(), kdk_printer_print_download_remote_file(), kdk_printer_cancel_all_jobs(), kdk_printer_get_status(), kdk_printer_get_job_status(), kdk_printer_get_filename() and kdk_printer_freeall().


🧚 SEE ALSO 🧚

kdk_printer_get_list(3), kdk_printer_get_available_list(3), kdk_printer_set_options(3), kdk_printer_print_download_remote_file(3), kdk_printer_cancel_all_jobs(3), kdk_printer_get_status(3), kdk_printer_get_job_status(3), kdk_printer_get_filename(3) and kdk_printer_freeall(3).


that's the whole page bestie, you ate it, go print something 🖨️💖

this was the Linux Programmer's Manual, page KDK_PRINTE...LOCAL_FILE(3), dated Fri Aug 25 2023. mwah. 💅🎀🌸

📦 where this page comes from