problem with PXCp_PlaceContents

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Support Staff, moderators

Post Reply
wesallen
User
Posts: 32
Joined: Wed Oct 03, 2007 9:15 pm
Location: Georgia

problem with PXCp_PlaceContents

Post by wesallen » Thu May 28, 2009 6:25 pm

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
Next
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)

Lzcat - Tracker Supp
Site Admin
Posts: 712
Joined: Thu Jun 28, 2007 8:42 am

Re: problem with PXCp_PlaceContents

Post by Lzcat - Tracker Supp » Fri May 29, 2009 6:13 am

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.

thanks
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

wesallen
User
Posts: 32
Joined: Wed Oct 03, 2007 9:15 pm
Location: Georgia

Re: problem with PXCp_PlaceContents

Post by wesallen » Fri May 29, 2009 2:55 pm

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.
Attachments
problem.rar
(437.84 KiB) Downloaded 215 times

John - Tracker Supp
Site Admin
Posts: 8202
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: problem with PXCp_PlaceContents

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

Hi,

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

thanks.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

wesallen
User
Posts: 32
Joined: Wed Oct 03, 2007 9:15 pm
Location: Georgia

Re: problem with PXCp_PlaceContents

Post by wesallen » Mon Jun 01, 2009 6:19 pm

Attached is the pdf after merge. Thanks
Attachments
resultpdf.rar
(203.08 KiB) Downloaded 209 times

Lzcat - Tracker Supp
Site Admin
Posts: 712
Joined: Thu Jun 28, 2007 8:42 am

Re: problem with PXCp_PlaceContents

Post by Lzcat - Tracker Supp » Tue Jun 09, 2009 8:18 am

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).
HTH.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.

Post Reply