Page 1 of 1
Add a grafic like JPG or BMP on a page
Posted: Thu Jun 10, 2021 12:31 pm
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;
}
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jun 10, 2021 12:36 pm
by Sasha - PDF-XChange
Hello rlcgm,
Check out the CoreAPIDemo application - it holds plenty of samples:
https://github.com/tracker-software/PDF ... oreAPIDemo
Cheers,
Alex
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jun 10, 2021 1:26 pm
by rlcgm
Hello Alex,
i use the sample code from the c# example, but i get a empty page.
Cheers
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jun 10, 2021 1:46 pm
by Sasha - PDF-XChange
Hello rlcgm,
Have you tried using that sample directly? Does it give correct results with your image?
Cheers,
Alex
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jun 10, 2021 2:14 pm
by rlcgm
Hello Alex,
i have translated from c# to c++ and the code is in the first post.
Cheers
Re: Add a grafic like JPG or BMP on a page
Posted: Fri Jun 11, 2021 7:23 am
by Sasha - PDF-XChange
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
Re: Add a grafic like JPG or BMP on a page
Posted: Fri Jun 11, 2021 7:52 am
by rlcgm
Thanks, i will check it.
Add a grafic like JPG or BMP on a page
Posted: Fri Jun 11, 2021 1:08 pm
by Sasha - PDF-XChange
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jun 24, 2021 5:58 am
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
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jun 29, 2021 7:59 am
by Sasha - PDF-XChange
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
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jun 29, 2021 1:07 pm
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
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jun 29, 2021 2:05 pm
by Sasha - PDF-XChange
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
Re: Add a grafic like JPG or BMP on a page
Posted: Wed Jun 30, 2021 5:18 pm
by rlcgm
Hallo Alex,
please, give me a short example for create a new pdf file with insert a jpg grafic.
Cheers
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jul 01, 2021 6:17 am
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
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jul 01, 2021 8:20 am
by Sasha - PDF-XChange
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
Re: Add a grafic like JPG or BMP on a page
Posted: Mon Jul 05, 2021 6:10 am
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
Re: Add a grafic like JPG or BMP on a page
Posted: Mon Jul 05, 2021 7:33 am
by Sasha - PDF-XChange
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
Re: Add a grafic like JPG or BMP on a page
Posted: Mon Jul 05, 2021 9:36 am
by rlcgm
Hello Alex,
the same problem = empty page.
Cheers
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jul 06, 2021 9:05 am
by Sasha - PDF-XChange
Hello rlcgm,
In two cases that I mentioned earlier?
Cheers,
Alex
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jul 06, 2021 9:13 am
by rlcgm
Hello Alex,
but what is wrong?
Cheers
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jul 06, 2021 3:09 pm
by Sasha - PDF-XChange
Hello rlcgm,
Well, we'll still need an answers for the behavior in both cases - then we can tell more.
Cheers,
Alex
Re: Add a grafic like JPG or BMP on a page
Posted: Wed Jul 07, 2021 9:50 am
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
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jul 13, 2021 7:58 am
by rlcgm
Hallo Alex,
are there any new findings on the subject?
Cheers
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jul 13, 2021 9:48 am
by Sasha - PDF-XChange
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
Re: Add a grafic like JPG or BMP on a page
Posted: Tue Jul 13, 2021 3:31 pm
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
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jul 15, 2021 7:39 am
by Sasha - PDF-XChange
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
If this works correctly on both machines then I will share the project code.
Cheers,
Alex
Re: Add a grafic like JPG or BMP on a page
Posted: Mon Jul 19, 2021 5:51 am
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
Re: Add a grafic like JPG or BMP on a page
Posted: Mon Jul 19, 2021 7:49 am
by Sasha - PDF-XChange
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
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jul 22, 2021 8:49 am
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
Re: Add a grafic like JPG or BMP on a page
Posted: Thu Jul 22, 2021 1:13 pm
by rlcgm
Hello Alex,
i have found it.
Cheers
Add a grafic like JPG or BMP on a page
Posted: Thu Jul 22, 2021 2:38 pm
by Stefan - PDF-XChange