How to Replace the image of a IPXC_ContentItem  SOLVED

PDF-XChange Editor SDK for Developers

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

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.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13376
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Tracker Supp-Stefan » Wed May 03, 2017 4:42 pm

Hi Jeff,

If nothing unexpected happens - the planned release date for build 322 is 8 May.

Regards,
Stefan

DolphinMann
User
Posts: 157
Joined: Mon Aug 04, 2014 7:34 pm

Re: How to Replace the image of a IPXC_ContentItem

Post by DolphinMann » Thu May 17, 2018 9:53 pm

Great thread, almost exactly what I needed to do. A few questions though...

Is it possible to get the image from the IPXC_ContentItem? I tried using the code you pasted from earlier in this thread but I only have the IPXC_ContentItem. I did take the ID for that but I only have an IPXC_Document from the OpenDocumentFromFile(inputPDF, clbk); command. Because of that it was not clear how to create the IPXV_ContentItemEntry object.

Basically I am on the wrong side of things, the IPXC side. And the documentation on what I should pass is not clear. If I missed it please point me in the right direction, happy to read up.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4089
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Sasha - Tracker Dev Team » Sat May 19, 2018 1:44 pm

Hello DolphinMann,

I see what you are implying - right now, the only way to use these operations is when you have the IPXV_Document available (thus you will need a IPXV_Control). I've implemented the IPXV_Inst::CreateCIEntry method that will create the IPXV_ContentItemEntry without the IPXV_DocumentSelection interface. I can prepare a dev. build on Monday so that you can use that implementation.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

User avatar
Sasha - Tracker Dev Team
User
Posts: 4089
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Sasha - Tracker Dev Team » Mon May 21, 2018 6:15 am

Hello DolphinMann,

The dev. build should be ready in a couple of hours. Here's the new method that should be available:

Code: Select all

IPXV_ContentItemEntry itRootEntry = null;
//Creating Root Content Item Entry
pxvInst.CreateCIEntry(ref itRootEntry);
//First level items in the root entry are pages
IPXV_ContentItemEntry itPageEntry = itRootEntry.Insert(nPage);
//Inserting needed content items from the page
var content = CoreDoc.Pages[nPage].GetContent(PDFXEdit.PXC_ContentAccessMode.CAccessMode_WeakClone);
for (uint i = 0; i < content.Items.Count; i++)
{
	//For example we will take all of the text items
	if (content.Items[i].Type == PDFXEdit.PXC_CIType.CIT_Text)
		itPageEntry.Insert(i);
}
Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

DolphinMann
User
Posts: 157
Joined: Mon Aug 04, 2014 7:34 pm

Re: How to Replace the image of a IPXC_ContentItem

Post by DolphinMann » Mon May 21, 2018 2:52 pm

Thank you for the assistance. I will try to test this tomorrow.

While I wait for that dev build though, I assume there is no easy way to get the image from the actual ContentItem? In my code for dealing with PDF Content I already loop through the content items and extract text(found that from another thread), so if it is a path/image I'd want to pull that information as well.

I saw this method: https://sdkhelp.tracker-software.com/vi ... ge_GetData

Which returns: https://sdkhelp.tracker-software.com/view/PXV:IMemBlock

Can I then read that memory block directly to a bitmap? Would there be any way at all to just use the content item?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4089
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Sasha - Tracker Dev Team » Tue May 22, 2018 1:41 pm

Hello DolphinMann,

Well you can get the https://sdkhelp.tracker-software.com/vi ... ateIXCPage from the content item. But this will give you the image as it is in the PDF - not always it's visual representation - for this it's better to use the operations mentioned in this topic.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jvanlaethem
User
Posts: 29
Joined: Thu Oct 29, 2015 3:16 pm

Re: How to Replace the image of a IPXC_ContentItem

Post by jvanlaethem » Fri Sep 14, 2018 9:40 am

I have a request similar to this thread. Using the Core API, I would like to decrease the size of the file by downscaling its images. Each page consists of a scanned image and its ocr text.

The problem I have is that the file is larger after this processing when the image in the original file was saved as jpeg. How could I control the way to save the image after rescale?

Thank you,

Jean

Here is my code:

Code: Select all

        public void Resize(String fileName, String newFileName)
        {
            IPXC_Document document = m_PdfCore.OpenDocumentFromFile(fileName, null);
            for (UInt32 pageIndex = 0; pageIndex < document.Pages.Count; pageIndex++)
            {
                IPXC_Page page = document.Pages[pageIndex];
                PXC_Rect pageBox = page.get_Box(PXC_BoxType.PBox_PageBox);
                pageBox.left += 0.1;
                pageBox.top -= 0.1;
                pageBox.right -= 0.1;
                pageBox.bottom += 0.1;
                ResizeImages(page, pageBox, page.GetContent(PXC_ContentAccessMode.CAccessMode_WeakClone));
            }
            document.WriteToFile(newFileName);
        }

        private static void ResizeImages(IPXC_Page page, PXC_Rect pageBox, IPXC_Content content)
        {
            IPXC_ContentItems items = content.Items;
            for (UInt32 itemIndex = 0; itemIndex < items.Count; itemIndex++)
            {
                IPXC_ContentItem item = items.GetItemForEditing(itemIndex);
                PXC_CIType itemType = item.Type;

                if ((PXC_CIType.CIT_Image == itemType)
                 || (PXC_CIType.CIT_InlineImage == itemType))
                {
                    // the image must cover the page
                    PXC_Rect itemBox = item.BBox;
                    if ((itemBox.left < pageBox.left) && (itemBox.top >= pageBox.top) && (itemBox.right >= pageBox.right) && (itemBox.bottom < pageBox.bottom))
                    {
                        IIXC_Page ixcPage = item.Image_CreateIXCPage(false, PXC_RenderingIntent.RI_Perceptual);
                        // only apply to gray/color images
                        IPXC_Image ipxcImage = item.Image_Object;
                        if (1 < ipxcImage.BPC)
                        {
                            ixcPage.Scale((ixcPage.Width + 1) / 2, (ixcPage.Height + 1) / 2, IXC_ScaleMethod.ScaleMethod_Bicubic);
                            IPXC_Image newImage = page.Document.AddImageFromIXCPage(ixcPage, 0);
                            item.Image_Handle = newImage.Handle;
                            page.PlaceContent(content, (UInt32)PXC_PlaceContentFlags.PlaceContent_Replace);
                        }
                    }
                }
            }
        }

User avatar
Sasha - Tracker Dev Team
User
Posts: 4089
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Sasha - Tracker Dev Team » Fri Sep 14, 2018 12:10 pm

Hello Jean,

You can change the IIXC_Page format as you want by setting the Format Parameters. Here's a code snippet for you:

Code: Select all

  pxcPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_FORMAT, (uint)PDFXEdit.IXC_ImageFileFormatIDs.FMT_PNG_ID);
   pxcPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_ITYPE, 21);
   pxcPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_XDPI, (uint)uiInst.DPI);
   pxcPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_YDPI, (uint)uiInst.DPI);
For more details, please check the Encoders List in the ImagesTest utility available from here:
viewtopic.php?f=66&t=25943

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jvanlaethem
User
Posts: 29
Joined: Thu Oct 29, 2015 3:16 pm

Re: How to Replace the image of a IPXC_ContentItem

Post by jvanlaethem » Sat Sep 15, 2018 4:14 pm

Alex,

This works fine when I save the image in a jpg file. But what I'm doing here is replacing an image inside a pdf, then saving the pdf. In this case, it doesn't seem to change the way the image is saved inside the pdf.

Jean

User avatar
Sasha - Tracker Dev Team
User
Posts: 4089
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Sasha - Tracker Dev Team » Mon Sep 17, 2018 9:05 am

Hello Jean,

Well it's a little more complex when we are talking about the writing the image into the PDF structure. You will have to specify a Stream Encoding type for that. What you should do is open your file with the End-User Editor, use Edit Content Tool or Select Text tool to select the image that you want to scale, right click it and select Recompress Image command. There you will see all of the current image settings and also, you can choose the resulting image parameters. But, as you are using the Core API SDK, not the Editor SDK, you cannot use the operation directly. But, what you can do, is find out the optimal Compression type for your picture. The thing is, that we can only find out the compression type, not the compression parameters, thus, when replacing the image, you will have to choose the compression for yourself. For this, before your replace code, you will have to call this method:
https://sdkhelp.tracker-software.com/vi ... StreamType
With it, you can set the encode compression filters that will be used when adding new items of the given type. This method should be used to add the filter info to the array:
https://sdkhelp.tracker-software.com/vi ... FilterInfo


Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jvanlaethem
User
Posts: 29
Joined: Thu Oct 29, 2015 3:16 pm

Re: How to Replace the image of a IPXC_ContentItem

Post by jvanlaethem » Mon Sep 17, 2018 12:31 pm

Thank you Alex, this is exaclty what I needed.

I now filter the images to be resized by their Format: PageFormat_8RGB. I created an EncodeFilter for streams of type "Image.TrueColor".
Where can I find what formats match what stream types ?

Jean

User avatar
Sasha - Tracker Dev Team
User
Posts: 4089
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Sasha - Tracker Dev Team » Mon Sep 17, 2018 1:15 pm

Hello Jean,

For that you will have to read the PDF reference available for example from here:
https://www.adobe.com/content/dam/acom/ ... 0_2008.pdf
What you will have to read for starters is 7.4. Filters section Table 6 Standard Filters. page 31.
By opening that table along with the recompress image dialog, you can see what filter should be used in your case. As for the filters' parameters - they are also in the same specification and also are given in the sample link on wiki I gave earlier.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

jvanlaethem
User
Posts: 29
Joined: Thu Oct 29, 2015 3:16 pm

Re: How to Replace the image of a IPXC_ContentItem

Post by jvanlaethem » Tue Sep 18, 2018 12:30 am

Thank you,

Jean

User avatar
Sasha - Tracker Dev Team
User
Posts: 4089
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: How to Replace the image of a IPXC_ContentItem

Post by Sasha - Tracker Dev Team » Tue Sep 18, 2018 5:18 am

:)
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply