Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shinxxxxwon opened this issue Jun 24, 2024 · 0 comments

Comments

@shinxxxxwon
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant