Using PDF tools with image xchange

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's Image-XChange Imaging SDK (only).

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

Post Reply
shssteve
User
Posts: 4
Joined: Tue Oct 12, 2004 5:23 pm

Using PDF tools with image xchange

Post by shssteve » Thu Aug 09, 2012 6:27 pm

Are there any examples of using the PDF tools SDK with the image xchange SDK together? There is a method in the pdf tools SDK for PXCp_getdocimageasxcpage, which alludes to returning a pointer to an xcpage, which as I understand, is directly usable by the image xchange sdk. However, any reference to the xcpage pointer by any of the image xchange methods (eg, img_pagescale) seems to result in an access violation.

We have an application that is going to extract images from a PDF, shrink them in size to 90% of original, add some text and write them back to a new PDF. We can do this using temporary BMP files, but the overhead of the I/O is taking too long and we'd like to do all manipulation in memory, preferably using all Tracker products. A code snippet (and a sample PDF) is attached. Development environment is Delphi 5 on 64-bit Windows 7.
Attachments
imgxchangesample.ZIP
Sample PAS and PDF files
(67.17 KiB) Downloaded 208 times

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Using PDF tools with image xchange

Post by Nico - Tracker Supp » Thu Aug 09, 2012 9:18 pm

Hi shssteve,

Thank you for your post.
Regarding to your questions:
Are there any examples of using the PDF tools SDK with the image xchange SDK together?
Yes, please take a look at:
<Installation Root Dir>\Tracker Software\PDF-Tools 4 SDK\Examples\SDKExamples\CExamples\TestPro35\Images\Images.cpp
<Installation Root Dir>\Tracker Software\Image-XChange 4 SDK\Examples\CExamples\ImagesTest\ImagesTestview.cpp
There is a method in the pdf tools SDK for PXCp_getdocimageasxcpage, which alludes to returning a pointer to an xcpage, which as I understand, is directly usable by the image xchange sdk.
Yes, this correct.
However, any reference to the xcpage pointer by any of the image xchange methods (eg, img_pagescale) seems to result in an access violation.
There seem to be something else because the functions you are using seem to be correct. Please check the return value of PXCp_getdocimageasxcpage.
Thanks.

Sincerely,
Nicolas

shssteve
User
Posts: 4
Joined: Tue Oct 12, 2004 5:23 pm

Re: Using PDF tools with image xchange

Post by shssteve » Wed Aug 22, 2012 11:51 pm

I would agree that there is something else missing. When I check the return values (hr), most of the routines (usually) return 0, but when I do think I have the first set of calls working, no matter what I pass to img_pagescale, it returns an error for 'invalid argument'. Here is the code snippet I'm using:

var pImage : PPXCImage;
img : xcimage;


begin
'
'
'
'
pImage := nil;
(*
function PXCp_GetDocImageAsXCPage(pDocument: hPDF; ImageID: DWORD; pImage: PPXCImage): HRESULT; stdcall;external xcprolib;
*)
hr := PXCp_GetDocImageAsXCPage(hDocument, DWORD(hndl), @pImage);

img := 0;
(*
function IMG_ImageCreateEmpty(var image: XCImage):HRESULT; stdcall; external ixclib;
*)
hr := img_imagecreateempty (img);

(*
function IMG_ImageInsertPage(image: XCImage; index: LONG; page: XCPage):HRESULT; stdcall; external ixclib;
*)

hr := img_imageinsertpagecopy (img, 0, cardinal (pimage^));

(*
function IMG_PageScale(page: XCPage; n_width: UINT; n_heigth: UINT; method: IXC_ScaleMethod):HRESULT; stdcall; external ixclib;
*)

hr := img_pagescale (img, 100, 100, IXC_ScaleMethod_Bilinear);
.
.
.
end;


Am I correct in understanding that the info returned from getdocimageasxcpage is a pointer to a cardinal? If I step through the code and examine the values, the calls DO returns values (albeit very high numbers), or else I get an access violation. Is the PPXPAGE really pointing to an image page or an image(depending on what example I look at, it could go either way). Should I be trying to scale the image or the image page? I'm totally lost, and out of time on getting this to the customer - I need to understand what calls i should be making and what I need to pass to each, or move onto a different way of doing this...

Steve

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Using PDF tools with image xchange

Post by Nico - Tracker Supp » Thu Aug 23, 2012 12:51 am

Hi Steve,

Thank you for your post.
Am I correct in understanding that the info returned from getdocimageasxcpage is a pointer to a cardinal?

pImage returned by PXCp_GetDocImageAsXCPage is a pointer to an Image-XChange Library image page object (_XCPage)
If I step through the code and examine the values, the calls DO returns values (albeit very high numbers), or else I get an access violation.
If the returned value is a non-negative integer the function succeeds.
Is the PPXPAGE really pointing to an image page or an image(depending on what example I look at, it could go either way)
.
The signatures you have are a little bit different from the C++ signatures which follow:

HRESULT IMG_ImageInsertPageCopy(_XCImage image, LONG index, _XCPage page);

HRESULT PXCp_GetDocImageAsXCPage( PDFDocument pObject, DWORD ImageID, void** pImage);

Here, pImage and page are the same object. The difference is you pass the address of pImage to PXCp_GetDocImageAsXCPage() and then you pass the value of pImage to IMG_ImageInsertPageCopy(), but "_XCPage page" and "void** pImage" refer to the same object in different libraries. This is an explanation based on C++, you should adapt this to Delphi.
Should I be trying to scale the image or the image page?
You need to scale the page that contains the image, in other words the _XCPage object in the following signature:
HRESULT IMG_PageScale(_XCPage page, UINT n_width, UINT n_heigth, IXC_ScaleMethod method);
Therefore in pseudocode:
hr := img_pagescale (pimage, 100, 100, IXC_ScaleMethod_Bilinear);

You may have to scale first the page before inserting it into the image. That something you want to try.
Please let me know if you have any questions.
Thanks.

Sincerely,

shssteve
User
Posts: 4
Joined: Tue Oct 12, 2004 5:23 pm

Re: Using PDF tools with image xchange

Post by shssteve » Fri Aug 24, 2012 3:29 pm

Thanks. It is a llittle clearer. However, I've boiled the problem down to a few lines of code:

var pimagepage : ppxcimage;
hr : hresult;
hndl : long;
hdocument : hpdf;

begin

// load pdf and get number of images

// for each hndl (number of images)...

pimagepage := nil;
hr := PXCp_GetDocImageAsXCPage(hDocument, DWORD(hndl), @pimagepage); // address of pimagepage (pointer), hr=0

hr := img_pagescale (pimagepage^, 100, 100, ixc_scalemethod_bilinear); // value pointed to by pimagepage, access violation

end;


Essentially, I'm modifying the example in pdf-xchange pro 4 sdk\examples\sdkexamples\delphiexamples\pxcprosample\mainmenu.pas which already has the declarations and the existing call to PXCP_GetDocImageAsXCPage by adding and testing the img_pagescale function, but no matter what I pass to img_pagescale, I either get an access violation or 'invalid page format' result for hr. The PDF I'm opening in the undoctored example opens fine (it was created using the SDK) and has 1 page and on that page, 1 image. I'm assuming that since the example sets pimagepage to nil initially that the call to PXCp_GetDocImageAsXCPage is going to change it (ie, the usage of void** in the c++ template), but should I pass the value in the cardinal pointed to by the value returned in pimagepage, or should I try to dereference what's pointed to by pimagepage and pass that value? Still stumped.....

Nico - Tracker Supp
User
Posts: 220
Joined: Fri May 18, 2012 8:41 pm

Re: Using PDF tools with image xchange

Post by Nico - Tracker Supp » Fri Aug 24, 2012 11:16 pm

Hi shssteve,

Thank you for your post.
I'm afraid documentation of PXCp_GetDocImageAsXCPage is not very clear about the void** pImage argument.

Signature: HRESULT PXCp_GetDocImageAsXCPage(PDFDocument pObject, DWORD ImageID, void** pImage);
pImage: [out] pImage specifies a pointer to an Image-XChange Library image page object (_XCPage).
From ixc_c.h:
typedef void* _XCPage;
typedef void* _XCImage;

Therefore you can do something like this:

Code: Select all

_XCPage pImagePage;			
hr =  PXCp_GetDocImageAsXCPage (hDocument, nImage, (void**)&pImagePage);
At PageScale you call it like this:

Code: Select all

hr = IMG_PageScale (pImagePage, newWidth, newHeight, ScaleMethod_Bilinear);
But I was running your example and the format of the extracted image is PageFormat_1Indexed. If you use ScaleMethod_Linear, it will work but if you want to use ScaleMethod_Bilinear or ScaleMethod_Bicubic it won't. In this case you need to convert the page format to something like PageFormat_8RGB:

Code: Select all

_XCPage pImagePage;			
hr =  PXCp_GetDocImageAsXCPage (hDocument, nImage, (void**)&pImagePage);
if(IS_DS_FAILED(hr)) return;
unsigned int width, height;
hr = IMG_PageGetSize(pImagePage, &width, &height);
if(IS_DS_FAILED(hr)) return;
IXC_PageFormat pFormat;
hr = IMG_PageGetFormat(pImagePage, &pFormat);
if(IS_DS_FAILED(hr)) return;
hr = IMG_PageConvertToFormat( pImagePage,PageFormat_8RGB);
unsigned int newWidth, newHeight;
newWidth = (unsigned int) (0.9 * width);
newHeight = (unsigned int) (0.9 * height);
hr = IMG_PageScale (pImagePage,newWidth, newHeight, ScaleMethod_Bilinear);
if(IS_DS_FAILED(hr)) return;
Thanks.

Sincerely,

Post Reply