我尝试使用cups pdftoraster后打印,但出现格式错误

问题描述 投票:0回答:1

我使用

pdftoraster.cxx
cupsfilter
将 pdf 文件创建为光栅文件。

这是我的打印机

Epson L6290
。以下是支持的
mimetypes

"application/octet-stream"
"image/pwg-raster"
"image/urf"
"image/jpeg"
"application/vnd.epson.escpr"
inPdf = fopen("test_raster_0604.tmp","wb");

if(inPdf == NULL){
  LOG("pdftoraster() inPdf == NULL");
  goto err1;
}else{
  LOG("pdftoraster() inPdf != NULL");
  inpdfdf = fileno(inPdf);
}

if ((raster = cupsRasterOpen(inpdfdf, pwgraster ? CUPS_RASTER_WRITE_PWG : CUPS_RASTER_WRITE)) == 0) {
   exit(1);
}

selectConvertFunc(raster);

for (i = 1;i <= npages;i++) {
   outPage(doc,catalog,i,out,raster);
}
cupsRasterClose(raster);
inSize = ftell(inPdf); //not 0
fclose(inPdf);

整个代码比较长,我简单写一下。我附上了下面引用的代码的 URL。
https://github.com/jianlei12138/cups-filters/blob/master/filter/pdftoraster.cxx#L1941

由于光栅文件已创建为名为

test_raster_0604.tmp
的文件,我们现在将使用 CUPS 打印光栅文件。

int nOptions = 0;

File* outRaster = fopen("/data/user/0/cache/test_raster_0604.tmp", "rb");

cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);

cups_dest_t* dest = cupsGetDestWithURI("EPSON_L6290_Series", "ipps://ip_address/ipp/print");

http_t* http = cupsConnectDest(dest, CUPS_DEST_FLAGS_DEVICE, 10000, NULL, resource, sizeof(resource), NULL, NULL);

cups_dinfo_t* pInfo = cupsCopyDestInfo(http, dest)

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);      

ipp_status_t status = cupsCreateDestJob(http, dest, pInfo, &nJobId, "My Document", nOptions, pOptions);


 if (cupsStartDestDocument(http, dest, pInfo, nJobId, "test_raster_0604.tmp", "image/pwg-raster", 0, NULL, 1) == HTTP_STATUS_CONTINUE)
{
   while ((bytes = fread(buffer, 1, sizeof(buffer), outRaster)) > 0)
   {
      if (cupsWriteRequestData(http, buffer, bytes) != HTTP_STATUS_CONTINUE)
                    break;
   }

   LOG("Document send write done : %s", cupsLastErrorString()); ///successful-ok

   if (cupsFinishDestDocument(http, dest, pInfo) != IPP_STATUS_OK)
   {
       LOG("Document send failed: %s", cupsLastErrorString()); ///client-error-document-format-error
   }
}

我相信我已正确设置

MimeType
,但CUPS 中出现格式错误。你知道解决办法吗?

printing raster mime-types cups
1个回答
0
投票

pdf 和 pwg-raster 的尺寸太大,无法在打印机上打印。如果您使用

apache pdfbox
缩小PDF的大小,转换它,然后打印,它将正常打印。

© www.soinside.com 2019 - 2024. All rights reserved.