Bugs item #3042917, was opened at 2010-08-11 10:18
Message generated for change (Comment added) made by domseichter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=790130&aid=3042917&group_id=154028

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: Invalid
Priority: 5
Private: No
Submitted By: herczeg3725 (herczeg3725)
Assigned to: Nobody/Anonymous (nobody)
Summary: PdfPage + PdfPainter: inserted texts rotated

Initial Comment:
Hello,

I try to edit a pdf document with the following code:
--------------------------------------------
size_t iPages = m_pDocument->GetPageCount();
PdfPainter painter;

PdfFont* pFont = m_pDocument->CreateFont( "Arial Unicode MS", new 
PdfIdentityEncoding(0, 0xffff, true));
pFont->SetFontSize(8.0);
painter.SetFont(pFont);
//pFont->SetFontSize(168.0);            //this size works for qtwebpage.pdf
//painter.SetColor( 1.0, 0.0, 0.0 );    //doesn't work

for(size_t iPage=0; iPage<iPages;iPage++)
{
        PdfPage* pPage  = m_pDocument->GetPage(iPage);
        PdfRect rect    = pPage->GetPageSize();
        //pPage->GetRotation() == 0
        painter.SetPage(pPage);
        QString s = "Page "+QString::number(iPage+1)+" von 
"+QString::number(iPages);
        painter.DrawText(11.0, 11.0, s.toLocal8Bit().data());
        painter.FinishPage();
}

m_pDocument->Write( filename.toLocal8Bit().data() );
--------------------------------------------

... and it works mostly, but not with the pdf-documents created by 
QPrinter(QPrinter::PdfFormat)!
See example:
in: http://home.arcor.de/cybergoth/share/qtwebpage.pdf
out:http://home.arcor.de/cybergoth/share/qtwebpage_out.pdf

What should I change in the code to be able to edit these pdf-files too?
Best Regards
George

----------------------------------------------------------------------

>Comment By: Dominik Seichter (domseichter)
Date: 2010-08-11 12:01

Message:
Well, the problem is that you will have to parse the entire content stream
to find out what kind of transformation matrix is set at the end of the
page.

You could try to prepend the relevant drawing commands at the beginning of
the content stream so that you start with the initial transformation
matrix. Or wrap the existing content stream in q OLDSTREAM Q operators, so
that you save and restore the graphics state, which will leave you with the
initial state at the end of the page.

----------------------------------------------------------------------

Comment By: herczeg3725 (herczeg3725)
Date: 2010-08-11 11:49

Message:
Thanks for the hint!
the solution for the specific PDF file is:
painter.setTransformationMatrix(1,0,0,-1,0,0.5);
(auxiliary to painter->SetFontSize(168.0);)

It works now for the problematic PDF file.

However, I would like to be able to determinate if I must set these magic
transformation parameters and fontSize for editing a specific pdf-File or
not.
It is possible to get the transformation matrix or the scale/translate
parameters for a page? (pPage->GetRotation() returns 0).

----------------------------------------------------------------------

Comment By: Dominik Seichter (domseichter)
Date: 2010-08-11 10:58

Message:
Well, if the text is just rotated, you might just want to set your own
transformation matrix.

PdfPainter does not know about the previous contents of the page, so it
just appends drawing commands. So, you have to make sure for yourself that
you are start drawing when the page coordinate system is in a state that
you expect.

So, I do not think this a bug in PoDoFo. It is a very low level library,
so you might want to look into the PDF specification to see what is going
on in content streams in detail.

Regards,
   Dom

----------------------------------------------------------------------

Comment By: herczeg3725 (herczeg3725)
Date: 2010-08-11 10:43

Message:
sorry,
to be more specific:
the position and rotation of the inserted text is unexpected, see
example:
in: http://home.arcor.de/cybergoth/share/qtwebpage.pdf
out:http://home.arcor.de/cybergoth/share/qtwebpage_out.pdf
the wrong position/rotation of the insserted text:
http://home.arcor.de/cybergoth/share/qtwebpage.pdf.comparison.png

Remark: I'm playing around with the demo application 'PoDoFoBrowser'.
I inserted the code above in the function
'bool PoDoFoBrowser::fileSave(const QString & filename)'
so my demo code uses the 'm_pDocument' member from PoDoFoBrowser.

----------------------------------------------------------------------

Comment By: Dominik Seichter (domseichter)
Date: 2010-08-11 10:31

Message:
What does not work? Could you please be more specific.

I would suggest to take a look on the created PDF content stream with
PoDoFoBrowser. Maybe you need calls lile Save/Restore aroung your calls.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=790130&aid=3042917&group_id=154028

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Podofo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to