Page 1 of 1

problem with PXCp_PlaceContents

Posted: Thu May 28, 2009 6:25 pm
by wesallen
We use the tracker tools to create a header for a pdf document, then we take an existing pdf shrink it and using PXCp_PlaceContents merge the 2 documents. This works fine for most documents, except when the original document has been printed in a Landscape format. When this happens the document shrinks, but when it is placed back on the page it is placed on top of the header and not at the bottom center of the page like it should be(normal 8.5 X 11 portrait docs work fine). Why is the document in Landscape not being properly formatted? below is code used to merge the documents. Thanks.

TransMatrix.A = 0.9
TransMatrix.b = 0
TransMatrix.c = 0
TransMatrix.d = 0.9
TransMatrix.e = 0
TransMatrix.f = 0

res = PXCp_TransformPage(ptrpdf, 0, TransMatrix, 0)
If IS_DS_FAILED(res) Then GoTo Error

PXC_WriteDocumentExA NewPDF, CurrentProjectFolder$ & PdfFileName$, 8, 0, ""
PXC_ReleaseDocument NewPDF
NewPDF = 0

res = PXCp_Init(NewPDF, InitPDF, InitPDFDevCode)
If IS_DS_FAILED(res) Then GoTo Error
res = PXCpVB_ReadDocumentW(NewPDF, CurrentProjectFolder$ & PdfFileName$, 0)
If IS_DS_FAILED(res) Then GoTo Error
Dim placeInfo(10) As PXCp_ContentPlaceInfo
For i = 0 To PagesCount - 1
placeInfo(i).Alignment = 0 'CPA_HorCenter And CPA_VerBottom And CPA_KeepAspect
placeInfo(i).DestPage = i
placeInfo(i).SrcPage = i
res = PXCp_PlaceContents(NewPDF, ptrpdf, PagesCount, placeInfo(0), 0)
If IS_DS_FAILED(res) Then GoTo Error
ptrpdf = 0

res = PXCpVB_WriteDocumentW(NewPDF, CurrentProjectFolder$ & PdfFileName$, PXCp_CreationDisposition_Overwrite, PXCp_Write_Release)

Re: problem with PXCp_PlaceContents

Posted: Fri May 29, 2009 6:13 am
by Lzcat - Tracker Supp
Can you provide us sample pdf files and test project (or at least complete call sequence) to reproduce problem? In PDF term "landscape" means nothing - the visual page appearance depends on page BBox and Rotation, and different creators make "landscape" pages in different ways.


Re: problem with PXCp_PlaceContents

Posted: Fri May 29, 2009 2:55 pm
by wesallen
Attached is an RAR file that contains the problem pdf file. Also a VB6 project is included that will demonstrate the problem. The project will take the pdf file from the current directory, create a header pdf file then merge the 2 pdf files into a single pdf in the current directory called test.pdf.

Re: problem with PXCp_PlaceContents

Posted: Mon Jun 01, 2009 5:18 pm
by John - Tracker Supp

Just a quick supplementary request - to check into quickly - can you please provide the resulting PDF that is incorrect.


Re: problem with PXCp_PlaceContents

Posted: Mon Jun 01, 2009 6:19 pm
by wesallen
Attached is the pdf after merge. Thanks

Re: problem with PXCp_PlaceContents

Posted: Tue Jun 09, 2009 8:18 am
by Lzcat - Tracker Supp
Ok, problem is in your code, not in library.
PDF files may contain rotated pages (like one you supplied), and your code does not handle such situations at all.
Function PXCp_TransformPage just transforms page content, regardless of page rotation. In your case the page content is scaled to lower left corner if page is not rotated and to other corners if it is. This is by design. However read page dimensions are not changed, so you get scaled content with white borders (upper and left sides for non-rotated page, lower and left for supplied file). Then when you place this page on new one with same dimensions all align flags are ignored - because pages has same dimensions and there is nothing to adjust!
So we have two ways to get content positioned where you need:
1. A bit more complex, but more flexible:
- take into acount page boxes (we need PB_MediaBox and PB_CropBox since visual part of page is intersection of this boxes) and page rotation.
- compute e and f coefficients of matrix separately for each rotation case to get correct content position
- transfrom page using correct matrix and follow your algorithm.
2. Simple one:
- transform page using current matrix
- get page boxes (both PB_MediaBox and PB_CropBox) and modify them to reduce page size (it will be enough to modify right and top edges of both boxes to reduce width and height with same factor for each box separately). For example NewRightVal = (Rigth - Left) * a + Left, where a is oefficient a from matrix, Left and Rigth - left and rigth values from box. This is regardless page rotation.
- set correct Alignment flags for PXCp_PlaceContents to position scaled page (you will be limited to edges and center).