IIXC_Image.InsertPage

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
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

IIXC_Image.InsertPage

Post by jeffp »

I'm essentially trying to append one 5 page .tif file to another with the code below. However, the InsertPage call below is not working. Can you tell me what I'm doing wrong.

Code: Select all

procedure TMyIMG.Test;
var
  i: Integer;
  AInput, ASrcInput: String;
  ADoc, ASrcDoc: IIXC_Image;
  APageCount, ASrcPageCount: Cardinal;
  APage: IIXC_Page;
begin
  AInput := ExtractFilePath(Application.ExeName) + 'Inputs\Numbers.tif';
  ASrcInput := ExtractFilePath(Application.ExeName) + 'Inputs\Letters.tif';

  INST_IXC.CreateEmptyImage(ADoc);
  INST_IXC.CreateEmptyImage(ASrcDoc);

  ADoc.Load(PChar(AInput), 0);
  ASrcDoc.Load(PChar(ASrcInput), 0);

  ADoc.Get_PagesCount(APageCount);
  ASrcDoc.Get_PagesCount(ASrcPageCount);

  for i := 0 to ASrcPageCount - 1 do
  begin
    ASrcDoc.GetPage(i, nil, APage);
    ADoc.InsertPage(APage, APageCount); //THIS DOES NOT WORK. Returns -2147024809
  end;
end;
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

I think I just figured it out. I needed to Clone the Pages before inserting them. Correct?
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: IIXC_Image.InsertPage

Post by Lzcat - Tracker Supp »

Hi jeffp.
Not exactly, but this is one of two options. Each IIXC_Page may belong to only one image or be standalone, and only standalone pages may be inserted to images. By default when loading image all pages from that image belongs to it (this is done to prevent decode entire image during load when you need only one page from it or even only information about pages). When you create new page or clone existing - resulting page became standalone. Also, you may call IIXC_Image::RemovePage - it will make page standalone and remove it from image pages list (but not from source file until you save changes). So if you need copy of page you should call clone, otherwise it will be better to call IIXC_Image::RemovePage.
HTH.
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

Thanks Lzcat. That makes sense to me know. I'll use RemovePage and Clone accordingly.

As a follow up, I'm doing more with your image calls now and have a few more questions.

[1]
If I load a .tif file into a IIXC_Image, how can I convert it from color to black and white?

[2]
If I load a multipage .tif file into a IIXC_Image, how can I save it out in .jpg format with each page being a separate file?

[3]
Where can I set compression options? Let say I load an uncompressed .tif and I now want to save it out with LZW compression.

[4]
What is the IIXC_Image.FormatID property. It seems it may help in the items above, but it doesn't seem to be documented.

[5]
After I run a cleanup routine line Deskew on a page, do I need to do anything to apply the changes before I save it back out to file? And what are the values for the nFlags parameter in Deskew?

Thanks.

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

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Hello Jeff,

[1] If I understood you correctly, you'll need to convert the tiff IIXC_Image to grayscale. If that's the case then you can do it like this:
https://gist.github.com/Polaringu/e0ecb ... e3b04d33d0

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

Actually, I wanted to convert to black and white, but it looks like I can use

IIXC_Page.ConvertToFormat(PageFormat_1Indexed);

I didn't see the ConvertToFormat call before, so thanks.

Any thoughts on the other items?
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

This isn't working. There must be something I'm missing in the code below. Take a look at the results in the attached zip file. I'm trying to convert the Color.tif file into BW and Grayscale but they don't turn out.

See attached zip and code below.

Code: Select all


procedure TMyIMG.Test;
var
  AInput, ADir: String;
  ADoc: IIXC_Image;
  APage: IIXC_Page;
begin
  ADir := ExtractFilePath(Application.ExeName) + 'Outputs\';
  AInput := ADir + 'Color.tif';

  INST_IXC.CreateEmptyImage(ADoc);
  ADoc.Load(PChar(AInput), 0);
  ADoc.GetPage(0, nil, APage);
  APage.ConvertToFormat(PageFormat_1Indexed);
  ADoc.Save(PChar(ADir + '1Indexed.tif'), CreationDisposition_Overwrite);
  ADoc := nil;

  INST_IXC.CreateEmptyImage(ADoc);
  ADoc.Load(PChar(AInput), 0);
  ADoc.GetPage(0, nil, APage);
  APage.ConvertToFormat(PageFormat_8Gray);
  ADoc.Save(PChar(ADir + '8Gray.tif'), CreationDisposition_Overwrite);
  ADoc := nil;

  INST_IXC.CreateEmptyImage(ADoc);
  ADoc.Load(PChar(AInput), 0);
  ADoc.GetPage(0, nil, APage);
  APage.ConvertToFormat(PageFormat_8AlphaGray);
  ADoc.Save(PChar(ADir + '8AlphaGray.tif'), CreationDisposition_Overwrite);
  ADoc := nil;
end;

Attachments
Color.zip
(3.6 MiB) Downloaded 95 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Hello Jeff,

[2-4] Here's how the code would look like:
https://gist.github.com/Polaringu/46461 ... 42fc39038b
Though you'll need to use our ImagesTest utility to know all of the images format parameters and values (see the attachment).
When you launch it, go into the "View \ Encoders List..." menu. Then the "Encoder's Features" dialog should open.
Image
There you will see all of the possible values for each format. Compare it with the code I provided and use that accordingly.

Cheers,
Alex
Attachments
ImagesTest.rar
(1.02 MiB) Downloaded 89 times
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

Ok. Your last post was extremely helpful.

Here's my convert to BW code. It works great for color images, but if I try to convert the attached grayscale.tif image using the code, it turns it into a completely black image.

Is there anything I'm doing wrong?

Code: Select all

procedure TMyIMG.ConvertToBW;
var
  i, APageCount: Cardinal;
  iPage: IIXC_Page;
begin
  if Assigned(FDoc) then
  begin
    APageCount := GetPageCount;
    for i := 0 to APageCount - 1 do
    begin
      FDoc.GetPage(i, nil, iPage);
      iPage.ClearFormatParams;
      iPage.Set_FmtInt(FP_ID_FORMAT, FMT_TIFF_ID);
      iPage.Set_FmtInt(FP_ID_ITYPE, 1); //1=BW
    end;
  end;
end;
Attachments
GrayScale.zip
(1.41 MiB) Downloaded 95 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Hello Jeff,

I've tried doing this code:

Code: Select all

PDFXEdit.IIXC_Inst iInst = (PDFXEdit.IIXC_Inst)pdfCtl.Inst.GetExtension("IXC");
PDFXEdit.IIXC_Image iImage = iInst.CreateEmptyImage();
iImage.Load(System.IO.Directory.GetParent(System.Environment.CurrentDirectory).Parent.FullName + "\\Resources\\GrayScale.tif");
int nIndex = 0;
while (iImage.PagesCount > nIndex)
{
	PDFXEdit.IIXC_Page iPage = iImage.GetPage(0);
	iImage.RemovePageByIndex(0);
	iPage.ClearFormatParams();
	iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_FORMAT, (uint)PDFXEdit.IXC_ImageFileFormatIDs.FMT_TIFF_ID);
	iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_ITYPE, 1); //

	PDFXEdit.IIXC_Image tmpImg = iInst.CreateEmptyImage();
	tmpImg.InsertPage(iPage);
	tmpImg.Save(@"C:\Test\" + Convert.ToString(nIndex++) + ".tif", PDFXEdit.IXC_CreationDisposition.CreationDisposition_Overwrite);
}
And everything worked correctly - the resulting image was grayscale.
If you want you can provide us a small working sample that we can try and debug.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

Ok. I've got a really strange issue for you. The code below successfully converts Color.tif to Grayscale.tif.

However, if I run the code twice, the second time the GrayScale.tif comes out completely black.

The code below replicates this by just running the main code twice. Attached is my original Color.tif, but I don't think it has to do with this image. It seems like it is an issue with not clearing out the image object. Is there a call I'm missing to clear the image object when I'm done with it.

Code: Select all

procedure TMyIMG.Test;
var
  APageCount: Cardinal;
  AInput, AOutput, ADir: String;
  ADoc, ATempDoc: IIXC_Image;
  APage: IIXC_Page;
begin
  ADir := ExtractFilePath(Application.ExeName) + 'Outputs\';
  AInput := ADir + 'Color.tif';
  AOutput := ADir + 'GrayScale.tif';

  INST_IXC.CreateEmptyImage(ADoc);
  INST_IXC.CreateEmptyImage(ATempDoc);

  ADoc.Load(PChar(AInput), 0);

  ADoc.Get_PagesCount(APageCount);
  while (APageCount > 0) do
  begin
    ADoc.GetPage(0, nil, APage);
    ADoc.RemovePageByIndex(0);

    APage.ClearFormatParams;
    APage.Set_FmtInt(FP_ID_FORMAT, FMT_TIFF_ID);
    APage.Set_FmtInt(FP_ID_ITYPE, 10); //1=BW, 10=Grayscale

    ATempDoc.InsertPage(APage, APageCount);

    ADoc.Get_PagesCount(APageCount);
  end;
  ATempDoc.Save(PChar(AOutput), CreationDisposition_Overwrite);
  ADoc := nil;
  ATempDoc := nil;

  msgbox('Stop and Check File. It will look good');

  INST_IXC.CreateEmptyImage(ADoc);
  INST_IXC.CreateEmptyImage(ATempDoc);

  ADoc.Load(PChar(AInput), 0);

  ADoc.Get_PagesCount(APageCount);
  while (APageCount > 0) do
  begin
    ADoc.GetPage(0, nil, APage);
    ADoc.RemovePageByIndex(0);

    APage.ClearFormatParams;
    APage.Set_FmtInt(FP_ID_FORMAT, FMT_TIFF_ID);
    APage.Set_FmtInt(FP_ID_ITYPE, 10); //1=BW, 10=Grayscale

    ATempDoc.InsertPage(APage, APageCount);

    ADoc.Get_PagesCount(APageCount);
  end;
  ATempDoc.Save(PChar(AOutput), CreationDisposition_Overwrite);
  ADoc := nil;
  ATempDoc := nil;

  msgbox('Stop and Check File. It will be ALL BLACK');

end;
Attachments
Color.zip
(3.23 MiB) Downloaded 93 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Hello Jeff,

I tried running your code with your sample image on C# - it all worked perfectly - the resulting image is grayscale:

Code: Select all

private void iIXCExperimentsToolStripMenuItem_Click(object sender, EventArgs e)
{
	PDFXEdit.IIXC_Inst iInst = (PDFXEdit.IIXC_Inst)pdfCtl.Inst.GetExtension("IXC");
	string sDir = System.IO.Directory.GetParent(System.Environment.CurrentDirectory).Parent.FullName + "\\Resources\\";
	string sInput = sDir + "Color.tif";
	string sOutput = sDir + "Grayscale.tif";
	PDFXEdit.IIXC_Image iDoc = iInst.CreateEmptyImage();
	PDFXEdit.IIXC_Image iTempDoc = iInst.CreateEmptyImage();

	iDoc.Load(sInput);
	while (iDoc.PagesCount > 0)
	{
		PDFXEdit.IIXC_Page iPage = iDoc.GetPage(0);
		iDoc.RemovePageByIndex(0);

		iPage.ClearFormatParams();
		iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_FORMAT, (uint)PDFXEdit.IXC_ImageFileFormatIDs.FMT_TIFF_ID);
		iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_ITYPE, 10); //1=BW, 10=Grayscale

		iTempDoc.InsertPage(iPage);
	}

	iTempDoc.Save(sOutput, PDFXEdit.IXC_CreationDisposition.CreationDisposition_Overwrite);
	iDoc = null;
	iTempDoc = null;

	iDoc = iInst.CreateEmptyImage();
	iTempDoc = iInst.CreateEmptyImage();

	iDoc.Load(sInput);
	while (iDoc.PagesCount > 0)
	{
		PDFXEdit.IIXC_Page iPage = iDoc.GetPage(0);
		iDoc.RemovePageByIndex(0);

		iPage.ClearFormatParams();
		iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_FORMAT, (uint)PDFXEdit.IXC_ImageFileFormatIDs.FMT_TIFF_ID);
		iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_ITYPE, 10); //1=BW, 10=Grayscale

		iTempDoc.InsertPage(iPage);
	}

	iTempDoc.Save(sOutput, PDFXEdit.IXC_CreationDisposition.CreationDisposition_Overwrite);
	iDoc = null;
	iTempDoc = null;
}
If you can, please provide us a small working sample that we can test and debug if the problem occurs. Because right now i don't see a problem from our side.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

The code I posted was intended to be a working sample. You just need to place it in a Delphi unit and compile.

Do you still want me to put it in a full project?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Well the thing is that we can't recreate this behavior on our side. So the best thing that I imagine would be a new small simple project that converts that image into the grayscale and reproduces invalid behavior on your side. Also, include the debug exe file from your side - maybe it has to do something with your local machine (settings, libraries etc). Because right now we can't help because we can't recreate that behavior that you got.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

See attached file. Just drop your core dll and resource file into the main folder and it should run just fine.
Attachments
EditorSDK_Test.zip
(4.62 MiB) Downloaded 91 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Got it. Will investigate and write back with an answer asap.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Hello Jeff,

We managed to reproduce that problem. There seems to be some kind of problem with the tiff encoder when the LZW compression is used. We will try to fix this in one of the nearest future builds. The workaround is to use any other compression type for example:

Code: Select all

APage.Set_FmtInt(FP_ID_COMP_TYPE, 8); //Deflate compression
APage.Set_FmtInt(FP_ID_COMP_LEVEL, 10);
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

LZW compression is essential for what I do, so I'll need to wait for the fix.

Any idea when and what build number I should be looking for?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: IIXC_Image.InsertPage

Post by Tracker Supp-Stefan »

Hello Jeff,

Just spoke with Sasha and he says that we will try to fix this for build 318 planned for release around the end of June, however Sasha can not guarantee this at 100%. And the suggestion for using other compression methods is meant to be just a temporary workaround while we do the proper fix.

Regards,
Stefan
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

Thanks. That will be fine.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17948
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: IIXC_Image.InsertPage

Post by Tracker Supp-Stefan »

Thanks for the understanding Jeff!

Cheers,
Stefan
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

For black and white TIFF files do you offer the CCITTFAX4 compression option? (very common in other image packages)

Also, what's the difference between LZW and Deflate w/level of 10 compression?

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

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

Yes we do offer it, it would look like this:

Code: Select all

iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_FORMAT, (uint)PDFXEdit.IXC_ImageFileFormatIDs.FMT_TIFF_ID);
iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_ITYPE, 1); //
iPage.set_FmtInt((uint)PDFXEdit.IXC_FormatParametersIDS.FP_ID_COMP_TYPE, (uint)PDFXEdit.IXC_ImageFileCompressionTypes.IComp_CCITTFax4);
As for the difference, its two entirely different compression types. Deflate uses ZIP which in most cases will give optimal results. Though the result is always input based - some files will give entirely different results.
By the way, the LZW problem is already fixed. We will launch a dev build soon where you can try the fixes.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: IIXC_Image.InsertPage

Post by jeffp »

Awesome. Where will the dev build be posted?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: IIXC_Image.InsertPage

Post by Sasha - Tracker Dev Team »

We will post the links here:
https://forum.pdf-xchange.com/ ... 66&t=25943
Also, all of the links and attachments will be updated in that topic when needed, so there always will be a latest version there.

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