No no, you do not have to add any matrix or keys to the dictionary! 

Just change the line p.DrawXObject( 0, vPos, &xo, 1, 1 ); to p.DrawXObject( 0, 
vPos, &xo );. That's all you have to do.

Please find attached the modified code snippet of yours that should work.

regards,
        Dom

Am Mittwoch, 25. Juni 2008 schrieb EXTERNAL Loch Sebastian (Firma Ferchau; 
BhP/TEF17):
> But this didn't work, I still I get an empty page!
>
> Meanwhile I tried the following, but still no success:
> PdfArray  s_matrix;
> s_matrix.push_back( PdfVariant( static_cast<long>( width ) ) );
> s_matrix.push_back( PdfVariant( 0L ) );
> s_matrix.push_back( PdfVariant( 0L ) );
> s_matrix.push_back( PdfVariant( static_cast<long>( height ) ) );
> s_matrix.push_back( PdfVariant( 0L ) );
> s_matrix.push_back( PdfVariant( 0L ) );
>
> xo.GetContents()->GetDictionary().AddKey( "Matrix", s_matrix );
>
> Any ideas?
>
> Thanks.
> Sebastian
>
>
> -----Ursprüngliche Nachricht-----
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Gesendet: Mittwoch, 25. Juni 2008 08:34
> An: EXTERNAL Loch Sebastian (Firma Ferchau; BhP/TEF17)
> Cc: [email protected]
> Betreff: Re: AW: [Podofo-users] Conversion Cals to Pdf not working anymore
> sinceswitch from 0.5.0 to svn trunk!
>
> Sorry, I think my answer was not clear. You do not have to set the matrix,
> PoDoFo will do it for you.
>
> Unfortunately the old code of yours was setting the matrix in a wrong way:
> p.DrawXObject( 0, vPos, &xo, 1, 1 );
>
> The last two parameters are 1 which result in a matrix like this:
> 1.000 0 0 1.000 0.000 10.000 cm
>
> If you leave the last 2 parameters to PdfPainter::DrawXObject away, PoDoFo
> will pick default values, i.e. the size of the XObject.
>
> So you onle have to use the line:
> p.DrawXObject( 0, vPos, &xo );
>
> regards,
>       Dom
>
> Am Mittwoch, 25. Juni 2008 schrieb EXTERNAL Loch Sebastian (Firma Ferchau;
>
> BhP/TEF17):
> > At the moment, I don't see how to set the matrix.
> > Maybe it's still to early...
> >
> > Probably by adding a key Matrix to the dictionary?
> > How can I specify these six values to the corresponding key?
> >
> > Regards
> > Sebastian
> >
> > -----Ursprüngliche Nachricht-----
> > Von: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] Im Auftrag von
> > Dominik Seichter Gesendet: Dienstag, 24. Juni 2008 13:43
> > An: [email protected]
> > Cc: EXTERNAL Loch Sebastian (Firma Ferchau; BhP/TEF17)
> > Betreff: Re: [Podofo-users] Conversion Cals to Pdf not working anymore
> > sinceswitch from 0.5.0 to svn trunk!
> >
> > Hello,
> >
> > Matrix in the 0.5.0 PDF: 3168.000 0 0 2448.000 0.000 10.000 cm
> > Matrix in the 0.6.0 PDF: 1.000 0 0 1.000 0.000 10.000 cm
> > BBox of XObject in both: [ 0.0 0.0 3168.000 2448.000]
> >
> > So just setting the correct matrix before drawing the XObject does the
> > trick.
> >
> > Instead of  p.DrawXObject( 0, vPos, &xo, 1, 1 ); just do
> > p.DrawXObject( 0, vPos, &xo );. PoDoFo will pick the correct default
> > values for scaling the XObject. This change was necessary because we
> > inconsistencies between drawing XObjects and Images. Sorry for the
> > inconviniences the change caused for you.
> >
> > best regards,
> >     Dom
> >
> > Am Dienstag, 24. Juni 2008 schrieb EXTERNAL Loch Sebastian (Firma
> > Ferchau;
> >
> > BhP/TEF17):
> > > Hello all,
> > >
> > > I switched our project from old release 0.5.0 to the
> > > actual version from trunk, but our main functionality
> > > didn't work since this switch.
> > >
> > > We need to convert documents in Cals format to pdf.
> > > With the new version a Pdf document is created, but you
> > > see only a blank page!
> > > I attached an example origin document plus the generated pdfs
> > > with the old 0.5.0 and new version from trunk.
> > > Maybe someone can see what's going wrong there...
> > >
> > > The conversion is done by the following:
> > > -reading header data from cals containing width,height,dpi,...
> > > -creating pdf page
> > > -creating Xobject with subtype Image and CCITTFAXDecode filter
> > >  -> creating appropriate dictionary
> > >  -> setting raw data
> > > -finally drawing XObject to page and writing pdf document
> > >
> > > For more details see see attached code.txt.
> > >
> > > At the moment I have no idea why this conversion is going wrong.
> > > It seems that the created pdf has the "correct" structure,
> > > but I don't know for sure! Maybe someone can have please a look
> > > at the created files.
> > >
> > > Any help is appreciated!
> > >
> > > Thanks.
> > >
> > > Regards
> > > Sebastian



-- 
**********************************************************************
Dominik Seichter - [EMAIL PROTECTED]
KRename  - http://www.krename.net  - Powerful batch renamer for KDE
KBarcode - http://www.kbarcode.net - Barcode and label printing
PoDoFo - http://podofo.sf.net - PDF generation and parsing library
SchafKopf - http://schafkopf.berlios.de - Schafkopf, a card game,  for KDE
Alan - http://alan.sf.net - A Turing Machine in Java
**********************************************************************
QByteArray DAOClientConnection::convertCals2Pdf( QFile* file, int vPos )
{
	logString_ = QString( "Converting to pdf: %1" ).arg( file->fileName() );
	LOG4CXX_DEBUG( logger, logString_.toStdWString() );

	QString rpelcnt;
	QString rdensity;
	int width;
	int height;	
	int dpi;

	QByteArray header;
	QByteArray data;

	if ( file->open( QFile::ReadOnly ) ) {
		header = file->read( 2048 );
		data   = file->readAll();

		int position = header.indexOf( "rpelcnt", Qt::CaseInsensitive );

		if ( position != -1 && ( position % 128 == 0 ) ) {
			rpelcnt = header.mid( position, 128 ).trimmed();
			rpelcnt = rpelcnt.section( " ", 1, 1 );
			width  = rpelcnt.split( "," ).first().toUInt();
			height = rpelcnt.split( "," ).last().toUInt();
		}
		else {
			logString_ = QString( "Problems with rpelcnt." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
		}

		position = header.indexOf( "rdensty", Qt::CaseInsensitive );

		if ( position != -1 && ( position % 128 == 0 ) ) {
			rdensity = header.mid( position, 128 ).trimmed();
			rdensity = rdensity.section( ' ', 1, 1 );
			dpi		 = rdensity.toUInt();
		}
		else {
			logString_ = QString( "Problems with rdensity." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
		}
		
		if ( width != 0 && height != 0 && dpi != 0 ) {
			PdfDocument pdf;
			//PdfMemDocument pdf;
			int pdfWidth = width/dpi * 72;
			int pdfHeight = height/dpi * 72;
			logString_ = QString( "Creating pdf page with %1,%2." ).arg( pdfWidth ).arg( pdfHeight );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			PdfPage* page = pdf.CreatePage( PdfRect( 0,0, pdfWidth, pdfHeight ) );
			
			logString_ = QString( "Creating painter and setting page." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			PdfPainter p;
			p.SetPage( page );

			logString_ = QString( "Creating XObject." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			PdfXObject xo( PdfRect( 0, 0, pdfWidth, pdfHeight ), page->GetContents()->GetOwner() );

			logString_ = QString( "Adding Key: Subtype Image." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			xo.GetContents()->GetDictionary().AddKey( "Subtype", PdfName("Image") );
			logString_ = QString( "Adding Key: CCITTFaxDecode filter." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			xo.GetContents()->GetDictionary().AddKey( "Filter", PdfName( "CCITTFaxDecode" ) );


			logString_ = QString( "Creating dictionary." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			PdfDictionary dp;
			dp.AddKey( "K", static_cast<long>( -1 ) );
			dp.AddKey( "Columns", static_cast<long>( width ) );

			xo.GetContents()->GetDictionary().AddKey( "DecodeParms",  dp );

			xo.GetContents()->GetDictionary().AddKey( "Width",  PdfVariant( static_cast<long>( width ) ) );
			xo.GetContents()->GetDictionary().AddKey( "Height", PdfVariant( static_cast<long>( height ) ) );

			xo.GetContents()->GetDictionary().AddKey( "BitsPerComponent", PdfVariant( static_cast<long>( 1 ) ) );
			xo.GetContents()->GetDictionary().AddKey( "ImageMask", PdfVariant( static_cast<bool>( true ) ));

			logString_ = QString( "Creating memory input stream." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			PdfMemoryInputStream mIs( data.constData(), data.length() );

			logString_ = QString( "Setting raw data of XObject." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			xo.GetContents()->GetStream()->SetRawData( &mIs, -1 );

			logString_ = QString( "Drawing XObject to page." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			p.DrawXObject( 0, vPos, &xo );

			logString_ = QString( "Finishing page." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			p.FinishPage();

			std::ostringstream oSS;
			PdfOutputDevice pOD( &oSS );

			logString_ = QString( "Writing pdf document." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			pdf.Write( &pOD );

			int l = oSS.str().length();
			QByteArray out( oSS.str().data(), oSS.str().size() );
			data = out;
		}
		else {
			logString_ = QString( "Missing parameters." );
			LOG4CXX_DEBUG( logger, logString_.toStdWString() );
			data = NULL;
		}
	}
	else {
		logString_ = QString( "Couldn't open file %1." ).arg( file->fileName() );
		LOG4CXX_DEBUG( logger, logString_.toStdWString() );
		data = NULL;
	}

	return data;
}

Attachment: signature.asc
Description: This is a digitally signed message part.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to