PDA

View Full Version : Print images dosen't work on server



mirek_zaklosa
12th June 2019, 20:30
Hello,

I'm trying to print images (for example to PDF):


QString filePath = "deklaracje/10100188";
QDir directory(filePath);

QStringList images = directory.entryList(QStringList() << "*.jpg" << "*.JPG",QDir::Files);
QString fileName = "pdf/test.pdf";

QPrinter printer2;
printer2.setOutputFormat(QPrinter::PdfFormat);
printer2.setPaperSize(QPrinter::A4);
printer2.setOutputFileName(fileName);
int size, i;
i = 0;
QPainter painter2(&printer2);
int painter2_w, painter2_h;
painter2_w = painter2.device()->width();
painter2_h = painter2.device()->height();
foreach(QString fileName, images) {
QImage img(filePath+"/"+fileName);
if(i==0){
QPainter p;
p.begin(&img);
p.setPen(QPen(QColor(0,0,48)));
p.setFont(QFont("Arial", this->fontSize, QFont::Bold));
QRect rect;
rect = img.rect();
rect.setLeft(100);
rect.setTop(200);
p.drawText(rect, Qt::AlignLeft, "xxxxx");
p.end();
}
painter2.drawImage(QPoint(0,0),img.scaled(painter2 _w,painter2_h,Qt::KeepAspectRatio));
i++;
if(i<size){
printer2.newPage();
}
}
painter2.end();


On my computer it is working good. The PDF is save with images and with the "xxxxx" text (with 146kb size).
When I send compiled software to server the PDFs created empty and with (with 2kb size). Even print on the printer is empty.

anda_skoa
13th June 2019, 14:20
Are both system similar? I.e. same operating systems, etc?

Are you deploying Qt with the application or do the systems use locally installed Qt libraries?
If the latter, are they the same version?

Are you using the same platform plugin (if the platform has multiple)?

Have you tried QPdfWriter?

Can the images actually be loaded?
e.g. have you checked the image sizes or have you tried loading and saving to a new file?

Cheers,
_

d_stranz
13th June 2019, 16:17
Can the images actually be loaded?

If the OP's code is what is actually being executed on the server, then he has specified a relative location for the "filePath" directory. If this doesn't exist on his server (or the program's working directory isn't where he thinks it is), then it is likely no JPG files are ever found for processing.

I just love it when people write code with absolutely no error checking and just assume it will work, then can't understand why it doesn't.