PDA

View Full Version : High quality business papers



NoRulez
30th September 2008, 13:50
Hey @all,

i've an example application were i want to print/save invoices. So i get the data from a database and write xml/xslt documents. After this I generate a html page. This page i load it into a QTextDocument and/or into a QWebView, but the quality is terrible. This generated documents a can't give to any customers. What can i do to generate high quality documents? I make use of libxml2 and libxslt.

Thanks for any hints and tips.

Best Regards
NoRulez

patrik08
30th September 2008, 14:24
This page i load it into a QTextDocument an....


QTextDocument quality as chance from 50% to 95% on QT version 4.5
try your self if you use window...
load file .....

1 - http://fop-miniscribus.googlecode.com/files/TextEdit4.5.exe
2 - http://fop-miniscribus.googlecode.com/files/TextEdit4.1.exe

unpack on path your like or default desktop

open the demo.html or demo.odt file on application 2 check speed on open document,
after open demo.html or demo.odt file on application 1 qt4.5 build and the same document open it so quickly and the are minimum 2 - 3 sec. difference to open same file...
Performance are super on qt4.5.

If you can transform document on xslt use document format XSL-FO
http://en.wikipedia.org/wiki/XSL_Formatting_Objects
http://xmlgraphics.apache.org/fop/

After you having 1000 more option on document ... pdf bookmark and other...
i write http://code.google.com/p/fop-miniscribus/ but QTextDocument can not display all formating instruction.
I print direct source to apache fop.

on QT4.5 you dont need gnome xslt have a look on
http://englich.wordpress.com/category/qt/
http://fop-miniscribus.googlecode.com/svn/trunk/doc/Xsltqt5/

Try your QTextDocument code on QT4.5 an tell me..

NoRulez
30th September 2008, 15:37
Thank you,

i've tried TextEdit 4.5, but the Result is the same. The Problem is that i use CSS within my XSLT Document for example I use:


.
.
.
.tdTest {
text-align: right;
border-left:none;
border-right:1pt solid;
}
</style>
</head>
.
.
.
<body>
<table>
<tr>
<td class="tdTest">Simple Test</td>
</tr>
</table>


I doesn't see the border line and the text isn't aligned to the right.
if I use "<div align="right">Simple Test</div>" within the <td> tags the text ist aligned to the right.

I will have a look at XSL-FO

Sorry, i forgot my QT Version: Currently I'm using QT-commercial 4.4.2

Best Regards
NoRulez

patrik08
30th September 2008, 17:03
css must load separate:

http://wiki.qtcentre.org/index.php?title=QTextBrowser_with_images_and_CSS
doc->addResource( QTextDocument::StyleSheetResource, QUrl( "format.css" ), css );

or write inline style xslt template

Open pdf http://fop-miniscribus.googlecode.com/files/bookmarktestwrite.pdf this is writteln by XSL-FO + qt miniscribus 2 beta

http://code.google.com/p/fop-miniscribus/
why beta? i wait 4.5 stable release and stable OpenDocument reader/writer

Reference + sample:
http://www.zvon.org/xxl/xslfoReference/Output/index.html

NoRulez
30th September 2008, 17:18
But XSL-FO is written in Java?
Is there a C/C++ api like libxml2 or libxslt?

In another post you say you can automate such things (Invoice, ...) with xsl-fo. Can you give me an example how i can call or convert xml and xsl documents with xsl-fo?

http://www.qtforum.de/forum/viewtopic.php?t=5279 (http://www.qtforum.de/forum/viewtopic.php?t=5279&highlight=pdf) and
http://www.qtcentre.org/forum/f-general-programming-9/t-strange-unit-em-same-as-inch-on-xslt-fo-format-8050.html

I think the first URL is written from you or he have the same name as you.

Best Regards
NoRulez

patrik08
1st October 2008, 01:32
But XSL-FO is written in Java?

NO¨¨
XSL-FO is pure xml !

the pdf - rtf - doc - tiff render engine is java fop http://xmlgraphics.apache.org/fop/ High quality business papers
but you can render XSL-FO -> PDF on qt like MiniScribus version 1/2.. only parse xml to qtextdocument all lib are ready.

this xml -> http://fop-miniscribus.googlecode.com/svn/trunk/fop_miniscribus.2.0.0/sample/bookmarksample2.fo
is the base from -> http://fop-miniscribus.googlecode.com/files/bookmarktestwrite.pdf

this xml -> http://fop-miniscribus.googlecode.com/svn/trunk/fop_miniscribus.2.0.0/sample/scribetigersvg.fo it include svg image tiger as vector direct on xml...



Is there a C/C++ api like libxml2 or libxslt?


QT 4.5 can convert libxslt remote or locale file search XSL-T and Qt on page
http://labs.trolltech.com/blogs/2008/09/



int main(int argc, char *argv[]) {
QApplication a( argc, argv );
qDebug() << "### init main void Extract, Transform ";
QDateTime timer1( QDateTime::currentDateTime() );
const QString localoutfile = "outresult.html";
StreamBuf *buf = new StreamBuf();
QXmlQuery xquery(QXmlQuery::XSLT20);
xquery.setFocus(QUrl("http://fop-miniscribus.googlecode.com/svn/trunk/doc/Xsltqt5/data.xml"));
xquery.setQuery(QUrl("http://fop-miniscribus.googlecode.com/svn/trunk/doc/Xsltqt5/style.xsl"));
xquery.evaluateTo(buf->device());
QTextEdit t;
t.show();
t.setPlainText ( const QString & text );
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
};

//// read dir http://fop-miniscribus.googlecode.com/svn/trunk/doc/Xsltqt5/





In another post you say you can automate such things (Invoice, ...) with xsl-fo. Can you give me an example how i can call or convert xml and xsl documents with xsl-fo?

I not need xslt to make simple invoice, only to make report or long mysql - query.. more as 2-3 pages.

to make a simple invoice i write a file on MiniScribus http://code.google.com/p/fop-miniscribus/ version 1.3 which having only Floating elements i parse XML and i insert time , data , customers adress , and table ant end invoice application print or display file on Miniscribus or render direct to pdf ... is only a xml query or you can search and replace ##datetime## and other string key...
In the new Miniscribus version 2 people can take OpenOffice document or pdf - rtf or wath else it need.... is only xml parse to fill data...

I write only 5 or 6 template and you can write 1000 of invoice and barcode
one sample is on http://fop-miniscribus.googlecode.com/svn/trunk/doc/Xsltqt5/tmp.fop
it place layer exact y,x from document and his barcode to find on db the correct invoice by
a hand barcode scanner ...

To learn xsl-fo is more simple as html write a page on MiniScribus 1 or 2 and have a look on source xml...
Other application based on qt is http://www.qt-apps.org/content/show.php/qxsl-fo?content=82672 but at this time it can only write basic simple xsl-fo.

tpf80
14th October 2008, 09:51
Heres what I do for HQ documents:

1) I create a printer
2) I use QPrinter::PdfFormat to make the printer print to PDF
3) I make a QPainter with the QPrinter as the device to print to
4) I then have programmed instructions to draw and type stuff with the QPainter on the printer,
5) When I call painter.end(), it causes the PDF to be created in perfect quality.

Although this method might be somewhat time consuming at first to set up, once you get the hang of it, you can make perfect documents that print on any printer exactly as you intend them to.

Heres a very simple example code to make a pdf with some random lines and text (more of a test of how the page sizes work and how stuff fits) :


void pdf::generatePdf() {

QPrinter printer; //create a printer
printer.setOrientation(QPrinter::Portrait); //set the orientation of the paper
printer.setOutputFormat(QPrinter::PdfFormat); //make that printer as a PDF
printer.setOutputFileName("filename.pdf"); //set the PDF file name
printer.setPaperSize(QPrinter::Letter); //set paper size that the PDF uses
printer.setPageMargins (0.5, 0.5, 0.5, 0.5, QPrinter::Inch); //1/2 inch margins
QPainter painter(&printer); //make a painter, which uses this printer,

//draw a blue round edged rectangle with the word "Hi" in it:
painter.setPen(Qt::blue);
painter.setFont(QFont("Arial", 30));
QRectF r1(100, 200, 100, 100);
painter.drawText(r1, Qt::AlignCenter, "Hi");
painter.drawRoundedRect(r1, 15.0, 15.0);

//draw a black line from the upper left, to the lower right side of the page
painter.setPen(Qt::black);
QLineF line(0, 0, 576, 756);
painter.drawLine(line);

//start a new page:
printer.newPage();

//draw a red box that reads "hello!" in it:
painter.setPen(Qt::red);
painter.setFont(QFont("Arial", 30));
QRectF r2(10, 30, 100, 100);
painter.drawText(r2, Qt::AlignCenter, "Hello!");
painter.drawRect(r2);

//draw a green dashed/dotted line in thick stroke, from upper right to lower left of page:
QPen pen(Qt::green, 3, Qt::DashDotLine, Qt::RoundCap, Qt::RoundJoin);
painter.setPen(pen);
QLineF line2(0, 756, 576, 0);
painter.drawLine(line);

//end the painter causing the PDF to be generated as "filename.pdf":
painter.end(); //done drawing, so save the PDF

}

you can then play around with more lines, positions, images, getting text from a database, etc which you can add using the painter. You can also print rich text documents to PDF like this, there is a text editor example that comes with Qt and within there is code to convert rich text documents to PDF if they are already in that format.

NoRulez
14th October 2008, 15:48
@tpf80: I don't want to draw the lines by my own, i would like to draw the lines with the finished html file. But I also read in the article (http://englich.wordpress.com/2008/09/10/xsl-t-and-qt/#comment-5476) that XSL-T won't be included in the QT Version 4.5.

I also looked to KD Reports for that problem, but the german phone number doesn't work. Did you know where I can have more informations about the price and/or licensing?

Regards

tpf80
14th October 2008, 22:55
One way you could convert the HTML straight to PDF would be like this:


QPrinter printer; //create a printer
printer.setOrientation(QPrinter::Portrait); //set the orientation of the paper
printer.setOutputFormat(QPrinter::PdfFormat); //make that printer as a PDF
printer.setOutputFileName("filename.pdf"); //set the PDF file name
QTextDocument *document = new QTextDocument();
document->setDefaultStyleSheet(styleSheet); //the style sheet QString;
document->setHtml(htmlContent); //the HTML QString;
document->print(&printer);

Note that the stylesheet is loaded separately from the html. Here is a list of the tags which the QTextDocmument can understand: http://doc.trolltech.com/4.4/richtext-html-subset.html

NoRulez
15th October 2008, 07:42
Thanks,

i will try it. Must the style sheet also contain the <style> and </style> tags?

Regards