PDA

View Full Version : Print saving relative position of elements in different output format



Zikoel
14th September 2013, 10:14
I have some problems to printing a document in different output format. I must save (in pdf) and print with normal printer the same document. This document have a grid that I have painting in svg format, some field and images.

The function that make this document is the same except for the istruction:


printer->setOutputFormat(QPrinter::NativeFormat);
The code is very simple:


QSvgRenderer *r;
r = new QSvgRenderer(QString("PrintModelWithoutNote.svg"));

QPrinter *printer = new QPrinter();
QPainter *paint = new QPainter();

if(pdf){
printer->setOutputFormat(QPrinter::PdfFormat);
printer->setOutputFileName("pdf_file.pdf");
}else{
printer->setOutputFormat(QPrinter::NativeFormat);
}

paint->begin(printer);
r->render(paint);

paint->drawText(QPointF(10, 10), "Test1");
paint->drawText(QPointF(50, 50), "Test2");
paint->end();
The problem is that I decided the positions of the text in the pdf format to align themselves with the grid in svg. When I print in native format the text loses alignment with the grid.

I did several tests removing or adding the page margins but without success. The only thing that interests me is to preserve the alignment. Anyone have any suggestions for me?

I hope I have explained my problem well. Thanks in advance.