Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pagecount PDF
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Titre:
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
Oracle
Divers
Thread ID:
01030995
Message ID:
01032422
Vues:
29
I don't know much about PDF specs so I would rather stick with my code because it makes less assumptions.

>It made me started and solved my current problem. In the time, I did some findings and managed to write few lines.
>Could you please glance it over. This code worked with all my files but possibly wont work for all PDF versions. Any ideas?
>
>Lparameter tcPdfFileName
>lcPdf = Filetostr(tcPdfFileName)
>Do Case
>Case Left(lcPdf,8) = "%PDF-1.2"
>	lnPos = At("/Count", lcPdf)
>	lPageCount=Substr(lcPdf,lnPos+6,10)
>	lPageCount=Val(lPageCount)
>Case Left(lcPdf,8) = "%PDF-1.4" Or Left(lcPdf,8) = "%PDF-1.5"
>	lPageCount=Occurs('/Page/',lcPdf)
>Otherwise
>	lPageCount=0
>Endcase
>Return lPageCount
>
>
>>You can use a free utility from http://www.appligent.com/products/ap_get_page_count/ap_get_page_count.php or write something using algorithm from http://www.users.on.net/~johnson/delphitips/. Below's a VFP solution based on http://lists.runrev.com/pipermail/use-revolution/2005-April/055538.html that I put together quickly. I didn't do much testing so use it on your own risk. It dosn't have any error checking either.
FUNCTION PdfPageCount
>>LPARAMETERS tcPdfFileName
>>LOCAL lnPageCount, lcPdf, lnPos, lcStr, lnPosStart, ;
>>      lcLine, lcObgPages, lnPosPages, lcPageCount
>>lnPageCount = Null
>>
>>lcPdf = FILETOSTR(tcPdfFileName)
>>lnPos = AT("/Type /Catalog", lcPdf)
>>
>>IF LEFT(lcPdf,8) = "%PDF-1.2"
>>	* The previous line has Pages object ref #
>>	lcStr = SUBSTR(lcPdf, lnPos-128, 128)
>>	lnPosStart = RAT(CHR(13), lcStr, 2)
>>	lcLine = STREXTRACT(SUBSTR(lcStr, lnPosStart), CHR(13), CHR(13))
>>ELSE
>>	* The next line has Pages object ref #
>>	lcLine = STREXTRACT(SUBSTR(lcPdf, lnPos, 256), CHR(13), CHR(13))
>>ENDIF
>>
>>* The 2nd word is the pages object ref #
>>lcObgPages = GETWORDNUM(lcLine,2)
>>* Find Pages object and extract page count
>>lnPosPages = AT(CHR(13) + lcObgPages + " 0 obj", lcPdf)
>>lcStr = SUBSTR(lcPdf, lnPosPages+1, 512)
>>lcPageCount = STREXTRACT(lcStr, "/Count ", " ")
>>lnPageCount = INT(VAL(lcPageCount))
>>
>>RETURN lnPageCount
>>
>>
>>>
>>>Need a free component to count no of pages in PDF.
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform