How to set the papersize through printManager

How to set the papersize through printManager

18627796338
Enthusiast Enthusiast
2,611 Views
9 Replies
Message 1 of 10

How to set the papersize through printManager

18627796338
Enthusiast
Enthusiast

Hi, everyone!

I'm working on developing a small addin in Revit to print all view sheet to pdf file using just one button. I faced some problems when I tried to set the PaperSize and OrientationType. Though it can print view sheets, the print setting did not work well. So the result can not meet the needs.

        PrintManager printManager = activeDoc.PrintManager;
        printManager.PrintRange = PrintRange.Select;
        ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
        printManager.PrintToFile = true;
        printManager.SelectNewPrintDriver("Adobe PDF");

        printManager.PrintSetup.CurrentPrintSetting = printManager.PrintSetup.InSession;
        PrintSetup pSetup = printManager.PrintSetup;
        PrintParameters pParams = pSetup.CurrentPrintSetting.PrintParameters;
        pParams.PageOrientation = PageOrientationType.Portrait;
        if (!(printManager.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize.Name == "Screen 640x480 (VGA)"))
        {
            foreach (PaperSize ps in printManager.PaperSizes)
            {
                if (ps.Name == "Screen 640x480 (VGA)")
                {
                    pParams.PaperSize = ps;
                }
            }
        }
        printManager.SubmitPrint(sheet);

Could someone please tell me how to change the code to set the PaperSize and OrientationType?

And, is there anyway to get the real size of the PaperSize? Because I can only get the PaperSizes' Name by PaperSizes.Name. Is there anyway to set my own PaperSize?

Thanks a lot.

2,612 Views
9 Replies
Replies (9)
Message 2 of 10

bxw
Enthusiast
Enthusiast

There is an SDK example that recreates the revit print dialog, including setting the paper size. The sample is called viewprinter.  I think that will get you sorted out. 

0 Likes
Message 3 of 10

18627796338
Enthusiast
Enthusiast

I've already read that sample, but I still can not find out what's wrong with my code, why it didn't work.

Thank you any way.

0 Likes
Message 4 of 10

bxw
Enthusiast
Enthusiast

What result are you getting?  Are you getting a value in the ps variable?  If not you could try this line where you are trying to match the name.  the .Equals should be used for string comparison. 

 

 

ps.Name.Equals("Screen 640x480 (VGA)")

0 Likes
Message 5 of 10

18627796338
Enthusiast
Enthusiast

I used this code, but it didn't change anything. By that code, I can print view sheet, but the print setting did not change as what I've set, in other word, the paper size was wrong. Could you help me to find a way to set the papersize?

0 Likes
Message 6 of 10

18627796338
Enthusiast
Enthusiast

I built the sample viewprint and use it in the Revit, and then I found that it also didn't change the papersize into what I selected! I use the pdf printer provided by Adobe Acrobat XI Pro. Anyone know how to solve this problem?

0 Likes
Message 7 of 10

kinjal
Enthusiast
Enthusiast

I am facing exactly same issue. Any updates / answers / work-arounds?

Kinjal Desai
Fullstack developer @ Dwaravati
Delivering high quality programmatic boosts for your already beautiful Revit


0 Likes
Message 8 of 10

FAIR59
Advisor
Advisor

try saving the Settings  and rollback.

 

 

using (Transaction t = new Transaction(doc, "testPrint"))

{

t.Start();

printManager.PrintSetup.SaveAs("test");

printManager.SubmitPrint(doc.ActiveView);

t.RollBack();

}

 

0 Likes
Message 9 of 10

kinjal
Enthusiast
Enthusiast

Thanks Fair.. It turned out that the code was alright, the print driver "Microsoft Print to PDF" was at fault.. (works well with other printers)

Kinjal Desai
Fullstack developer @ Dwaravati
Delivering high quality programmatic boosts for your already beautiful Revit


0 Likes
Message 10 of 10

FilipNekic
Contributor
Contributor
Try to add this:

try { printMenager.PrintSetup.Save(); } catch{}

more info here:

http://forums.augi.com/showthread.php?103878-Updating-PrintSettings 

0 Likes