Re: QPainting to an eps file
Hello
I just did something similar: I draw an image and some markings into a pdf file. If you look at the generated pdf file, you can see that it generates vector graphics.
Here is a fragment of the code:
Code:
// 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
));
Re: QPainting to an eps file
Yes... painting to a QPrinter works perfectly, and does what I want for postscript and pdf files.
The question is, how can I make an *encapsulated* postscript file, other than by printing to a postscript file, and then editing it? Or is that the only way (I'm guessing that it is...:( )
http://en.wikipedia.org/wiki/Encapsulated_PostScript
Re: QPainting to an eps file
I think it is - Qt doesn't support EPS natively.
Re: QPainting to an eps file
Hi!
I have small question. By this way of generating postscript file, is it realy vector format postscript file or is it some sort of bitmap wrapped inside generated postscript file. I have similar problem with EPS and I rather use handly maked export to EPS :-). Do you think it's realy so hard to implement EPS support, even if it needs only Bounding box to define? :-).
Is here some way how to easy reimplment Qt provided printer by own and use it in my program?
Thanks for replay.
Re: QPainting to an eps file
Qt 4.5.3 (and maybe 4.4) solved this problem by the including a new overloaded setPaperSize function in the QPrinter class:
printer.setPaperSize(QSizeF(80, 80), QPrinter::Millimeter);
The paperSize code gets set to Unknown/user defined but when printing to a file the size set above is set as the bounding box for the eps file.
By the way the output file is proper PostScript, not an encapsulated bitmap.
Re: QPainting to an eps file
Thanks this is exactly what i was looking for
Re: QPainting to an eps file
thanks, it works realy prety fine :-)
Re: QPainting to an eps file
Quote:
Originally Posted by
enno
Qt 4.5.3 (and maybe 4.4) solved this problem by the including a new overloaded setPaperSize function in the QPrinter class:
printer.setPaperSize(QSizeF(80, 80), QPrinter::Millimeter);
The paperSize code gets set to Unknown/user defined but when printing to a file the size set above is set as the bounding box for the eps file.
Do I have to provide the code which sets the bounding box or is it done simply by calling the above code ??
Quote:
Originally Posted by
enno
By the way the output file is proper PostScript, not an encapsulated bitmap.
:confused: But without the ps showpage command and a bounding box ??
Have a nice day
dexli