4
votes

I want to display a table and a image side by side. i.e Left side the image and right side the table. I want this because the image is the reference image for the data present in the table. I want that output in pdf. So I am using QTextDocument, QTextCursor and QPrinter to get the output in pdf. So how it is possible to display the image and table in QtextDocument i.e within a single page of the pdf? I am using Qt 4.5.3 and Windows Xp. Any pointers regarding this are welcome.

1
@liaK What about: create an HTML content with frame, where will be the image (left side) and data table (right side), and open it with textDocument->setHtml(htmlText);? And after that use qprinter.setOutputFileName(fileName); qprinter.setOutputFormat(QPrinter::PdfFormat);mosg
ya but i have to specify html sources isn't for frames?? You want me to create html files first for the image and table separately and then use it in html frames?? Or is there any other way??liaK
I mean the the easiest way to create pdf with your data, is to create html content (frame, table, what ever), and you could do it for example with MS Word: 1. you creating <table></table>, adding your images, and tables, and post it to textDocument value. 2. do printing with qprinter value.mosg
But my values of the table are obtained after execution of my application so i don't think it will be good idea to create html files first and take output to pdf. Since the same application that produces the values gonna generate the pdf.liaK
@liaK When I was saying about HTML creating, I'm talking about that your application would create that HTML contest, then load, then print... You do not need to create html before...mosg

1 Answers

2
votes

Hi i managed to do that. Just adding the snippet if someone might need that..

QTextImageFormat m_ReferenceImageFormat; 
m_ReferenceImageFormat.setWidth(525);
m_ReferenceImageFormat.setHeight(450);
m_ReferenceImageFormat.setName(imageFileName);
m_pReportCursor->insertImage(m_ReferenceImageFormat,QTextFrameFormat::FloatRight);

QTextTableFormat m_TableFormat;
m_TableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
    m_TableFormat.setAlignment(Qt::AlignTop);
    m_TableFormat.setWidth(400);
m_pReportCursor->insertTable(5,2,m_TableFormat);
// Table implementation goes here..

Just make sure that the image and table are not overlapping. Adjust width and height accordingly. It should work fine. Thats all.