Results 1 to 3 of 3

Thread: Print images dosen't work on server

  1. #1
    Join Date
    May 2019
    Posts
    9
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Print images dosen't work on server

    Hello,

    I'm trying to print images (for example to PDF):
    Qt Code:
    1. QString filePath = "deklaracje/10100188";
    2. QDir directory(filePath);
    3.  
    4. QStringList images = directory.entryList(QStringList() << "*.jpg" << "*.JPG",QDir::Files);
    5. QString fileName = "pdf/test.pdf";
    6.  
    7. QPrinter printer2;
    8. printer2.setOutputFormat(QPrinter::PdfFormat);
    9. printer2.setPaperSize(QPrinter::A4);
    10. printer2.setOutputFileName(fileName);
    11. int size, i;
    12. i = 0;
    13. QPainter painter2(&printer2);
    14. int painter2_w, painter2_h;
    15. painter2_w = painter2.device()->width();
    16. painter2_h = painter2.device()->height();
    17. foreach(QString fileName, images) {
    18. QImage img(filePath+"/"+fileName);
    19. if(i==0){
    20. p.begin(&img);
    21. p.setPen(QPen(QColor(0,0,48)));
    22. p.setFont(QFont("Arial", this->fontSize, QFont::Bold));
    23. QRect rect;
    24. rect = img.rect();
    25. rect.setLeft(100);
    26. rect.setTop(200);
    27. p.drawText(rect, Qt::AlignLeft, "xxxxx");
    28. p.end();
    29. }
    30. painter2.drawImage(QPoint(0,0),img.scaled(painter2_w,painter2_h,Qt::KeepAspectRatio));
    31. i++;
    32. if(i<size){
    33. printer2.newPage();
    34. }
    35. }
    36. painter2.end();
    To copy to clipboard, switch view to plain text mode 


    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Print images dosen't work on server

    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,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,141
    Thanks
    235
    Thanked 661 Times in 651 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Print images dosen't work on server

    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.
    Last edited by d_stranz; 13th June 2019 at 16:22.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 23rd September 2010, 12:49
  2. Replies: 1
    Last Post: 9th November 2009, 09:27
  3. Http server : send images
    By fitzy in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 12:04
  4. Client/Server doesn't work
    By mattia in forum Newbie
    Replies: 2
    Last Post: 1st November 2007, 13:31
  5. Why QCursor setPos() dosen't work here?
    By kar98k in forum Qt Programming
    Replies: 8
    Last Post: 1st June 2007, 12:52

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.