Click here to Skip to main content
13,046,499 members (73,495 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am using QIMAGE class of QT for constructing the image and using the COURIER font .

Printer will support 32 characters for line and i am calculating the IMAGE Height using formula total characters in file/ no of characters per line .

But the problem is it is giving the empty spaces after printing of the file.

Please help me how to resolve the issue.

Thank you.


test.txt is the input file.i want all its text to correctly fit on the image.
Below is the piece of code i am using.once you execute this,you will get test2.png file.but this file has some extra spaces.

#include <QtGui>
#include <QDebug>
#include <QImage>
#include  <QApplication>
#include <QPainter>
#define MAX_NUM_CHAR 30
//test.txt is any text file,this is input file
#define PATH &quot;/home/narendar/test/QtTest/qtitr/test/naru/test.txt
 int main(int argc,char** argv){
 #define IMAGE_WIDTH 384
 #define FONT_HEIGHT 39
     QApplication app(argc,argv);
     QFile file (PATH);
     int  numLines;
     if ( QIODevice::ReadOnly ) )
         QTextStream out(&amp;file);
         QString str = out.readAll();
         int  strLen = str.size();
         // Get number of lines
         numLines =  strLen / MAX_NUM_CHAR ;
         // Get image height
         int  imageHeight;
         imageHeight = FONT_HEIGHT * numLines ;
         // Construct the image with the obtained dimension
          QImage img( 384, imageHeight, QImage::Format_Mono );
          //  QImage img(100,100,QImage::Format_Mono);</pre>
         QPainter painter(&img);
         painter.drawText(QRect(0,0,IMAGE_WIDTH,imageHeight),Qt::AlignLeft | Qt::TextWrapAnywhere | Qt::TextIncludeTrailingSpaces,
         qDebug()<<"image saved"<<endl;
Posted 8-Aug-11 1:28am
Updated 9-Aug-11 0:11am
Richard MacCutchan 9-Aug-11 3:55am
Without seeing your code it is impossible to guess what you are doing wrong.
Richard MacCutchan 9-Aug-11 6:16am
This looks like an issue with the QT package and your calculations regarding text, font and image sizes. I would guess that you need to spend some time with your debugger, checking that these values are correct.
ashok1202 9-Aug-11 6:27am
Do you find any wrong logical calculation for the algorithm ?It works fine for small files but problem mainly comes from large file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 9 Aug 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100