PXCp_TransformPage equivalent in Core API

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi,

I am converting an application from PDF Tools to Core API and could not find a function/group of functions that I should be using to achieve the same functionality. I looked into the forum and the help site but could not find anything. Can you please guide me on this?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Hello mmasood,

This piece of code will do the same thing:
https://gist.github.com/Polaringu/1a7f9 ... f0498d2622

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

I tried the method that you posted and following are my observations:

1. It only works if you have very few (i believe < 10) GStates on the page
2. If we have placed a watermark on the page, it gets messed up (instead of going across the page from bottom-left to top-right, it goes from bottom-left to bottom-right)
3. If there are any images on the page, they disappear
4. If there are many GStates on the page, the result is a mess

Here are a few questions:

1. What exactly are the GStates?
2. What are CStates, EStates and TStates?
3. I want to transform everything in the page's Media Box in one go (like PXCp_TransformPage did) and do not want to transform every GState one by one. How can I do that?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Hello mmasood,
1. What exactly are the GStates?
2. What are CStates, EStates and TStates?
You can read about this in the PDF specification.
3. I want to transform everything in the page's Media Box in one go (like PXCp_TransformPage did) and do not want to transform every GState one by one. How can I do that?
Currently there is no other way of doing that. The only way is to implement your method that would do this (similar to the one I gave as an example).
1. It only works if you have very few (i believe < 10) GStates on the page
2. If we have placed a watermark on the page, it gets messed up (instead of going across the page from bottom-left to top-right, it goes from bottom-left to bottom-right)
3. If there are any images on the page, they disappear
4. If there are many GStates on the page, the result is a mess
The method that I gave illustrates the overall algorithm of what should be done. The problems could occur when the same GState was modified several times - you'll need to take that into account.

Also a small working sample that illustrates all of your problems would be preferable.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

Just wanted to know if there has been any development in the recent version of the Core API regarding the PXCp_TransformPage function in V5? I am using the version 6.0.317 of Core API. If there is, can you please post some sample code?

Also if this functionality is not available in Core API, do you have some function in Editor SDK that can achieve the same functionality i.e. resize the contents of the page and redraw then at specific coordinates?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Hello mmasood,

All of this is possible on the Core API level. Please provide a piece of code that is not working for you and also a sample document so that we can advice further.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

I am trying with the code that you posted above and getting the same results. Is the code that you post the only way to do this?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Hello mmasood,

Please provide a small sample project with your code that is not working and a file sample that you test on and we can assist further.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

Attached is a small sample application in VB6 along with some sample files. Please let me know if you find anything in the sample that should be changed.

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Hello mmasood,

The files that you've attached contained a valid licence key.
Please do NOT post your license information on the forums, or we will be forced to deactivate it!

As for the issue - we will investigate it and write back with the results.

Chees,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

Is there any update on this? I also downloaded the latest version of the Core API (6.0.318.1) and had the same results.

Thanks for pointing out the license key mistake. I will be more careful in future.

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Hello mmasood,

We are still testing (as this is VB6 that is problematic to use on modern environments), but from what I have seen - you are not doing what I gave you as a sample. If you would look carefully, you would see that you need to multiply the CTM with your matrix.

Code: Select all

PDFXEdit.PXC_Matrix mCtm = gState.get_CTM();
mCtm = Multiply(mCtm, m);
gState.set_CTM(mCtm);
Please update the code with the correct one and try whether everything works for you.
Also, we have updated the library with the MathHelper that has the operations with matrices included. So you can use this method instead of the hand-written Multiply method that I wrote in the sample:

Code: Select all

PDFXEdit.PXC_Matrix mCtm = gState.get_CTM();
mCtm = auxInst.MathHelper.Matrix_Multiply(mCtm, m);
gState.set_CTM(mCtm);
Where the auxInst is the IAUX_Inst.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

The problem was solved by adding the multiply function. Thanks for pointing that out.

I have another issue that I am running into; i want to resize the PDF pages to a predefined page size. With the old library this is what I was doing:

1. Create an new PDF
2. Add empty pages of the desired size to the new PDF
3. Place the content of the existing PDF page by page on the new file using the following code:

Code: Select all

    For i = 0 To (num_pages - 1)
        ' Prepare information for placing the contents
        pci.Alignment = &H3 Or &H30 Or &H100 & &H200
        ' Destination page in the target document
        pci.DestPage = i
        ' Source page (first one) from the source document
        pci.SrcPage = i
        
        res = PXCp_PlaceContents(newPdf, pdf, 1, pci, 0)
        If IS_DS_FAILED(res) Then
            sError = "Failed to copy content into new pdf document: " & ReturnDSErrorString(res)
            GoTo badpdf:
        End If
    Next
I can achieve 1 and 2 with the Core API but not 3. What are the proper function calls that I need?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

Following is the code that I have:

Code: Select all

Set oPageContent = currentPage.GetContent(PXC_ContentAccessMode.CAccessMode_WeakClone)
where 'currentPage' is the page of the existing document.

Code: Select all

pDocNew.Pages.Item(i).PlaceContent oPageContent, PXC_PlaceContentFlags.PlaceContent_Replace
and 'pDocNew' is the new PDF file that I created and added an empty page to that document. This outputs an empty page in the new PDF file and no content is added to that page even though there is no crash.

Q. Can I export content from one document to another using this code?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Well, you can copy the entire pages from one document to another using this method:
https://sdkhelp.pdf-xchange.com/vie ... gesFromDoc

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

I have tried that but then I cannot extend the page size to the custom page size. So if I do that, how can I extend the page size?

I tried setting the Box property to an updated rectangle of the custom size but that does not extend/shrink the page size.

How can I achieve this?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

You will need to change the PBox_MediaBox.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: PXCp_TransformPage equivalent in Core API

Post by mmasood »

Hi Alex,

Yes I am already changing the Media Box.

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: PXCp_TransformPage equivalent in Core API

Post by Sasha - Tracker Dev Team »

Please provide a piece of code that you change the page's size with so I can assist you further.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply