How to remove the content outside a CropBox?

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
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

How to remove the content outside a CropBox?

Post by whoit »

Hi -

I'm currently trying to take a PDF which has a Crop Box, scale it, and remove any content outside the Crop Box.
I am working with the Crop Box and the Media Box to scale documents and maintain aspect ratios.
If my Crop Box scale smaller than my intended page size, I'd like to remove all content outside of the Crop Box.

This would be similar to using the Editor Feature "Remove the content outside of the crop area" (Document>Crop Pages>Crop Pages).
Can this be done with the CoreAPI ?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello whoit,

This can be done through the Core API - though there is no method that you can use directly for that. What you should do is take the IPXC_Content from the page and remove all of the items that are outside of the crop box area - that's all.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

Hi Alex -

Can you be more specific about the process you refer to?

Do you have an example, or some lines of code or pseudo-code?

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

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Well there is not much to tell. You will have to extract a content (full clone) from each page and run through it's content items. Then you will have to get each item's bound box (BBox) and see whether it is inside/outside of the page's crop box. Then when you have the needed items, use IPXC_ContentItems::DeleteItems to remove the needed items from the content. Then you will have to set the page with the new changed content that you have.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

What happens to an item that is partially in the crop box?
I assume you wouldn't remove it - correct?

Sorry - one more thing - what is the difference between a weak and full clone? (It's not in the docs).
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

If the part is partially in the crop box - we would cut it.
Weak clone does not duplicate the content items, full clone does thus the weak clone is cheaper to use. Basically the weak clone would work in your case as you are modifying the item list, not the items themselves.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

Maybe this is just a language thing but when you say "If the part is partially in the crop box - we would cut it."
do you mean that the Crop Box would cut the item (as expected)
or do you mean you would 'cut out' (delete) the item from the content?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello Wayne,

By cut, I meant that we are changing the content items by removing a part of them. If you want the same behavior - not just removing the content items entirely, then you can use the Redaction annotations as the Crop operation uses them. What you will need to do is to create a RedactInfo via IPXC_Inst::CreateRedactInfo, set that it's a CropMode to true. Then create a PXC_QuadF structure and fill it with 4 Crop Box points. Then use the IPXC_RedactInfo::InsertNew method to insert the quad into it. Also, what is being done in the operation is that the IPXC_RedactOverlayParams are being created and the FColor property is being set to ColorType_None from here https://sdkhelp.pdf-xchange.com/view/PXV:ColorType. Then you should set those overlay parameters to RedactInfo and then use the IPXC_Page::Redact method to apply the redaction to the content that is not in the Crop's margins.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

Hi Alex -

I wanted to post some images to indicate what I'm trying to accomplish.

I want to:
1) Eliminate all of the contents outside of the crop area.
2) Scale the crop area to fit (aspect) the page.

I can do step 2 by scaling the CropBox and MediaBox, but step 1 is my issue.

Starting with this - an 17x11 inch page and an 11x8.5 inch crop area:

Image

I'd like to end up with this - an 11x17 inch page:

Image

To do what I show in the images I used this function in the Editor:

Image

Does this help clarify what I need to accomplish?
Can you provide steps to do this?
(Any sample could would help too)

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

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Here's how this command works in the End-User Editor:
https://www.pdf-xchange.com/forum3 ... 28#p117006

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

Hi Alex -

I read that and in fact have tried implementing it.
(Well, Mohsin has tried - we work together)

We're having a problem with data types since we have to use VB6 for this code.

I'll have Mohsin post the code and show you the issue.

Thanks,
Wayne
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to remove the content outside a CropBox?

Post by mmasood »

Hi Alex,

Following is the code that I wrote from your post above:

Code: Select all

        Dim oRedactInfo As IPXC_RedactInfo
        Set oRedactInfo = pInst.CreateRedactInfo
        
        oRedactInfo.SetCropMode True
        
        Dim oQuad As PXC_QuadF
        Dim oEntry As IPXC_RedactEntry
        Dim lIndex As Integer
        
        oQuad.pt(0).x = LC
        oQuad.pt(0).y = BC
        oQuad.pt(1).x = LC
        oQuad.pt(1).y = TC
        oQuad.pt(2).x = RC
        oQuad.pt(2).y = TC
        oQuad.pt(3).x = RC
        oQuad.pt(3).y = BC
        lIndex = -1
                
        oRedactInfo.Clear
        oRedactInfo.InsertNew oQuad, llIndex
        
        Dim oRedactParams As IPXC_RedactOverlayParams
        oRedactParams.FColor = ColorType_None
        
        oRedactInfo.SetOverlayParams oRedactParams
        
        currentPage.Redact oRedactInfo
I am having an issue when compiling on the following line:

Code: Select all

oRedactInfo.InsertNew oQuad, llIndex
The error is "Invalid Optional parameter type".

I check the help site and there was nothing there. Can you take a look and let me know what is wrong with the code?

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

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello guys,

Can you please make this a small vb6 project that my colleague can use to recreate this behavior? We don't use the VB6 as our coding language though we can try investigating if we have a complete project.

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

Re: How to remove the content outside a CropBox?

Post by mmasood »

Hi Alex,

I have attached a small demo for you to look at.

Regards,
M
Attachments
CROP-Demo.rar
(4.49 KiB) Downloaded 135 times
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

Hi Alex -

Has there been any movement on this?

Have you been able to try the sample code that Mohsin uploaded?

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

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello Wayne,

Yes, my colleague has been searching for a solution for two days now, though still no luck with this one.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

Wow....I thought for sure it was just an issue with the declaration of a var or something....
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to remove the content outside a CropBox?

Post by mmasood »

Hi Alex,

Any update on this?

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

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello guys,

Sadly we did not find a solution yet.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: How to remove the content outside a CropBox?

Post by whoit »

Hi Alex -

Is this because it is VB6 ?

Does this occur in .NET too?

I think we need to escalate this as it is preventing us from finishing our client's project.
What can we do from here to move this forward?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello whoit,

Well I just tried doing this on .Net - everything worked though be sure to create a new PXC_QuadF and new PXC_PointF[4] - had problem with those. Hopefully translating this to VB6 will work:

Code: Select all

private void CropWithRedactionCoreLevel(IPXC_Document doc, IPXC_Inst coreInst)
{
	IPXC_RedactInfo redactInfo = coreInst.CreateRedactInfo();
	redactInfo.SetCropMode(true);
	coreInst.CreateQuads();
	PXC_QuadF q = new PXC_QuadF();
	q.pt = new PXC_PointF[4];
	//top>bottom
	q.pt[0].x = 100; q.pt[0].y = 100; //lb
	q.pt[1].x = 300; q.pt[1].y = 100; //rb
	q.pt[2].x = 300; q.pt[2].y = 400; //rt
	q.pt[3].x = 100; q.pt[3].y = 400; //lt

	redactInfo.InsertNew(ref q);
	IPXC_Page page = doc.Pages[0];
	IPXC_UndoRedoData data;
	page.Redact(redactInfo, out data);
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: How to remove the content outside a CropBox?

Post by mmasood »

Hi Alex,

I tried implementing the code that you provided but was not able to run it in VB6. Can you please translate this code in VB6 so that I can give it a try?

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

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

We will try to write this in VB6.

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

Re: How to remove the content outside a CropBox?

Post by mmasood »

Hi Alex,

Any luck with this so far?

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

Re: How to remove the content outside a CropBox?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

Well we tried with our VB6 knowledge - no luck with this one. As you are a VB6 expert it would be easier for you to translate this code as this C# sample works correctly. I'm afraid that's pretty much all we can help with on this matter.

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