cups icon indicating copy to clipboard operation
cups copied to clipboard

When printing a document of type "image/pwg-raster", the error "client-error-document-format-error" occurs.

Open shinxxxxwon opened this issue 8 months ago • 0 comments

I am testing printing using CUPS and cupsfilter.

I know that the mimetype that supports printing is different depending on the printer. So, before making a print request, we search for mimetypes supported by the printer.

attr = ippFindAttribute(pInfo->attrs, "document-format-supported", IPP_TAG_MIMETYPE);

PDF was converted to a pwg-raster file using cupsfilter's pdftoraster.cpp.

Now we ask the printer to print the pwg-raster file.

int scorePrint(char* printerName, char* priterUri, char* mimeType, char* filePath, int lastPage){
    size_t bytes;
    FILE* pOut = NULL;
    char buffer[65536];
    char resource[256];
    int  nIndex=0;

    http_t*         pHttp;
    cups_dest_t*    pDest;
    cups_dinfo_t*   pInfo;
    cups_option_t*  pOptions = NULL;
    ipp_t*          request = NULL;
    ipp_t*          response = NULL;
    ipp_status_t    status = IPP_OK;
    ipp_status_t    close_status = IPP_OK;
    int             nJobId = 0;
    int             nOptions = 0;


    cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);

    pDest = cupsGetDestWithURI(printerName, priterUri);
    pHttp = cupsConnectDest(pDest, CUPS_DEST_FLAGS_DEVICE, 10000, NULL, resource, sizeof(resource), NULL, NULL);
    pInfo = cupsCopyDestInfo(pHttp, pDest)   

     nOptions = cupsAddOption(CUPS_COPIES, "1", nOptions, &pOptions);
     nOptions = cupsAddOption(CUPS_MEDIA, CUPS_MEDIA_A4, nOptions, &pOptions);
     nOptions = cupsAddOption(CUPS_ORIENTATION, CUPS_ORIENTATION_PORTRAIT, nOptions, &pOptions);

     status = cupsCreateDestJob(pHttp, pDest, pInfo, &nJobId, "My Document", nOptions, pOptions);

     pOut = fopen(filePath, "rb");

         if (cupsStartDestDocument(pHttp, pDest, pInfo, nJobId, filePath, mimeType, 0, NULL, lastPage) == HTTP_STATUS_CONTINUE)
         {

           while ((bytes = fread(buffer, 1, sizeof(buffer), pOut)) > 0)
           {
             if (cupsWriteRequestData(pHttp, buffer, bytes) != HTTP_STATUS_CONTINUE)
               break;
           }

           if (cupsFinishDestDocument(pHttp, pDest, pInfo) != IPP_STATUS_OK)
           {
             printf("Document send failed: %s\n", cupsLastErrorString());
           }
         }

         fclose(pOut);
         httpFlushWrite(pHttp);

     if(lastPage == 0){
       close_status = cupsCloseDestJob(pHttp, pDest, pInfo, nJobId);
     }

     cupsFreeDests(1, pDest);
     cupsFreeDestInfo(pInfo);
     cupsFreeOptions(nOptions, pOptions);
     httpClose(pHttp);

     return nJobId;
}

When I call the above function, I get an error.

_cupsGlobalLock() : cg->lastError2 (411)
_cupsGlobalLock() : cg->lastError2 (411)
_cupsGlobalLock() : cg->lastError2 (411)
1cupsFinishDestDocument: client-error-document-format-error (client-error-document-format-error)
_cupsGlobalLock() : cg->lastError2 (411)
 _cupsGlobalLock() : cg->lastError2 (411)
Document send failed: client-error-document-format-error

I don't know how to resolve the error and print pwg-raster normally.

shinxxxxwon avatar Jun 24 '24 08:06 shinxxxxwon