30 auto __dbg = make_QCScopedDebug(
"QOhosPdfPrintEngine::begin");
33 qOhosCritical(QtForOhos) <<
"QOhosPdfPrintEngine: Cannot print multiple documents at once.";
37 d->outputFileName = s_tempDir.filePath(QStringLiteral(
"doc.pdf"));
39 qOhosDebug(QtForOhos) <<
"QOhosPdfPrintEngine: Printing to pdf file:" << d->outputFileName;
41 if (!d->openPrintDevice()) {
42 state = QPrinter::Error;
45 state = QPrinter::Active;
47 return QPdfEngine::begin(pdev);
52 auto __dbg = make_QCScopedDebug(
"QOhosPdfPrintEngine::end");
57 d->closePrintDevice();
59 if (!QFile::exists(d->outputFileName)) {
60 qOhosCritical(QtForOhos) <<
"QOhosPdfPrintEngine: output pdf doc" << d->outputFileName <<
"does not exist. Aborting";
65 if (!QOhosNativePrint::queryPrinterInfo(m_deviceId, printerInfo)) {
66 qOhosCritical(QtForOhos) <<
"QOhosPdfPrintEngine: failed to retrieve printer info";
70 if (printerInfo.state == ::PRINTER_UNAVAILABLE) {
71 qOhosCritical(QtForOhos) <<
"QOhosPdfPrintEngine: printer is unavailable";
75 QFile f(d->outputFileName);
76 if (!f.open(QIODevice::ReadOnly)) {
77 qOhosCritical(QtForOhos) <<
"QOhosPdfPrintEngine: failed to open generated document";
82 qOhosCritical(QtForOhos) <<
"QOhosPdfPrintEngine: failed to obtain fd of pdf file";
85 qOhosDebug(QtForOhos) <<
"QOhosPdfPrintEngine: printing file" << d->outputFileName <<
"with fd:" << fd;
87 std::vector<std::uint32_t> fdList;
88 fdList.push_back(
static_cast<std::uint32_t>(fd));
90 auto printerId = m_deviceId.toUtf8();
91 auto supportedPageSize
92 = QOhosPrintDevice(m_deviceId).supportedPageSize(d->m_pageLayout.pageSize());
93 QByteArray pageSizeId = supportedPageSize.key().toUtf8();
94 auto jobName = QPdfPrintEngine::property(PPK_DocumentName).toString().toUtf8();
96 Print_PrintJob printJob{};
97 printJob.jobName = jobName.data();
98 printJob.fdListCount = fdList.size();
99 printJob.fdList = fdList.data();
100 printJob.printerId = printerId.data();
101 printJob.resolution.horizontalDpi =
static_cast<std::uint32_t>(d->resolution);
102 printJob.resolution.verticalDpi =
static_cast<std::uint32_t>(d->resolution);
103 printJob.copyNumber = m_copies;
105 printJob.pageSizeId = pageSizeId.data();
106 printJob.colorMode = nativeColorMode();
107 printJob.duplexMode = nativeDuplexMode();
108 printJob.orientationMode = nativeOrientationMode();
110 QJsonObject advancedOptions = {
111 {
"isCollate", QPdfPrintEngine::property(PPK_CollateCopies).toBool()},
112 {
"isReverse", QPdfPrintEngine::property(PPK_PageOrder).toInt() == QPrinter::LastPageFirst},
114 auto advancedOptionsJson = QJsonDocument(advancedOptions).toJson(QJsonDocument::Compact);
115 printJob.advancedOptions = advancedOptionsJson.data();
117 if (!QOhosNativePrint::startPrintJob(printJob)) {
118 qOhosCritical(QtForOhos) <<
"QOhosPdfPrintEngine: failed to start print job";
122 state = QPrinter::Idle;
130 Q_D(QOhosPdfPrintEngine);
134 auto requestedDuplexMode = QPrinter::DuplexMode(value.toInt());
135 if (printDevice.supportedDuplexModes().contains(
static_cast<QPrint::DuplexMode>(requestedDuplexMode)))
136 m_duplexMode = requestedDuplexMode;
139 case PPK_CustomPaperSize:
140 d->m_pageLayout.setPageSize(printDevice.supportedPageSize(value.toString()));
143 case PPK_NumberOfCopies:
144 if (printDevice.supportsMultipleCopies())
145 m_copies = value.toInt();
147 case PPK_ColorMode: {
148 auto requestedColorMode = QPrinter::ColorMode(value.toInt());
149 if (printDevice.supportedColorModes().contains(
static_cast<QPrint::ColorMode>(requestedColorMode)))
150 QPdfPrintEngine::setProperty(key, value);
154 QPdfPrintEngine::setProperty(key, value);
224 setProperty(PPK_ColorMode, QVariant(
static_cast<
int>(currentPrintDevice.defaultColorMode())));