Opening Non-PDF files

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

Opening Non-PDF files

Post by jeffp »

The ability to open non-PDF files using the OpenDocFromPath is very nice. It allows me to convert a lot of non-PDF files to PDF.

However, I was wondering about some options that may control the PDF page size when converting to PDF upon open.

For example, the attached file contains two TIF files, one that is 1700x2200pixels and there the second is 1728x2255pixeks. When I open them using OpenDocFromPath, the first gets converted to 612x792points/8.5x11inches (which is what I expected) but the second gets converted to 414.7x541.2points/5.76x7.52inches (much smaller than expected).

Why does the second on get reduced so small. I would have expected it to be bigger than the first. What is your algorithm to determine PDF page size when opening non-PDF files? And are there any options to specify what page size I desire?

For example, let's say I have some small images but want them always converted to US Letter page size when opened in PDF?

Thanks.

--Jeff
Attachments
Test.zip
(88.54 KiB) Downloaded 66 times
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17910
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Opening Non-PDF files

Post by Tracker Supp-Stefan »

Hi Jeff,

One of your files is 200dpi - and this gets converted to the correct Letter page size (1700 / 200 = 8.5 inch). The other one is 300 dpi (1728 / 300 = 5.76 inch), and that's why it's dimensions in inches are smaller than for the other one with less pixels. I am not aware of a way you can control what DPI should be used, and am not sure if there is one, so I will need to check with my colleagues from the dev team. We will update this topic as soon as possible.

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

Re: Opening Non-PDF files

Post by jeffp »

Ok. That makes sense now. I didn't realize the second image was 300 dpi.

But it would still be nice to specify the default page size.

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

Re: Opening Non-PDF files

Post by Tracker Supp-Stefan »

Hi Jeff,

Yes it would be. I've already asked my colleagues for help with answering that part and if there is a way - we will post it here.

Regards,
Stefan
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Opening Non-PDF files

Post by Ivan - Tracker Software »

I'm afraid we cannot promise such feature for converters in general case because supporting such feature for different kind of formats might not be possible.

In your case, you can use op.imagesToDoc operation, where you can specify how images should be placed on the pages.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Opening Non-PDF files

Post by jeffp »

Yes, op.imagesToDoc looks promising.

Do you by chance have any sample code that uses this so I can get a better look at how you are setting up the options.

In my case, I'd want to create a blank PDF page with dimensions specified by my user and then insert an image onto that page. Sometimes I'd want it to scale the full size of the page and sometimes just place it in the upper left corner, etc.

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

Re: Opening Non-PDF files

Post by Tracker Supp-Stefan »

Hello Jeff,

In the Editor Full Demo project under "Operations" there is a "Images To Document" sample - please look at the code of this :)

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

Re: Opening Non-PDF files

Post by jeffp »

I'm using Delphi so sometimes it's a bit difficult for me to find my way around your C# code in the full demo, but after taking a look, it appears that the Images to Document sample is just displaying a build in dialog containing those options.

I'm looking for some C# code that is actually making the op.imagesToDoc call and programatically setting some of the options. I have my own options dialogs so I just need a way to transfer the options directlyh in code.

Am I missing something? Is there a specific .cs file I should be looking at in the full demo source?

Also, it looks like your scanning is done in the images to document context. Are there some calls into your scanning code I can make directly to launch a scan from within my program without having to use your built in dialog?

Thanks.

--Jeff
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Opening Non-PDF files

Post by jeffp »

Perhaps my working code would help here.

Below is my procedure to convert an image file into a PDF using op.imagesToDoc

I get an exception when trying to save out the PDF file;

I'm happy to use either Option 1 or Options 2 below but need help in setting this up right.

Code: Select all

procedure TMyPDF.ImageToDocEx(AInputFile, AOutputFile: String);
var
  nID: integer;
  pOp: IOperation;
  output: ICabNode;
  input: ICabNode;
  target: ICabNode;
  options: ICabNode;
  imgPath: IAFS_Name;
  ATargetDoc: IPXC_Document;
begin
  SetExceptionMask(exAllArithmeticExceptions);

  nID := INST_PXV.Str2ID('op.imagesToDoc', False);
  pOp := INST_PXV.CreateOp(nID);

  imgPath := INST_AFS.DefaultFileSys.StringToName(PChar(AInputFile), 0, nil);
  input := pOp.Params.Root['Input'];
  input.Add(dt_IUnknown).v := imgPath;

  options := pOp.Params.Root['Options'];
  options['KeepAspect'].v := True;

  //Option 1 - How do I place the Outlput in ATargetDoc??
  //output := pOp.Params.Root['Output'];


  //Option 2 - Set Options.TargetDoc to ATargetDoc
  ATargetDoc := INST_PXC.NewDocument;
  target := pOp.Params.Root['Options.TargetDoc'];
  target['DocID'].v := ATargetDoc.ID;
  target['Location'].v := 1;

  pOp.Do_(0);

  ATargetDoc.WriteToFile(PChar(AOutputFile), nil, 0);
end;
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Opening Non-PDF files

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Please look at other operation samples and set the imagesToDoc parameters accordingly - they are almost all documented and should not be that hard to fill. Also, here's the topic where this operation is being called:
https://www.pdf-xchange.com/forum3 ... oc#p103658

As for the direct scan launching - there is a op.scanToImages operation. Though it's not documented yet because it is a very big operation and requires a great amount of time of the developer who wrote it to write the description. Though we will try to update this in the nearest future.

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: Opening Non-PDF files

Post by Sasha - Tracker Dev Team »

As for your last post - the output of the operation is what the operation returns after the successful Do(). You don't need to fill it.
As for the option 2 - better use the NewDoc dictionary not the TargetDoc.

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

Re: Opening Non-PDF files

Post by jeffp »

the output of the operation is what the operation returns after the successful Do().
Can you show me in the Delphi code above how to get ATargetDoc assigned to the output of the Do(0);

I can't figure that out.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Opening Non-PDF files

Post by Sasha - Tracker Dev Team »

The output should be read after successful Do. You should not fill it before the operation. If needed the Output is being filled by the Do() method of the operation itself. For example this operation's sample illustrates how the Output is used:
https://sdkhelp.pdf-xchange.com/vie ... ewBlankDoc

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

Re: Opening Non-PDF files

Post by jeffp »

Ok. I'm really close. I just can get the typecast right for the output. The following code compiles but errors out at the line

ATargetDoc := IUnknown(pOp.Params.Root['Output'].v) as IPXC_Document;

Code: Select all

procedure TMyPDF.ImageToDocEx(AInputFile, AOutputFile: String);
var
  nID: integer;
  pOp: IOperation;
  output: ICabNode;
  input: ICabNode;
  new: ICabNode;
  options: ICabNode;
  imgPath: IAFS_Name;
  ATargetDoc: IPXC_Document;
begin
  nID := INST_PXV.Str2ID('op.imagesToDoc', False);
  pOp := INST_PXV.CreateOp(nID);

  imgPath := INST_AFS.DefaultFileSys.StringToName(PChar(AInputFile), 0, nil);
  input := pOp.Params.Root['Input'];
  input.Add(dt_IUnknown).v := imgPath;

  options := pOp.Params.Root['Options'];
  options['KeepAspect'].v := True;

  pOp.Do_(0);

  ATargetDoc := IUnknown(pOp.Params.Root['Output'].v) as IPXC_Document;

  ATargetDoc.WriteToFile(PChar(AOutputFile), nil, 0);
end;
I followed your op.newBlankDoc example, but the type casts in Delphi are sometimes problematic.

Can your Delphi expert help me on this one?

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

Re: Opening Non-PDF files

Post by Sasha - Tracker Dev Team »

Hello Jeff,

I will send him this question, though he will be able to look at this on Monday.

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: Opening Non-PDF files

Post by Sasha - Tracker Dev Team »

Hello Jeff,

Our Delphi expert is ill right now. He will answer this when he gets better.

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