Page 1 of 1

PXCp_TransformPage throws an exception

Posted: Mon Jan 23, 2012 4:17 pm
by relapse
Hello, I've found the following function to scale page contents:

Code: Select all

HRESULT PXCp_TransformPage (PDFDocument pDocument, DWORD PageNumber, LPCPXC_Matrix matrix, DWORD flags);
The matrix structure is defined like this:

Code: Select all

public struct PXC_Matrix
    {
      public double  a;  //      | a b 0 |
      public double  b;  //      | c d 0 |
      public double  c;  //      | e f 1 |
      public double  d;  //
      public double  e;  // dx
      public double  f;  // dy
    };
I declare the API function as follows:

Code: Select all

[DllImport("xcpro40")]
public static extern int PXCp_TransformPage(int pDocument, int iPageNumber, ref PXC_Matrix pMatrix, int iFlags);
The function call in C#:

Code: Select all

            var TransformMatrix = new PdfXchangePro.PXC_Matrix() { a = 0.0, b = 0.0, c = 0.0, d = 0.0, e = 2.0, f = 3.0 };
            if (_documentId != 0)
            {
                int res = PdfXchangePro.PXCp_TransformPage(_documentId, 0, ref TransformMatrix, 0x0001);
            }
This call ends with an AccesViolatioException ("Attempted to read or write protected memory. This is often an indication that other memory is corrupt.")

What is wrong? The memory for the matrix object is reserved with the new() operator. I see no reason for the exception to be thrown except of the calling parameters in C++ and C# which don't match each other (LPCPXC_Matrix matrix vs. ref PXC_Matrix pMatrix).


Thanx

Re: PXCp_TransformPage throws an exception

Posted: Tue Jan 24, 2012 11:25 pm
by Ivan - Tracker Software
Just tried your code and it works without problems.
Can you send me the PDF where problem is reproduced?

By the way, the matrix you made is invalid (singular matrix) - it transforms everything to single point (2, 3);

Re: PXCp_TransformPage throws an exception

Posted: Wed Jan 25, 2012 10:09 am
by relapse
Hello, in the attachment you can find the PDF file I'm trying to resize. What other values do I need to manipulate the size (you say with those 2 values I have only an access to a single point)?

In the docs (PDF-ToolsV4SDK.pdf) in the information regarding PXCp_TransformPage function I've found the following reference "See PDF Reference 1.6, section 4.2.2 for Common Transformations for more detailed information." What docs are meant there?

Re: PXCp_TransformPage throws an exception

Posted: Thu Jan 26, 2012 8:50 pm
by Ivan - Tracker Software
Here is the link to PDF references: http://www.adobe.com/devnet/pdf.html
Also, what is the matrix as how it should be used, you can find on the Wikipedia: http://en.wikipedia.org/wiki/Transforma ... formations

Re: PXCp_TransformPage throws an exception

Posted: Fri Jan 27, 2012 7:02 am
by relapse
Can you advise me a JavaScript function to manipulate width/height values of a PDF page/doc?

Re: PXCp_TransformPage throws an exception

Posted: Fri Jan 27, 2012 2:57 pm
by Tracker Supp-Stefan
Hello relapse,

You will need to use the PDF Tools functions discussed above in this topic to physically change a page's dimensions and perform a proper rotation, but if you want - you should also be able to use the setPageBoxes JS method to change the visible dimensions of a document's page(s).

For more information on this function - please refer to the JS for Acrobat API reference.

Best,
Stefan

Re: PXCp_TransformPage throws an exception

Posted: Tue Jan 31, 2012 11:34 am
by relapse
I've tried to execute this JavaScript code with your sample program for testing JS:

Code: Select all

var rCrop = this.getPageBox("Crop",this.pageNum);
rCrop[1] -= 50; // top
rCrop[2] -= 50; // right
this.setPageBoxes("Crop",this.pageNum,this.pageNum,rCrop);
I get the error message: "An error occured in java script".

Re: PXCp_TransformPage throws an exception

Posted: Tue Jan 31, 2012 5:45 pm
by Tracker Supp-Stefan
Hello relapse,

After checkign this with our Viewer Project Leader, he confirmed that this method is not yet supported in our Viewer - so I have created a ticket in our internal system:
#1421: Viewer 2.5.201: Implement support for setPageBoxes JS
And this will be fixed for the next build of the Viewer.

Best,
Stefan

Re: PXCp_TransformPage throws an exception

Posted: Wed Feb 01, 2012 6:56 am
by relapse
Thanks for your answer. Back to PXCp_TransformPage function: I have a suggestion it's a problem with the document ID that I'm using. I suppose it's wrong because it should be a document handle.

Re: PXCp_TransformPage throws an exception

Posted: Wed Feb 01, 2012 10:59 am
by relapse
My suggestion was correct. I used document id provided by Viewer and not the document handle provided by PXCp_Init function. 8) But the PXCp_TransformPage function expects a handle!

The document is transformed, I only have to alter the boxes (crop box etc.).

Re: PXCp_TransformPage throws an exception

Posted: Wed Feb 01, 2012 6:44 pm
by John - Tracker Supp
So - unless otherwise we can assume this is resolved ?

Thanks

Re: PXCp_TransformPage throws an exception

Posted: Thu Feb 02, 2012 7:07 am
by relapse
Not yet :(

After the transformation I get the PDF file where the outer border keeps its original size (see the attached file). I tried to alter the size of the boxes (crop, media and trim) either before transformation or after it but without any success. Do you have any idea what fails?



Thanks

Re: PXCp_TransformPage throws an exception

Posted: Thu Feb 02, 2012 12:55 pm
by relapse
Sorry, my fault - I used false values resizing the boxes. And surely altering the boxes is to be done BEFORE file resizing. The problem is resolved. Thanks for all who helped me!

Re: PXCp_TransformPage throws an exception

Posted: Thu Feb 02, 2012 1:32 pm
by John - Tracker Supp
Excellent news - thanks Relapse :)

Re: PXCp_TransformPage throws an exception

Posted: Thu Jun 14, 2012 12:29 am
by Paul - Tracker Supp
Hi relapse

The "setPageBoxes" JS method that was not yet implemented in our Viewer has been added to the new build. It should be available for download around the 18th.

hth