Getting the number of pages in a PDF [JavaScript in CS3]

Hello All,
I am an InDesign JavaScript newbie that will be posting questions in the near future. Before asking a lot of questions, I would like to contribute something to the group. Here is a function that will query a PDF and return the number of pages that it contains. This is useful for placing multi-page PDFs.
Rick Quatro
rick at frameexpert dot com
function GetPdfPageCount(oFile)
// Convert filename to a VBS-friendly format.
var sFile = oFile.fsName.replace(/\\/g, "\\\\");
var aFile = [sFile]; // An array of arguments.
if(File.fs == "Windows"){
var sGetPdfPageCount = "Dim AcroApp, AVDoc, PDDoc, iPages\r";
sGetPdfPageCount += "Set AcroApp = CreateObject(\"AcroExch.App\")\r";
sGetPdfPageCount += "Set PDDoc = CreateObject(\"AcroExch.PDDoc\")\r";
sGetPdfPageCount += "If PDDoc.Open(arguments(0)) Then\r";
sGetPdfPageCount += " iNumPages = PDDoc.GetNumPages()\r";
sGetPdfPageCount += " Set oInDesign = CreateObject(\"InDesign.Application\")\r";
sGetPdfPageCount += " oInDesign.ScriptArgs.SetValue \"ScriptArgumentA\", CStr(iNumPages)\r";
sGetPdfPageCount += " PDDoc.Close()\r";
sGetPdfPageCount += "End If\r";
sGetPdfPageCount += "Set AcroApp = Nothing\r";
sGetPdfPageCount += "Set PDDoc = Nothing\r";
app.doScript(sGetPdfPageCount, ScriptLanguage.visualBasic,aFile);
return Number(app.scriptArgs.getValue("ScriptArgumentA"));
else
return 0;

Hi Peter,
The solutions that open the PDF files with f.open and look for particular strings don't work for all of the PDF files I have. This one seems to work well for me so far. Thanks for the link.
Rick

Similar Messages

  • How to get the number of pages in a PDF file with AcroPDF ActiveX control

    Hi,
    I am using the AcroPDF ActiveX control provided by Acrobat Reader and Professionals(version 9). I just wonder if I using LoadFile to load a PDF document, how can I know the number of pages in that PDF? I do not find any properites or methods that can do that.
    Thanks
    Alan

    Hi unk2,
    There's no functionality in the Acrobat.com online services to do a character count. But, you could use ExportPDF to convert your PDF file to Word format, and then do your character count in Word.
    Please let us know if you need additional assistance.
    Best,
    Sara

  • How to get the number of pages when assemble pdf with DDX

    Hi,
         I have tried to add two bookmarks to one pdf with DDX(in java code),
         the first bookmark I shall add to the first page,and the second I shall add to the second page....
        the question is:
         If the pdf has only one page, I will not add bookmarks to the pdf. so I need to get the pages of pdf before my processing.
        but I did not found any APIs in the SDK about it .
         Can anyone help me.
         thanks.

    I have solve the problem myself
    I use the tag "DocumentInformation" in DDX and get the xml after invoking DDX,
    the xml contain the information of document
    the sample DDX as:
         <?xml version="1.0" encoding="UTF-8"?>
       <DDX xmlns="http://ns.adobe.com/DDX/1.0/">
               <DocumentInformation source="mergedPDF" result="doc_info.xml" />
       </DDX>

  • Getting the number of pages in excel sheet or current page using OLE2

    Hi,
    I fill an excel sheet using CLIENT_OLE2 from Oracle 10g form,
    I want to get the number of pages in sheet or the number of current page,
    after searching for solution I found this example on VB:
    Sub GetPageCount()
    Dim iView As Integer
    Dim iHorizontalBreaks As Integer
    Dim iVerticalBreaks As Integer
    Dim iPageCount As Integer
    On Error Resume Next
    'go to the range and set PrintArea to the range name
    Application.Goto Reference:="ABC"
    ActiveSheet.PageSetup.PrintArea = Selection.Address
    'turn monitor flickering/updating off
    Application.ScreenUpdating = False
    'remember current View setting
    iView = Application.ActiveWindow.View
    'refresh the print area
    Application.ActiveWindow.View = xlPageBreakPreview
    'set view back
    Application.ActiveWindow.View = xlNormalView
    'turn monitor flickering/updating back on
    Application.ScreenUpdating = True
    'calculate the # of pages
    iHorizontalBreaks = ActiveSheet.HPageBreaks.Count + 1
    iVerticalBreaks = ActiveSheet.VPageBreaks.Count + 1
    iPageCount = iHorizontalBreaks * iVerticalBreaks
    How can I implement this using CLIENT_OLE2?
    Any assistance would be welcome.
    Thanks

    IF all the panels were exactly the same width (highly doubtful for a roll-fold) and IF ID supported 12 pages per spread (it doesn't) then it might be less work to make 12-page spreads and place the PDF twice, but since I think there's a really good chance you'll need to adjust the positioning for at least 22 pages, that seems doomed.
    I wouldn't even bother, in this case, with facing pages. Presumably they want this for the screen, so there's nothing gained from facing pages or multiple columns. You can either make the file with 24 pages and place the PDF 12 times for each page of the PDF, or place each page of the PDF once in a 2-page file, then copy the pages and reposition the image in the frame for each panel. The big thing here is to put the PDF into frames that are the same size as the new page (so they get cropped down to one-panel on each page). Then it's just a case of sliding the the PDF left or right in the frame to expose the next panel.

  • How to get the number of page by creating OLE microsoft word document

    Hihi Experts,
    I have generated a word document using ole in sap abap report.
    May i know which command can i use to call the word object to get the number of page before closing the word document?
    eg. call method of wordobj 'insertpagefield' ? and i need to require the page number in a variable eg. gv_pagenumber for other filtering purposes.
    Thanks and Regards,
    li Hui
    Edited by: lihui lil on Aug 11, 2009 9:35 AM
    Edited by: lihui lil on Aug 11, 2009 12:36 PM

    hi,
    use the following code:
    CALL METHOD OF gv_selection 'Information' = gv_curpage
        EXPORTING
        #1 = 3. " get current page number
      CALL METHOD OF gv_selection 'TypeText'
        EXPORTING
        #1 = gv_curpage. "show current page number
      CALL METHOD OF gv_selection 'TypeText'
        EXPORTING
        #1 = ' of '.
      CLEAR gv_endpage.
      CALL METHOD OF gv_selection 'Information' = gv_endpage
        EXPORTING
        #1 = 4. "get total page number
      CALL METHOD OF gv_selection 'TypeText'
        EXPORTING
        #1 = gv_endpage. " show total page number
    Edited by: VoonHan on Oct 13, 2009 7:35 AM

  • Function Module to determine the number of pages in a pdf file

    Hi All,
    Is there any standard function module to determine the number of pages in a pdf file?
    Thanks,
    Sai

    Hi unk2,
    There's no functionality in the Acrobat.com online services to do a character count. But, you could use ExportPDF to convert your PDF file to Word format, and then do your character count in Word.
    Please let us know if you need additional assistance.
    Best,
    Sara

  • How to get  the number of page which exists the change bar ?

    In FDK development, I want to find the number of page which exists the change bar.

    zhaopeng,
    You can get the page number by querying the FP_PageNum property of the FO_Page object:
    pageNum = F_ApiGetInt(docId, pageId, FP_PageNum);
    ...or you can use FP_PageNumString if you are using string page numbers.
    If you do not have the ID of the FO_Page object, you can get it from the paragraph ID using the following function, courtesy of Rick Quatro, posted to the Yahoo Framedev list. Send the paragraph (FO_Pgf) ID as oObj and it will return the page ID:
    F_ObjHandleT GetPage(F_ObjHandleT oDoc, F_ObjHandleT oObj)
    F_ObjHandleT oFrame = 0;
    IntT iObjType;
    F_ObjHandleT oRow, oCell;
    while(oObj)
    oFrame = oObj;
    iObjType = F_ApiGetObjectType(oDoc, oObj);
    switch(iObjType){
    case FO_SubCol:
    oObj = F_ApiGetId(oDoc, oObj, FP_ParentTextFrame);
    break;
    case FO_Tbl:
    oRow = F_ApiGetId(oDoc, oObj, FP_FirstRowInTbl);
    oCell = F_ApiGetId(oDoc, oRow, FP_FirstCellInRow);
    oObj = oCell;
    break;
    case FO_Row:
    oCell = F_ApiGetId(oDoc, oObj, FP_FirstCellInRow);
    oObj = oCell;
    break;
    case FO_Cell:
    // handle FO_Pgf case
    case FO_Pgf:
    // handle FO_AFrame case
    case FO_AFrame:
    oObj = F_ApiGetId(oDoc, oObj, FP_InTextFrame);
    break;
    // handle graphic object cases
    case FO_TextLine:
    case FO_TextFrame:
    case FO_UnanchoredFrame:
    case FO_Arc:
    case FO_Ellipse:
    case FO_Group:
    case FO_Inset:
    case FO_Line:
    case FO_Math:
    case FO_Polygon:
    case FO_Polyline:
    case FO_Rectangle:
    case FO_RoundRect:
    oObj = F_ApiGetId(oDoc, oObj, FP_FrameParent);
    break;
    default:
    // prevents loop if unknown object type is found.
    oObj = 0;
    break;
    if(oFrame){
    // Use FP_PageFramePage to get the page identifier of the object.
    return (F_ApiGetId(oDoc, oFrame, FP_PageFramePage));
    else
    return(0);
    Russ

  • How can I get the number of pages of a report?

    Hello to everyone, I'm writing a small app that exports a report to PDF (the app is done and everything is ok).
    Along with the PDF I need to create an XML file that describes the PDF file properties. One of the properties I need to supply is the number of pages of the PDF file. How can I ask Crystal Reports SDK for the number of pages my ReportDocument is made of?
    Best regards
    Alessandro

    Hello Alessandro,
    I found a Business Objects Note with a possible solution.  You can search for Notes yourself by starting at the Business Objects area of this SAP Community Network (SCN) site.
    Go to the [Business Objects link|https://www.sdn.sap.com/irj/boc] in the menu bar on SCN.
    Then go to the [Support link|https://www.sdn.sap.com/irj/boc/businessobjects-support] in the sub menu for Business Objects.
    Now go to the [Business Objects Note link|https://www.sdn.sap.com/irj/boc/businessobjects-notes] in the left side navigation menu.
    Finally, click on the [Search Business Objects Notes link|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_ossnotes&query=&adv=true] in the middle of the page.
    From the Notes Search page click on the Advanced Search link.  For your question I searched on these terms - net page number - and added "boj" (without the quotes) in the Component field for Advanced Search.  The "boj" component helps limit the search to Business Objects components - like the Crystal Reports .NET SDK.
    This search brought up a number of results.  The second result looks like it will address your question:
    "[SAP Note 1216240|https://bcp.wdf.sap.corp/sap/sapnotes/display/0001216240] - How to retrieve the number of pages from a ReportDocument in VS .NET"
    I hope this helps!
    Sincerely,
    Dan Kelleher

  • How to get the no of pages in a report?

    Hi All,
    I have a requirement to get the number of pages in the crystal report.
    I found that the following method of IReportSource gives the value.
    public int getLastPageNumber(com.crystaldecisions.sdk.occa.report.application.IRequestContext requestContext)
                          throws java.lang.NullPointerException,
                                 ReportSDKException
    But the issue issue is with the paramter requestContext. How can I get this requestContext.
    Appreciate your time.
    Regards,
    Anil Chowdary K

    Because of the page on demand feature, by default there is no clean way to get the page number, because each page is generated as requested.  To get the total page count, the viewer must render the entire report first.  The easiest way to accomplish this is to use the CrystalReportViewer object and call the showLastPage() method, then using the CrystalReportViewer object generate a ViewInfo object, and call the getPageNumber() method.
    For more information review the Viewer documentation in our [SDK Library|http://www.sdn.sap.com/irj/sdn/bi-sdklibrary].

  • How to limit the number of pages a PDF can print?

    Hi,
    Does anyone know how to lime the number of pages a PDF can print? For example, if a PDF has 100 pages, it only allow the user to print no more than 100 pages.
    Any software can achieve this ?

    But once I purchased a ebook, which required be opened with Adobe digital edition, the ebook only allow to print 57 pages out of 300+ pages total. 
    Are there any way to convert a PDF to a ebook and encrypted by the printing limits?

  • From Word to PDF without changing the Number of pages

    When I convert a document of 320 pages from Word 2013 to PDF using Acrobat, the number of pages jump to 331, changing the footnotes, sections...How to fix it? Tx

    To expand on Michael Kazlow's response, the problem isn't caused by Windows, but rather how Microsoft Office applications format their text. The issue isn't only with Word, but also with every other Office application as well. Furthermore, it isn't a matter of whether you create the PDF using the Adobe PDF PostScript printer driver instance, but rather, when you compose the document while the Adobe PDF PostScript printer driver instance is the default/current printer within Word!!!
    These applications format text using font metrics normalized to the resolution of the current output device. Thus, if you are displaying a document in Word and the current printer selected (usually the default printer you have selected in Windows when you start up Word) has a device resolution of 600dpi, the document is formatted with each character's space measured in units of 1/600 of an inch. If you change the current printer or print to a printer that has a different resolution set, Word reformats the document using font metrics based on the new resolution. In the case of the Adobe PDF PostScript printer driver instance, by default, the resolution is 1/1200 of an inch. Typically, more text will fit on a page with long text lines when higher resolution is used and less text will fit on a page with long lines when a lower resolution is used. If your default printer is a high resolution inkjet printer, you may see resolutions as high as 2400 dpi, for example.
    Microsoft Office applications are also known to reformat pages based upon other metrics such as printable area.
    These issues don't just affect PDF creation, but also printing to different devices yielding different line endings and pagination.
    To further complicate matters, when you either Save as PDF using Office's own PDF creation facility or even Save as Adobe PDF using Acrobat's PDFMaker facility (part of Acrobat), Office uses yet a different mechanism to reformat the page, also yielding inconsistencies in line ending and pagination from what you see on the screen and/or in print directly from Word to a particular device. (We don't know exactly what mechanism Microsoft is using in these cases to cause the discrepancies.)
    Users of Office and Adobe have complained to Microsoft about this general behavior for over 20 years and apparently it is not of any priority to Microsoft to resolve this.
              - Dov

  • Is there a limit to the number of pages in a spread?

    Does ID limit the number of pages you can have in one spread? I have a long document with 400 or so pages of small size. For the purposes of on-screen reviewing of the work, I'd like to group them into spreads of 12 pages each. I'm using the pages panel, and I have it set to allow pages to shuffle. It works fine for the first 10 pages, but then it refuses to allow the 11th page to attach to spread.  CS4.

    IF all the panels were exactly the same width (highly doubtful for a roll-fold) and IF ID supported 12 pages per spread (it doesn't) then it might be less work to make 12-page spreads and place the PDF twice, but since I think there's a really good chance you'll need to adjust the positioning for at least 22 pages, that seems doomed.
    I wouldn't even bother, in this case, with facing pages. Presumably they want this for the screen, so there's nothing gained from facing pages or multiple columns. You can either make the file with 24 pages and place the PDF 12 times for each page of the PDF, or place each page of the PDF once in a 2-page file, then copy the pages and reposition the image in the frame for each panel. The big thing here is to put the PDF into frames that are the same size as the new page (so they get cropped down to one-panel on each page). Then it's just a case of sliding the the PDF left or right in the frame to expose the next panel.

  • When I air print from my iPad, I can't limit the number of pages. It just says print and the number of copies and I end up with way more than I want. How do I set it to limit the pages?

    When I air print using FingerPrint from my ipad, it doesn't let me limit the number of pages, and I end up with more pages than I want. It asks if I want multiple copies, but it doesn't ask me number of pages, or which pages. Is there a way to do this?

    When you use an AirPrint compatible printer, you get this option for page range. You are using your computer as the server in order to print, so you probably have to set the range on the computer. While you can print from your printer with this app, I assume that it doesn't give you the same control that you get directly from the iPad when using an AirPrint printer.
    Read this from the FingerPrint support site. Selecting the page range would be part of the formatting of a print job.
    http://fingerprint-support.collobos.com/knowledgebase/articles/66972-i-can-t-for mat-the-print-job

  • Indesign CS3: How to get the number of the current layer?

    Hallo!
    How to get the number of the current layer in a page?
    Thanks,
    Alois Blaimer

    InterfacePtr<ILayerList> layerList(documentUIDRef, UseDefaultIID());          <br /><br />int32 layerCount = layerList->GetCount();<br /><br />To findout layer name use<br /><br />IDocumentLayer* documentLayer = layerList->QueryLayer(layerIndex);<br />                         <br />PMString layer=documentLayer->GetName();

  • How to get the number of community members from outside the community

    Hi everyone.
    I need to know if there is any way to get the number of community members from outside the community, I mean, not using the "What's happening" webpart. I want to build up a page with a Webpart that summarize my three most visited communities indicating
    number of members, three last messages in the newsfeed, and number of posts in blog, wikis, document libraries, etc.
    Do I need statistics to get this kind of information? Should I use Sharepoint Object model instead?
    Here is an example of what I need:
    - Community name
    - Number of members
    - Community activity (messages, docs uploaded to library, etc)
    - Number of posts in calendar, blog, wiki that belongs to community
    Thank you all!

    Hi Thuan.
    Thanks for your answer but it does not help me because these communities are Sharepoint Communities not external sites so I need to get that information using SP object model and BCS in this case is useless.
    EDIT
    I found the solution using the search objects but I was only able to get members, discussions and replies
    using (ClientContext clientContext = new ClientContext("URL_OF_ENTERPRISE_SEARCH_CENTER"))
    KeywordQuery keywordQuery = new KeywordQuery(clientContext);
    keywordQuery.QueryText = "The_Name_of_the_Community WebTemplate:COMMUNITY";
    SearchExecutor searchExecutor = new SearchExecutor(clientContext);
    ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
    clientContext.ExecuteQuery();
    System.Collections.Generic.IDictionary<string, object> ret = null;
    foreach (System.Collections.Generic.Dictionary<string, object> resultRow in results.Value[0].ResultRows)
    Console.WriteLine("{0}: {1} ({2})", resultRow["CommunityMembersCount"], resultRow["CommunityTopicsCount"], resultRow["CommunitiyRepliesCount"]);
    This is a Console Application.
    I hope someone helps

Maybe you are looking for

  • REG: DTP - Selections

    Hi Gurus, Please guide me in the ABAP Routine for the DTP Selections. Here is the code: Tables: ZIP_SEL_TAB. data: l_idx like sy-tabix.   select single * from ZIP_SEL_TAB.   read table l_t_range with key       fieldname = 'COSTCENTER'.   l_idx = sy-t

  • In iBooks or other pdfs apps markings/highlights of ebook recorded by itunes at sychs

    In iBooks or other pdfs apps, markings/highlights of ebooks done when reading, recorded by itunes after sychronization?

  • Problem with attachements in bid invitation

    I posted 3 attached documents in a bid invitation,1.xls,an 2 .doc ,the problem is that the supplier can't open the documents attached plus the documents are not big, can any one please help me with this issue? there will  be rewards.

  • How do I get music onto my nano ipod

    Bought a new nano ipod at Staples yesterday.   It has taken me over 6 HOURS to get the darn thing registered.  I am seriously ready to return this if things continue in this vein.  No support, no manual, no help, no info on how to use this item.  I n

  • EjbFindAll method returns only primaryKeys.

    Hi All, Im having a problem when calling the findAll() method for my bean. It returns only the primary keys in a collection when it should be returning a collection of beans with full data. here is my EJB method for ejbFindAll() which returns just th