Results 1 to 9 of 9

Thread: QPainting to an eps file

  1. #1
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QPainting to an eps file

    In my app, we are able to export to bitmap graphics files with QImage, and with qprinter, to export proper PDF and PS files.

    However, we also need to be able to export to encapsulated postscript (which is just a ps file with bounding box info). Using qimage produces a bitmap, which isn't what we want - we need a proper postscript file with vector lines and proper fonts.

    In the past, we've exported to a regular .ps file, edited it to insert the bounding box info, and renamed it. This really sounds like a hack. Is there a better way to do this?

  2. #2
    Join Date
    Mar 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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:

    Qt Code:
    1. // Setup printer
    2. QPrinter printer(QPrinter::HighResolution);
    3. printer.setOutputFormat(QPrinter::PdfFormat);
    4. printer.setOutputFileName(pdfFileName);
    5. printer.setFullPage(true);
    6. printer.setPageSize(QPrinter::Custom);
    7. printer.setPaperSize(QSizeF(pdfWidth,pdfHeight),QPrinter::Millimeter);
    8. printer.setPageMargins(0,0,0,0,QPrinter::Millimeter);
    9.  
    10. // Get the painting context from the printer
    11. QPainter painter(&printer); // Destructing painter writes the pdf file
    12.  
    13. // Set the scale, so we can draw in millimeter
    14. double scale = printer.width()/pdfWidth;
    15. painter.setTransform(QTransform(scale,0,0, 0,scale,0, 0,0,1.0));
    16.  
    17. // Draw the image
    18. QRectF src(0,0,image.width(),image.height());
    19. QRectF dst(imageOffsetX,imageOffsetY,imageWidth,imageHeight);
    20. painter.drawImage(dst,image,src);
    21.  
    22. // Draw the markings
    23. QPen pen;
    24. pen.setWidthF(m_lineWidth);
    25. pen.setColor(Qt::red);
    26. QVector<qreal> dashes;
    27. dashes << m_solidDashLength/m_lineWidth << m_blankDashLength/m_lineWidth;
    28. pen.setDashPattern(dashes);
    29. painter.setPen(pen);
    30. 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 
    Last edited by wysota; 12th August 2009 at 08:55. Reason: missing [code] tags

  3. #3
    Join Date
    Aug 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainting to an eps file

    I think it is - Qt doesn't support EPS natively.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  6. #6
    Join Date
    Aug 2009
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  7. #7
    Join Date
    Sep 2007
    Location
    Germany
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainting to an eps file

    Thanks this is exactly what i was looking for
    CAFU......

  8. #8
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainting to an eps file

    thanks, it works realy prety fine :-)

  9. #9
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainting to an eps file

    Quote Originally Posted by enno View Post
    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 View Post
    By the way the output file is proper PostScript, not an encapsulated bitmap.
    But without the ps showpage command and a bounding box ??

    Have a nice day
    dexli

Similar Threads

  1. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  2. Can you specify a file engine?
    By skimber in forum Qt Programming
    Replies: 2
    Last Post: 18th September 2008, 15:54
  3. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  4. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.