// Setup printer
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(pdfFileName);
printer.setFullPage(true);
printer.
setPaperSize(QSizeF(pdfWidth,pdfHeight
),
QPrinter::Millimeter);
printer.
setPageMargins(0,
0,
0,
0,
QPrinter::Millimeter);
// Get the painting context from the printer
QPainter painter
(&printer
);
// Destructing painter writes the pdf file
// Set the scale, so we can draw in millimeter
double scale = printer.width()/pdfWidth;
painter.setTransform(QTransform(scale,0,0, 0,scale,0, 0,0,1.0));
// Draw the image
QRectF src
(0,
0,image.
width(),image.
height());
QRectF dst
(imageOffsetX,imageOffsetY,imageWidth,imageHeight
);
painter.drawImage(dst,image,src);
// Draw the markings
pen.setWidthF(m_lineWidth);
pen.setColor(Qt::red);
QVector<qreal> dashes;
dashes << m_solidDashLength/m_lineWidth << m_blankDashLength/m_lineWidth;
pen.setDashPattern(dashes);
painter.setPen(pen);
painter.
drawRect(QRectF(m_pdfMargin
-m_lineWidth
/2,m_pdfMargin
-m_lineWidth
/2,productionWidth
+m_lineWidth,productionHeight
+m_lineWidth
));
// Setup printer
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(pdfFileName);
printer.setFullPage(true);
printer.setPageSize(QPrinter::Custom);
printer.setPaperSize(QSizeF(pdfWidth,pdfHeight),QPrinter::Millimeter);
printer.setPageMargins(0,0,0,0,QPrinter::Millimeter);
// Get the painting context from the printer
QPainter painter(&printer); // Destructing painter writes the pdf file
// Set the scale, so we can draw in millimeter
double scale = printer.width()/pdfWidth;
painter.setTransform(QTransform(scale,0,0, 0,scale,0, 0,0,1.0));
// Draw the image
QRectF src(0,0,image.width(),image.height());
QRectF dst(imageOffsetX,imageOffsetY,imageWidth,imageHeight);
painter.drawImage(dst,image,src);
// Draw the markings
QPen pen;
pen.setWidthF(m_lineWidth);
pen.setColor(Qt::red);
QVector<qreal> dashes;
dashes << m_solidDashLength/m_lineWidth << m_blankDashLength/m_lineWidth;
pen.setDashPattern(dashes);
painter.setPen(pen);
painter.drawRect(QRectF(m_pdfMargin-m_lineWidth/2,m_pdfMargin-m_lineWidth/2,productionWidth+m_lineWidth,productionHeight+m_lineWidth));
To copy to clipboard, switch view to plain text mode
Bookmarks