Convert images to PDF

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, 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
chavas
User
Posts: 141
Joined: Tue Mar 15, 2016 12:21 pm

Convert images to PDF

Post by chavas »

Hi,

I have a list of image files, which I would like to convert to PDF. I am using VB.net. I have written the following code-
Dim m_Inst As PDFXEdit.PXV_Inst = Nothing
Dim m_pxcInst As PDFXEdit.IPXC_Inst = Nothing
Dim m_nID1 As Integer = 0
m_Inst = New PDFXEdit.PXV_Inst()
m_Inst.Init()
m_pxcInst = CType(m_Inst.GetExtension("PXC"), PDFXEdit.IPXC_Inst)
m_nID1 = m_Inst.Str2ID("op.imagesToDoc", False)
Dim arrimagefiles as new arraylist
arrimagefile.addrange(collection) ///contains list of image files with full path
Dim Op As PDFXEdit.IOperation = m_Inst.CreateOp(m_nID1)
Dim Input As PDFXEdit.ICabNode = Op.Params.Root("Input")
For i As Integer = 0 To arrimagefiles.Count - 1
Input.Add().v = arrimagefiles(i)
Next
Op.Do()

In the above code, Input.add().v throws error as it is expecting "IAFS_NamesCollection"

Pls help...

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

Re: Convert images to PDF

Post by Sasha - Tracker Dev Team »

Hello Charu,

In situations like this, you will need to do the following steps (I'll write an example for our case):
1) Search the wiki (in the tree search box) for the IAFS_NamesCollection and it will return this:
https://sdkhelp.pdf-xchange.com/vie ... Collection
2) In the See Also part of the page you will see the methods that use this interface. You'll need to find something that would create\return the needed interface. In our case, we'll need to create one, so the IAFS_Inst::CreateNames method sounds good:
https://sdkhelp.pdf-xchange.com/vie ... reateNames
3) So now you will have an empty names collection to which you will need to add names. Again, looking at the wiki help page, the Add method require the IAFS_Name:
https://sdkhelp.pdf-xchange.com/vie ... ection_Add
4) Searching the wiki (in the tree search box) for the IAFS_Name interface to see what it's like:
https://sdkhelp.pdf-xchange.com/view/PXV:IAFS_Name
5) And what you will see - it event contains a sample on how to use it. Now you will need to create the names you need and fill the names collection.
6) Try passing the filled names collection to the operation.

If something goes wrong, what to do:
1) Read the operation input description:
https://sdkhelp.pdf-xchange.com/vie ... magesToDoc
2) See that the names collection part can be skipped and the IAFS_Name objects can be added to the input array.
3) Try the operation again.

Please try those steps with similar problems - it will save a ton of your an our time :wink:

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
chavas
User
Posts: 141
Joined: Tue Mar 15, 2016 12:21 pm

Re: Convert images to PDF

Post by chavas »

Hi,

Thank you for the information. I am trying to extract images from PDF. but 'FormatParams ' link is broken.
https://sdkhelp.pdf-xchange.com/vie ... es_Options

I would like to be able to extract image in B&W, Grey scale, color (RGB, ARGB) depending on user choice. Pls guide me how to set 'FormatParams'

I also noticed the sample code for exporttoimages-
https://sdkhelp.pdf-xchange.com/vie ... rtToImages

The code has specified - fmtParams["ITYP"].v , twice. First time it says,"Image type" and second time it says,"Thumbnail".
I am confused. Pls guide
The code below is copied from your sample of Exporttoimages-
fmtParams["DPIY"].v = 150;
22 //Image format
23 fmtParams["FMT"].v = 1414088262; //TIFF
24 //Image type
25 fmtParams["ITYP"].v = 16; //24 TrueColor
26 //Use Predictor
27 fmtParams["PRED"].v = 1; //Yes
28 //Thumbnail
29 fmtParams["ITYP"].v = 0; //No
30
31 Op.Do();

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

Re: Convert images to PDF

Post by Sasha - Tracker Dev Team »

Hello Charu,

Please try using the ImagesTest utility available from here:
https://forum.pdf-xchange.com/ ... 66&t=25943

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
chavas
User
Posts: 141
Joined: Tue Mar 15, 2016 12:21 pm

Re: Convert images to PDF

Post by chavas »

Pls guide me how to set 'FormatParams' The documentation is missing.

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

Re: Convert images to PDF

Post by Sasha - Tracker Dev Team »

Hello Charu,

That was a small mistake in the code - thanks for noticing. The thumbnails format parameter should be called THUM.
Take ID from the possible image formats here:
https://sdkhelp.pdf-xchange.com/vie ... eFormatIDs
Take the needed format parameter here:
https://sdkhelp.pdf-xchange.com/vie ... ametersIDS
After that, you can use from the ImagesTest utility to see what values are available for the needed image format and set the Cab nodes using the Format Parameters and the needed value.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Convert images to PDF

Post by DolphinMann »

Alex,

I have reviewed the parameters and ImageTest program, both were useful.

What does the "THUM" do when set to true? I tried using it to create a few images and got some strange results so it was not clear to me. The image seemed the same size as when I set the value to false, only it wouldn't load in Windows viewer. It did open in GIMP or other tools but again, did not appear any different.

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

Re: Convert images to PDF

Post by Sasha - Tracker Dev Team »

Hello Mark,

The THUM (thumbnail) parameter is only supported by a few decoder formats, for example TIFF files. The Thumbnails are used for image's page previews for example. You can google that for more details if you want though I suspect you won't need that one.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Convert images to PDF

Post by DolphinMann »

I have come up with another question.

When setting: fmtParams["ITYP"].v

I noticed the sample provided uses 16, I then found the other options in the "FullDemo" application UI for the other color modes(32 for color w/Alpha for example).

However it seems the value of "8" can mean both grayscale & indexed. How do I specify which one I intend when writing the code? If there another format param I should use? It was not immediately clear from the FullDemo application or API guide.

Example:
if (useColor)
{
fmtParams["ITYP"].v = 32; //32 TrueColor w/alpha
}
else
{
fmtParams["ITYP"].v = 8; //grayscale not indexed and dithered
}
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert images to PDF

Post by Sasha - Tracker Dev Team »

Hello DolphinMann,

As you can see from the ImagesTest utility, the ImageType parameters differ from the encoder type. For example, for BMP, the 32True-Color value is 21 and 8Indexed value is 9.
Capture16.PNG
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
DolphinMann
User
Posts: 158
Joined: Mon Aug 04, 2014 7:34 pm

Re: Convert images to PDF

Post by DolphinMann »

I forgot about the image test program, thank you. Then value I needed was found within.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Convert images to PDF

Post by Sasha - Tracker Dev Team »

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