Results 1 to 14 of 14
  1. #1
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print Word Doc To PDF Stripping Blank Page (Word 2003)

    Have the following code to print a Word document to PDF:

    strActPrntr = Application.ActivePrinter
    'temporarily set default printer to PDF995
    Application.ActivePrinter = "PDF995"
    'strip last page of document as it is always blank
    intPages = Selection.Information(wdNumberOfPagesInDocument) - 1
    MsgBox intPages
    'print to PDF
    Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, item:= _
    wdPrintDocumentContent, Copies:=1, Pages:="1-" & intPages, PageType:=wdPrintAllPages, _
    ManualDuplexPrint:=False, Collate:=True, Background:=False, PrintToFile:= _
    False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
    PrintZoomPaperHeight:=0
    'reset back to original default printer
    Application.ActivePrinter = strActPrntr
    'set a sleep here in order that pdf is correctly decoded
    Sleep 5000 'wait 5 sec before continuing

    The reason for setting intPages to the number of pages in the document less 1 is that all documents produced via our Template System have a section break at the end ( needed for print functions etc ). Can anyone enlighten me as to how to update the above Print procedure to strip the last page so that the pdf won't include a blank page? I've tried to manipulate the code above, setting ranges etc., removing PageType:=wdPrintAllPages, removing item:= wdPrintDocumentContent, just can't get it to work.

    Many thanks in anticipation

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Word 2003)

    You haven't told us what the problem with your code is...

  3. #3
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Word 2003)

    Sorry Hans - it won't actually strip that last blank page from the document, so the pdf still includes a blank page. Where the document contains 4 pages I only want to "pdf" 3 pages, as the last page is always blank, due to section break at the end. I can't remove that section break as it contains formatting info etc. I thought it would be an easy thing to just set intRage equal to number of pages in the document minus 1 but it isn't working. I can manually print the pdf driver, selecting pages 1-3 and the blank page is stripped, but with this code it remains.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Word 2003)

    I'm sorry, I have no idea. The code is correct, as far as I can tell.

    I don't use pdf995 myself, perhaps someone who does can test the code and help.

  5. #5
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Word 2003)

    Thanks Hans. Seems that pdf995 totally ignores anything that follows Application.PrintOut, as I even tried just printing the current page - again, no go. The whole document went to pdf. Hope someone may chime in here with a workaround.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    Have you tried printing the range based on sections rather than pages? I don't know that it will solve your problem but it is something else to test.

    dim sPages as string
    sPages = "s1-s" & ActiveDocument.Sections.Count - 1
    Application.PrintOut Pages:=sPages

    If that also fails then you may need to examine ways to edit the resulting PDF to remove the last page. This is possible but messy.

    This simplest fix of all that I can see is to examine the reason for you having an extra page at the end of the document anyway. If your template system requires this then I would be complaining about the template system. I can't imagine any good reason why there would need to be an extra section in every document that is produced - but then again, I don't have much of an imagination. Surely there is a more elegant way to construct documents. Maybe one way to get the desired result is to remove the last section before using your code to print to PDF and then close the file without saving.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    Thanks Andrew - will give it a try but don't hold out much hope, as I've tried actually printing the current page only and that's a no go. Have also deleted the section prior to pdf, which works, although bit of mucking around if penultimate page has a different header / footer etc.

    As to why we have the section break - our template system is object oriented, and where a document contains multiple pages , i.e, a letter (over one page, and a form, or such) the document variables are populated with print codes and name codes for each. We then have print buttons which allow user to print various copies of each/all pages based on these document variables.

    Will give your suggestion a go, crossing fingers, although I gotta say, it's as if all code following Application.PrintOut is ignored by pdf995 driver.

  8. #8
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    No go ... anything after Application.PrintOut is ignored. I'm still trying go strip the last section break prior to pdf, however headers/footer get jumbled. Any other ideas out there ?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    This is for work purposes, correct? If so, do you have Adobe Acrobat at work? You might try using that instead of Pdf995.

  10. #10
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    Correct Hans. Problem with full version is licensing, as many users need to access this project. Having said I'm getting the full version loaded - will post back

  11. #11
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    As an alternative to removing the last section before printing to PDF, have you tried formatting it as hidden text?

    You'd have to ensure that the Word option to print hidden text is unchecked, and you might need to add a temporary "hidden" paragraph before the section break, but it works for me using Adobe Acrobat 7 Standard (manually or via code). Incidentally, your original code also works for me using Acrobat.

  12. #12
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    Thanks William - Yes it WORKED formatted as hidden text. Why did I not think of that one !! You wouldn't believe the time I've spent on this, not to mention the "googling". Seems the problem isn't restricted to trying to print to pdf995 driver either. Code execution just stops after Application.PrintOut, no matter what ranges, page numbers etc are set.

    Anyways, thanks Hans, Andrew and William - invaluable site for me

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    > Seems the problem isn't restricted to trying to print to pdf995 driver either.

    I'm quite certain that you can print a specified range of pages directly (to a physical printer) using VBA.

  14. #14
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print Word Doc To PDF Stripping Blank Page (Wo

    Thanks Hans - quite correct. I just realised this morning that I had to add some code to get the extensibility object as we now have Document Management Software, and this module did not have it. Once this was added, the original code worked a treat. Thanks so much again for your help, sorry to waste your time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •