Size a New Document the Same Dimensions of an Image

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

aitchisj
User
Posts: 47
Joined: Mon Apr 04, 2011 4:44 am

Size a New Document the Same Dimensions of an Image

Post by aitchisj »

Hi There,

When using the "NewDocumentFromImages" function, is there any way to tell it to create the new document to match the dimensions of the image that is being added?

Thanks in advance,
-John
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Size a New Document the Same Dimensions of an Image

Post by Stefan - PDF-XChange »

Hello John,

I am afraid that no -currently there isn't such an option. You will need to set a standard page size for all pages (e.g. A4 or Ansi A/Letter) and all images will be scaled to fit on such pages.

Best,
Stefan
aitchisj
User
Posts: 47
Joined: Mon Apr 04, 2011 4:44 am

Re: Size a New Document the Same Dimensions of an Image

Post by aitchisj »

Thanks for the reply. Is this something that will be considered as a feature in a future version, or is this likely something that will not change?
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Size a New Document the Same Dimensions of an Image

Post by Stefan - PDF-XChange »

Hello aitchisj,

We've added this as a feature request, and after the initial build of ver3 of our Viewer is released - we will consider this for implementation.

Best,
Stefan
aitchisj
User
Posts: 47
Joined: Mon Apr 04, 2011 4:44 am

Re: Size a New Document the Same Dimensions of an Image

Post by aitchisj »

Okay, thank you.

When I use the end-user version of the PDF XChange Viewer, it looks like you can specify custom dimensions on the document when you create it. I have a 3rd party PDF library which can tell me the dimensions in pixels of the image I am adding to a new document (but unfortunately, their library doesn't add the image as nicely as your does in all cases which is why I'm trying to use yours instead)... I'm wondering if I can use that information to set a custom page size before I add the image to the document. Would this be possible?

The only problem I'm seeing with this approach (before actually trying it) is that I cannot specify a pixel-unit type, from what I can tell, when I give the document custom dimensions.

So, I have an image that is 300 x 400 pixels and want to size my new document to be the same when the picture gets added. Will this approach work, and if so, can you please shed give me an idea of what functions I should look at to accomplish this?

Thanks in advance,
-John
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Size a New Document the Same Dimensions of an Image

Post by Stefan - PDF-XChange »

Hello John,

Yes - this could work, but you will need to decide the DPI you would want to use for the newly created page and calculate it's dimensions using the desired DPI.

All you need to do is to divide your image's pixel dimensions by the desired DPI - and get the page dimensions in inches.
So for a 300x400 pixels image you will need a 1 x 1.33 inches page for 300 DPI resolution (print quality), or 4.166 x 5.555 inches if you want 72 DPI (screen quality).

Best,
Stefan
aitchisj
User
Posts: 47
Joined: Mon Apr 04, 2011 4:44 am

Re: Size a New Document the Same Dimensions of an Image

Post by aitchisj »

Thanks a million, this is super helpful.
8)
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Size a New Document the Same Dimensions of an Image

Post by Stefan - PDF-XChange »

You are welcome! :)

Cheers,
Stefan
aitchisj
User
Posts: 47
Joined: Mon Apr 04, 2011 4:44 am

Re: Size a New Document the Same Dimensions of an Image

Post by aitchisj »

I'm having a hard time trying to figure out how to call methods to size the page as I would expect. I've pored through postings on the forum here in addition to looking through the documentation and I can't get it to work. I want the image that is displayed in screen to not show any white space from the document that it is added to.

Problem 1: It looks like you can only specify the PaperWidth and PaperHeight properties for "FromImages" as unit type "pt". How does "pt" correspond back to inches?

Problem 2: My code is crashing, I need to know how to call the methods correctly.

Here's what I'm doing. To keep it simple, I've hardcoded the dimensions that I'm trying to adjust the image to.

Code: Select all

double		ld_width    // width in points
double		ld_height   // height in points

ld_width = 200
ld_height = 100

try 
	ole_viewer.object.SetProperty("FromImages.PaperWidth",ld_width)
	ole_viewer.object.SetProperty("FromImages.PaperHeight",ld_height)
	
	// convert the image into a PDF which effectively renders the image on screen
	ole_viewer.object.DoVerb("","NewDocumentFromImages",ps_absolute_filename,"",0)
catch(Throwable t2) 
	return -1
end try
It seems that the properties that are being set aren't lining up properly (ie: FromImages.PaperWidth, FromImages.PaperHeight). I probably don't have the right name but I'm not sure how it should be called. Please help.

Thanks in advance,
-John
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Size a New Document the Same Dimensions of an Image

Post by Stefan - PDF-XChange »

Hello John,

The correct way to set the paper dimensions is this:

ole_viewer.object.SetProperty("Operations.NewDocument.FromImages.Paper.PaperWidth", ld_width, 0);

Best,
Stefan
aitchisj
User
Posts: 47
Joined: Mon Apr 04, 2011 4:44 am

Re: Size a New Document the Same Dimensions of an Image

Post by aitchisj »

Stefan,

You must wear a cape and save people from burning buildings at night? I can picture you as nothing less than a superhero.

Thanks again, this worked and has saved the day!
-John 8)
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Size a New Document the Same Dimensions of an Image

Post by Stefan - PDF-XChange »

Shh! Don't expose my secret identity! :P

Cheers
Stefan