Add a grafic like JPG or BMP on a page

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
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello,
I have a little problem and I need support:
I want to add a grafic like JPG or BMP on a page, but it is not visible. The values from x, y and the size are correct. What is wrong on my c++ code? All return values are OK (S_OK).
hr = pdfInt.pdfContentCreator_->SaveState();
if ( hr != S_OK )
{
pdfInt.error_ = hr;
pdfInt.errorText_ = getErrorDesc( pdfInt.error_ );
return false;
}
PXC::IPXC_Image* img;
PXC::ULONG_T size;
PXC::PXC_Matrix im = { 0 };

hr = pdfInt.pdfFile_->AddImageFromFile(wstrFileName, 0, 0, &img);
if ( hr != S_OK )
{
pdfInt.error_ = hr;
pdfInt.errorText_ = getErrorDesc( pdfInt.error_ );
return false;
}
// get image width
hr = img->get_Width(&size);
if ( hr != S_OK )
{
pdfInt.error_ = hr;
pdfInt.errorText_ = getErrorDesc( pdfInt.error_ );
return false;
}
// get image heigth
hr = img->get_Height(&size);
if ( hr != S_OK )
{
pdfInt.error_ = hr;
pdfInt.errorText_ = getErrorDesc( pdfInt.error_ );
return false;
}
// set position and size
im.a = width; //Image Width
im.d = height; //Image Height
im.e = calcX( x ); //Location x
im.f = calcY( y ); //Location y

hr = pdfInt.pdfContentCreator_->ConcatCS(&im);
if ( hr != S_OK )
{
pdfInt.error_ = hr;
pdfInt.errorText_ = getErrorDesc( pdfInt.error_ );
return false;
}
hr = pdfInt.pdfContentCreator_->PlaceImage(img);
if ( hr != S_OK )
{
pdfInt.error_ = hr;
pdfInt.errorText_ = getErrorDesc( pdfInt.error_ );
return false;
}
hr = pdfInt.pdfContentCreator_->RestoreState();
if ( hr != S_OK )
{
pdfInt.error_ = hr;
pdfInt.errorText_ = getErrorDesc( pdfInt.error_ );
return false;
}
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

Check out the CoreAPIDemo application - it holds plenty of samples:
https://github.com/tracker-software/PDF ... oreAPIDemo

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

i use the sample code from the c# example, but i get a empty page.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

Have you tried using that sample directly? Does it give correct results with your image?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

i have translated from c# to c++ and the code is in the first post.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

I meant using the code from the C# sample with your file and looking at the results.
If it all works correctly - then it's the problem with the translation.
If it behaves the same as your C++ code - then the problem is with the file itself.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Thanks, i will check it.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hi Alex,

i have check the source code and it works with Windows 21H1 and Visual Studio 2019 (for the check), but not with Windows 2004 and Visual Studio 2008. So i mean, it is a version problem. i habe check it with the PdfXChange version "8.0.337.0" and "8.0.341.0" and VS2008.

So my question is: What is the right version for using with VS2008? Better a older version or a newer one?

Thanks, for your support.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

Does it work with the latest Windows version and the VS2008? Because I'm afraid that it's outdated for correct usage.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hallo Alex,

it works with Windows 10 (Version from this year) and Visual Studio 2019, but not on the PC with Windows 10 (Version from last year) and Visual Studio 2008. We use C++ on both machines.

On the machine with VS2008 i can read the sizes from the picture but the insert is not correct (nothing to see from the picture on the page and the size from the pdf file is 4KB = 4071 byte = to small with the picture).

The VS2008 is an older version and the question is: Is it a version issue from VS2008 (not Windows 10)?

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

Well I'm afraid that you will have to debug this for yourself, as we don't know what the issue is exactly.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hallo Alex,

please, give me a short example for create a new pdf file with insert a jpg grafic.

Cheers
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

this is the Preview from the MSC C++ example:
image.png
Then i added the code to save it to a Pdf file and this is the result:
image1.png
and all resultcode from the functions are S_OK.

Please tell me what is wrong? Thanks.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

OK, I don't get it now. You said that your code is working perfectly for VisualStudio2019. Are you trying the same code with VS2008 and it does not work? If so, that the problem is not with the SDK, but with the VS, settings and environment.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

the hardcopy are from the pc with Visual Studio 2019 and c++.
The first hardcopy shows the preview from the c++ example, with the picture.
The preview is ok.
Than i added the source code to save the pdf file.
The second hardcopy shows the pdf file, it is empty and the size is 4KB.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

OK, and if you take the built exe file from the 2019 PC and try it on the 2008 one? And the reversed case - take the exe from the 2008 and try it on the 2019 PC.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

the same problem = empty page.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

In two cases that I mentioned earlier?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

but what is wrong?

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

Well, we'll still need an answers for the behavior in both cases - then we can tell more.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

rlcgm wrote: Tue Jun 29, 2021 1:07 pm Hallo Alex,

it works with Windows 10 (Version from this year) and Visual Studio 2019, but not on the PC with Windows 10 (Version from last year) and Visual Studio 2008. We use C++ on both machines.

On the machine with VS2008 i can read the sizes from the picture but the insert is not correct (nothing to see from the picture on the page and the size from the pdf file is 4KB = 4071 byte = to small with the picture).

The VS2008 is an older version and the question is: Is it a version issue from VS2008 (not Windows 10)?

Cheers
Hello Alex,

the same problem = empty page.

Cheers
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hallo Alex,

are there any new findings on the subject?

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

Nope - as we did not get an answer prior to both cases:
1) Does it work correctly if you take the built exe file from the VS2019 PC and try it on the VS2008 one?
2) Does it work correctly if you take the built exe file from the VS2008 PC and try it on the VS2019 one?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hallo Alex,

1) Does it work correctly if you take the built exe file from the VS2019 PC and try it on the VS2008 one?
No

2) Does it work correctly if you take the built exe file from the VS2008 PC and try it on the VS2019 one?
No

Please use the c++ example from the delivery path and add the code lines from my post from "Thu Jun 10, 2021 2:31 pm".
Use your own jpg or bmp grafic file and look at the preview. It shows the grafic file (see hardcopy from posr).
Go to the end of the function and save the pdf file to the file system. Open it with a pdf viewer and you habe a empty page.
The file on the filesystem is 4 KB big without any text or the grafic.

I hope this helps to understand my problem.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

I've made a working sample that generates a one page document with one image content item that's being loaded from file Figures.png. To try this you should unpack the archive, put the PDFXCoreAPI.x64.dll in the unpacked folder and launch the exe.
The result of this should be a Test.pdf document that would be generated in the exe directory.
ConsoleCoreAPISample.zip
(32.14 KiB) Downloaded 159 times
If this works correctly on both machines then I will share the project code.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

sorry, for the late reaction.
It works on both machines. But we use VS2008 and the 32 bit version from PdfXChange. I this a problem?

Thanks.

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

Re: Add a grafic like JPG or BMP on a page

Post by Sasha - Tracker Dev Team »

Hello rlcgm,

Here's a fully working project for this sample. Also, we've tried extracting the code and launching this on VS2012 - everything worked as expected:
https://github.com/tracker-software/PDF ... eAPISample

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

i have i short question:
The second lines are setting the position to 0,0.
bbox.left = 0;
bbox.bottom = 0;
I want to set i to 100, 200.

This lines are setting the size from the image:
bbox.right = nW * 72.0 / 96.0;
bbox.top = nH * 72.0 / 96.0;

This line set the right top position:
pMH->Matrix_Scale(&im, bbox.right, bbox.top, &im);

In the documentation i can not find the information. What is todo, to set the position to 100, 200?
In the source code from the example i can not find it.

Cheers
rlcgm
User
Posts: 38
Joined: Thu Jun 10, 2021 11:00 am

Re: Add a grafic like JPG or BMP on a page

Post by rlcgm »

Hello Alex,

i have found it.

Cheers
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17768
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Add a grafic like JPG or BMP on a page

Post by Tracker Supp-Stefan »

:)
Post Reply