Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read pagesize and number of pages in a pdf 1

Status
Not open for further replies.

GriffMG

Programmer
Mar 4, 2002
6,288
1
38
FR
Has anyone tried to do this?

I want to open a pdf file in vfp and determine the page size and number of pages - so I can compare it with what the 'uploader' to my web sites have entered and let an operator know that it may have been misdescribed...

Any help well appreciated

Martin

Regards

Griff
Keep [Smile]ing
 
Martin,

Most PDF viewer controls should let you do this. You can usually embed a control in a form, then have it open the PDF and return various properties, such as page count and page size. You don't need to make the document visible to do that.

For example, PDFViewer is an ActiveX control that appears to do what I've just described. I don't have a URL for it, but it's from Skysof Software, so you should be able to find it. Note that I am not specifically recommending this product; it's just an example of one that might meet your requirement.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Chris

Thanks for that, I had spotted that with a google search - I wondered if anyone had tried actually opening a PDF in VFP (using fopen() or somesuch) and tried to extract that info manually?

I've found my imageviewer component can read the sizes in inches x 100, so that's a start - I haven't found a pagecount yet!

Regards

Griff
Keep [Smile]ing
 
Martin said:
I wondered if anyone had tried actually opening a PDF in VFP (using fopen() or somesuch) and tried to extract that info manually?
If you FILETOSTR("pdffilename.pdf"), you might be able to determine the page count info from the string, depending on what program distilled the postscript file.


I think you will find pdfinfo.exe the most reliable method.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Thanks Brigmar
Thanks Mike

I'm playing with the sizes now...

Regards

Griff
Keep [Smile]ing
 
I *could* look at the PDFInfo source and see if there is a clue in there!


Regards

Griff
Keep [Smile]ing
 
Did some more digging/experimenting, and try this:
Code:
oExch = CreateObject("AcroExch.PDDoc")
WITH oExch
  .open('C:\Scratch\PerlWin32_quickref.pdf')
  lnNumPages = .GetNumPages()
  DIMENSION laPageSize[lnNumPages,2]
  FOR i = 1 TO lnNumPages
    WITH .AcquirePage(i-1).GetSize
      laPageSize[i,1] = .x
      laPageSize[i,2] = .y
    ENDWITH
  NEXT i
  .close()
ENDWITH
RELEASE oExch

The laPageSize array now contains the size of each page
 
Hi Chris

I have discovered that the ImageViewerCP Pro ocx control (that I am using to create thumbnails from smallish PDF files) can also tell me the total pages!

So I'm done!

I'm using the fileHeight and filewidth to determine the probable page size, and then reloading the image in a LoadMultiPage mode and GetTotalPage to get the number of pages.

Like this:
Code:
M.PDFWIDTH = INT(MAX(THISFORM.IMAGEVIEWER1.FILEHEIGHT,THISFORM.IMAGEVIEWER1.FILEWIDTH)/100)
M.PDFHEIGHT = INT(MIN(THISFORM.IMAGEVIEWER1.FILEHEIGHT,THISFORM.IMAGEVIEWER1.FILEWIDTH)/100)
DO CASE
	CASE m.PDFWIDTH = 11 .AND. m.PDFHEIGHT = 8
		M.DRGSIZE = "A4"
	CASE m.PDFWIDTH = 16 .AND. m.PDFHEIGHT = 11
		M.DRGSIZE = "A3"
	CASE m.PDFWIDTH = 23 .AND. m.PDFHEIGHT = 16
		M.DRGSIZE = "A2"
	CASE m.PDFWIDTH = 33 .AND. m.PDFHEIGHT = 23
		M.DRGSIZE = "A1"
	CASE m.PDFWIDTH = 46 .AND. m.PDFHEIGHT = 33
		M.DRGSIZE = "A0"
	OTHERWISE
		M.DRGSIZE = ""
ENDCASE

THISFORM.IMAGEVIEWER1.LOADMULTIPAGE(THISFORM.IMAGEVIEWER1.FILENAME, 1)
M.NUMPAGES = THISFORM.IMAGEVIEWER1.GETTOTALPAGE


Regards

Griff
Keep [Smile]ing
 
Thanks Chris,

I don't think it's worthy of a FAQ, but I'm pleased to take your star!

Incidently, if you do use it (the ocx thingie) watch out a bit, because it seems to have a memory leak and can't handle enormous PDF files very well.

Stick to about 4MB and restart the app after reading a dozen or so...



Regards

Griff
Keep [Smile]ing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top