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, Chris - Tracker Supp, Vasyl-Tracker Dev Team, 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: 21
Joined: Thu Jun 10, 2021 11:00 am

Add a grafic like JPG or BMP on a page

Post by rlcgm » Thu Jun 10, 2021 12:31 pm

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;
}

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Thu Jun 10, 2021 12:36 pm

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Thu Jun 10, 2021 1:26 pm

Hello Alex,

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

Cheers

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Thu Jun 10, 2021 1:46 pm

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Thu Jun 10, 2021 2:14 pm

Hello Alex,

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

Cheers

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Fri Jun 11, 2021 7:23 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Fri Jun 11, 2021 7:52 am

Thanks, i will check it.

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Fri Jun 11, 2021 1:08 pm

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

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

Post by rlcgm » Thu Jun 24, 2021 5:58 am

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Tue Jun 29, 2021 7:59 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » 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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Tue Jun 29, 2021 2:05 pm

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Wed Jun 30, 2021 5:18 pm

Hallo Alex,

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

Cheers

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

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

Post by rlcgm » Thu Jul 01, 2021 6:17 am

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Thu Jul 01, 2021 8:20 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Mon Jul 05, 2021 6:10 am

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Mon Jul 05, 2021 7:33 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Mon Jul 05, 2021 9:36 am

Hello Alex,

the same problem = empty page.

Cheers

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Tue Jul 06, 2021 9:05 am

Hello rlcgm,

In two cases that I mentioned earlier?

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

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

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

Post by rlcgm » Tue Jul 06, 2021 9:13 am

Hello Alex,

but what is wrong?

Cheers

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Tue Jul 06, 2021 3:09 pm

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Wed Jul 07, 2021 9:50 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Tue Jul 13, 2021 7:58 am

Hallo Alex,

are there any new findings on the subject?

Cheers

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Tue Jul 13, 2021 9:48 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Tue Jul 13, 2021 3:31 pm

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Thu Jul 15, 2021 7:39 am

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 4 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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Mon Jul 19, 2021 5:51 am

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5530
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 » Mon Jul 19, 2021 7:49 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Thu Jul 22, 2021 8:49 am

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: 21
Joined: Thu Jun 10, 2021 11:00 am

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

Post by rlcgm » Thu Jul 22, 2021 1:13 pm

Hello Alex,

i have found it.

Cheers

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14755
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 » Thu Jul 22, 2021 2:38 pm

:)

Post Reply