Printing API question

Printing API question

russ.green
Advocate Advocate
2,809 Views
5 Replies
Message 1 of 6

Printing API question

russ.green
Advocate
Advocate

Having trouble with a bit of printing code if the community would be kind enought to offer some help. I have looked at ViewPrinter sample but A: struggle to read that much C# and B:  think its more about replicating the revit UI for each print.

 

What I'm doing is looking through a list of sheets and exporting to DWG, DWF and hopefully printing to PDF.   I want to determine the sheet size at runtime and adjust the print settings to suite.  This works well for the DWF method.

 

So here is a snippet.  There is a simplified UI (a single page in a wizard) where some print settings are selected.  Then for each sheet I call this method.  Most things work.  My chosen printer is used and the sheet is printed to the correct place but  my print settings are not saving so the PDF is generated using the selected driver but with the wrong page size, colour settings, etc

 

    Private Sub ExportPDF(ByVal ExportFileName As String, ByRef thisdoc As Document, ByRef sheet As ViewSheet)
        Try
            'configure filename path for final PDF save location
            Dim sFullPath As String = Path.Combine(sbIssuePath.ToString, ExportFileName)
         
           'get the sizes with from the titleblock instances
           'method called to get these values from sheet

            pMgr = thisdoc.PrintManager
            pMgr.PrintRange = Autodesk.Revit.DB.PrintRange.Select
            pMgr.SelectNewPrintDriver(PDFPRINTERNAME)
            pMgr.PrintToFile = True
            pMgr.PrintToFileName = sFullPath

            pSetup = pMgr.PrintSetup
            pParams = pSetup.CurrentPrintSetting.PrintParameters

            pParams.ZoomType = ZoomType.Zoom
            pParams.Zoom = 100
            If Width > Height Then
                pParams.PageOrientation = PageOrientationType.Landscape
            Else
                pParams.PageOrientation = PageOrientationType.Portrait
            End If
            pParams.PaperPlacement = PaperPlacementType.Center

            pParams.ColorDepth = CType(Me.cboPDFColors.SelectedItem, ColorDepthType)
            pParams.RasterQuality = CType(Me.cboPDFRasterQuality.SelectedItem, RasterQualityType)

            pParams.HiddenLineViews = HiddenLineViewsType.VectorProcessing
            pParams.ViewLinksinBlue = Me.chkPDFViewLinksInBlue.CheckState
            pParams.HideReforWorkPlanes = Me.chkPDFHideRefWorkPlanes.CheckState
            pParams.HideUnreferencedViewTags = Me.chkPDFHideUnreferenceViewTags.CheckState
            pParams.HideCropBoundaries = Me.chkPDFHideCropBoundaries.CheckState
            pParams.HideScopeBoxes = Me.chkPDFHideScopeBox.CheckState
            pParams.ReplaceHalftoneWithThinLines = Me.chkPDFHalftone.CheckState
            pParams.MaskCoincidentLines = Me.chkPDFCoincidentLines.CheckState

            Dim PaperSize As String = GetPapersize(Width, Height)
            For Each ps As Autodesk.Revit.DB.PaperSize In pMgr.PaperSizes
                If ps.Name.Equals(PaperSize) Then
                    pParams.PaperSize = ps
                    Exit For
                End If
            Next

            pMgr.Apply()

            'Try
            '    oPM.ViewSheetSetting.SaveAs("transmittal")
            'Catch ex As Exception
            '    'do nothing and move on
            'End Try
            Try
                pSetup.SaveAs("transmittal")
                'oPM.PrintSetup.SaveAs("transmittal")
            Catch ex As Exception
                'do nothing and move on
            End Try

            pMgr.SubmitPrint(sheet)

            'Try
            '    oPM.ViewSheetSetting.Delete()
            'Catch ex As Exception
            '    'do nothing and move on
            'End Try
            'Try
            '    oPM.PrintSetup.Delete()
            'Catch ex As Exception
            '    'do nothing and move on
            'End Try

        Catch ex As Exception
            TaskDialog.Show("There has been an error generating the PDF file " & ExportFileName & "." & Environment.NewLine & "Please manually print the PDF using the Revit print command." & Environment.NewLine & ex.ToString, MsgBoxStyle.Information, "Error creating PDF")
        Finally

        End Try
    End Sub

 

 

 

 

 

 

Russ Green
0 Likes
Accepted solutions (1)
2,810 Views
5 Replies
Replies (5)
Message 2 of 6

russ.green
Advocate
Advocate

just missed setting the setup for the manager....doh!

Russ Green
0 Likes
Message 3 of 6

mikako_harada
Community Manager
Community Manager

Hi Russ, 

 

So, did you solve the problem?  If so, it will be helpful for other if you can post the working version here.  

 

Thank you. 


Mikako Harada
Developer Technical Services
0 Likes
Message 4 of 6

russ.green
Advocate
Advocate
Accepted solution

Just needed this before configuring the settings

 

pMgr.PrintSetup.CurrentPrintSetting = pMgr.PrintSetup.InSession

 

Russ Green
0 Likes
Message 5 of 6

mikako_harada
Community Manager
Community Manager

Thank you, Russ!


Mikako Harada
Developer Technical Services
0 Likes
Message 6 of 6

18627796338
Enthusiast
Enthusiast

Hello. I also faced the same problem. Could you post where you put that adding code? Because when I added that code into mine, it still didn't work. Could you please post your final code? Thank you very much.

0 Likes