Solved

number of papers to be used durin printing; a formula that I can't solve; using mspublisher pages

Posted on 2012-03-26
11
380 Views
Last Modified: 2012-03-28
Im looking for a formula or math calculation of ms publisher pages

The default paper size is 8.5 x 11[in] or A4 (the paper to use in printing)
I'm finding a way to retrieved how many papers to be used during printing with Microsoft publisher pages.

if the pagesize is tabloid(11x17[in]), what is the formula to result a 4pieces of default paper
if the pagesize is banner(60x8.5[in]), what is the formula to result a 6pieces of default paper

I have solve that but using different formulas, of which the code grows longer.

i got this for banner(60x8.5[in]), of which  I'm not sure for other banner width and height to come
                    pagenum = Convert.ToDecimal(aDoc.PageSetup.PageWidth) / (Convert.ToDecimal(aDoc.PageSetup.PageHeight) - Convert.ToDecimal(aDoc.PageSetup.TopMargin))
                    pagenum = Math.Floor(pagenum)
                    If pagenum = 0 Then pagenum = 1
                    pagenum = pagenum * adocPageCount

Open in new window



i got this for banner (24x72[in]), the result is 20 pages, which is 21pages(the correct)with A4
                Dim formula1 As Integer = Convert.ToUInt32(aDoc.PageSetup.PageSize.PageWidth) + Convert.ToUInt32(aDoc.PageSetup.PageSize.PageHeight)
                Dim formula2 As Integer = formula1 / 792
                Dim formula3 As Integer = formula1 / 612
                Dim formula4 As Integer = formula2 + formula3
                pagenum = formula4

Open in new window

0
Comment
Question by:systan
  • 6
  • 5
11 Comments
 
LVL 20

Expert Comment

by:ElrondCT
ID: 37769449
You'll need to calculate the amount for height and the amount for width separately. For example, a 3x13 print size will need two pages, while 7x9 needs just one (with 8.5x11 paper), but if you add height and width together, each of them is a total of 16 inches, with no way to distinguish them.

Can you determine whether the printer is set for portrait or landscape mode? In other words, an 11x17 tabloid will be 2 pages if it's printed on 11x8.5 pages, but it'll be 4 pages if it's on 8.5x11 pages.

Assuming you can get printer output dimensions, which I'll call PrinterHeight and PrinterWidth, your formula would be:

PageHeight = Math.Int(aDoc.PageSetup.PageHeight / PrinterHeight + .999)
PageWidth = Math.Int(aDoc.PageSetup.PageWidth / PrinterWidth + .999)
PagesUsed = PageHeight * PageWidth
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 37769464
Oops. Replace Math.Int with CInt (or Math.Floor) in the formulas. I don't know what I was thinking...
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 37769556
Forgot to count the number of (oversized) pages Publisher thinks it's printing:

PagesUsed = PageHeight * PageWidth * aDoc.PageCount
0
 
LVL 14

Author Comment

by:systan
ID: 37772144
>>Can you determine whether the printer is set for portrait or landscape mode?
No, but I can determine the page setting if is portrait or landscape
Dim PubApp As New Publisher.Application
Dim aDoc As New Publisher.Document
aDoc = PubApp.Open(PathnFileName, True, False, Publisher.PbSaveOptions.pbDoNotSaveChanges)
aDoc.ActiveWindow.Visible = False
''//This only counts the page number, But not the real count of pages to be printed
Dim pagenum as Integer = aDoc.Pages.Count
If aDoc.PageSetup.PageSize.Name.Contains("Portrait") Then
''//
ElseIf aDoc.PageSetup.PageSize.Name.Contains("Landscape") Then
''//
End If

Open in new window


>>In other words, an 11x17 tabloid will be 2 pages if it's printed on 11x8.5 pages, but it'll be 4 pages if it's on 8.5x11 pages.
Ok, here's some image,
tabloidp1pagetabloid4pages
>>Assuming you can get printer output dimensions, which I'll call PrinterHeight and PrinterWidth
I'll try
thANKS, ill be back
0
 
LVL 14

Author Comment

by:systan
ID: 37772492
Dim ps As Publisher.Printer
Dim printh As Integer = ps.PaperHeight
Dim printw As Integer = ps.PaperWidth

Open in new window

No, I can't get the printer height and width
it say's object not instance
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:ElrondCT
ID: 37772561
I'm actually not surprised. The printer hasn't been selected when you open the file; you're not in the middle of a print job. So I think what you'll have to do is either set a standard page size, or allow the user to select what page size he plans to use for printout (perhaps from a PrintDialog that would be in your app), and then calculate the number of pages accordingly.
0
 
LVL 14

Author Comment

by:systan
ID: 37772601
                Dim adocPageCount As Integer = aDoc.Pages.Count
                Dim formula2 As Integer = CInt((Convert.ToUInt32(aDoc.PageSetup.PageSize.PageHeight) / 792) + 0.999)
                Dim formula3 As Integer = CInt((Convert.ToUInt32(aDoc.PageSetup.PageSize.PageWidth) / 612) + 0.999)
                Dim formula4 As Integer = formula2 * formula3 * adocPageCount
                pagenum = formula4

Open in new window


Still it says 6 pages, even its 4 actually

with this mm to inches of 0.999mm is 0.0393307087 inches
                Dim formula2 As Integer = CInt(Convert.ToDouble(Convert.ToUInt32(aDoc.PageSetup.PageSize.PageHeight) / 792) + 0.0393307087)
                Dim formula3 As Integer = CInt(Convert.ToDouble(Convert.ToUInt32(aDoc.PageSetup.PageSize.PageWidth) / 612) + 0.0393307087)
                Dim formula4 As Integer = (formula2 * formula3) * adocPageCount
                pagenum = formula4

Open in new window


it says 2 pages
0
 
LVL 20

Expert Comment

by:ElrondCT
ID: 37772679
OK, let's troubleshoot. What are the values of PageHeight and PageWidth that you're getting? What is the value of formula2, formula3, and adocPageCount? Where do 792 and 612 come from? (That's not the correct ratio for either letter or A4, whatever the unit of measure is.)
0
 
LVL 14

Author Comment

by:systan
ID: 37772799
>>What are the values of PageHeight and PageWidth that you're getting?
Ok,
this is what I got:
aDoc.PageSetup.PageSize.PageHeight is 1224
aDoc.PageSetup.PageSize.PageWidth is 792 ( I guess this is the default width of tabloid portrait)

The aDoc.Pages.Count is 1(cause it's only 1 page of tabloid), if its 2 then we have to multiply it by 2

>>Where do 792 and 612 come from?
Ok,
http://hplipopensource.com/hplip-web/tech_docs/page_sizes.html
792in came from the default paper height of Letter or(as our default paper use)
612in is from the default paper width

Since you gave idea about print height and print width, then I used that for

thanks
0
 
LVL 20

Accepted Solution

by:
ElrondCT earned 500 total points
ID: 37773420
Sorry, my mistake on the 792x612.

Also, I was mistaken in using CInt. CInt rounds on conversion; I meant to truncate the results of the calculation. It should be Int() instead. The purpose of adding .999 and then truncating is to make sure that the results are always rounded up to the next whole number. (We still need CInt, though, to convert to Integer form.)

With a document size of 1224 x 792, the formulas should be:

formula2 = 1224 / 792: round up to 2
formula3 = 792 / 612: round up to 2

1224 / 792 = 1.55; we added .999, which gave us 2.54. With proper truncation, the result is 2. Using CInt, which rounds, the result is 3, which multipled by formula3 (value: 2) gives us 6.

Note that if the page is reoriented in landscape mode, output should fit on two pages.

So the corrected formulas should be:

                Dim adocPageCount As Integer = aDoc.Pages.Count
                Dim formula2 As Integer = CInt(Int(aDoc.PageSetup.PageSize.PageHeight / 792 + 0.999))
                Dim formula3 As Integer = CInt(Int(aDoc.PageSetup.PageSize.PageWidth / 612 + 0.999))
                Dim formula4 As Integer = formula2 * formula3 * adocPageCount
                pagenum = formula4

Open in new window

0
 
LVL 14

Author Closing Comment

by:systan
ID: 37775873
thank you :)

oh, in landscape its 6 pages, can't figure it out why
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now