I am currently trying to automate the printing of a word doc that is 91 pages long. The .doc has a bookmark ("Print") defined to show the print range. As you can see below, I am finding the value of the bookmark and passing it to the .PrintOut call. In debug I can see that the value is "45". Thus, I would expect to receive a .PDF file with 45 pages. Unfortunately I still get the full 91 pages...
Dim PDF As CDIntfEx.CDIntfEx = New CDIntfEx.CDIntfEx
Dim origPath As String = txtOrigPath.Text
Dim newPath As String = txtNewPath.Text
Dim wa As Word.Application
Dim wd As Word.Document
wa = New Word.Application
If File.Exists(origPath) Then
PDF.DriverInit("Amyuni PDF Converter")
PDF.EnablePrinter(companyName.ToString(), activationCode.ToString())
PDF.SetDefaultPrinter()
wa.ActivePrinter = "Amyuni PDF Converter"
wa.Visible = True
wd = wa.Documents.Open(origPath)
Else
UpdateTxtBox("Document does not exist.")
End If
If File.Exists(newPath) Then
File.Delete(newPath)
End If
Dim pages As String
pages = wd.Bookmarks.Item("Print").Range.ComputeStatistics(WdStatistic.wdStatisticPages)
wd.PrintOut(background:=True, range:=Word.WdPrintOutRange.wdPrintRangeOfPages, outputfilename:=newPath, pages:="1-45")
wa.Documents.Close(False)
wa.Quit()
wa = Nothing
PDF.RestoreDefaultPrinter()
PDF.DriverEnd()
Thanks ahead of time... any help is much appreciated.
I tried to print out a range of pages from Access to the PDF printer and it worked fine. I have Word 2003.
I used pages := '1-2' and I got the first two pages of the document printed.
Please check if 'Pages' is computed properly in your code. If you replace Pages by 45, wont you get the first 45 pages printed?
I guess you are facing the same issue if you print to a physical printer because this issue is related to the Printout function of Word and not to the printer to which you are printing.
Thank you for the reply. After some more investigation, the problem seems to be in the document itself. I can create another doc and get the proper action.