The trick is to temporaly set the flowLayoutPanel as large as to fit all the controls within, even if it gets too large for the visible screen, then do the DrawToBitmap using the flowLayoutPanel.clientRectangle area, not the .Width and .Height.
In my example, Outside_Splitter is docked to the form, with two panels, and fraAction is a groupbox and is the last control on the panel, that is vertically scrolled.
Public Sub Print_Panel()
Dim newHeight As Integer
Dim pos As Point, oheight As Integer, owidth As Integer, xDock As DockStyle
With Outside_Splitter ' This contains the two panel ...
pos.X = .Left ' Store original position and size
pos.Y = .Top
oheight = .Height
owidth = .Width
xDock = .Dock ' get original dock set
newHeight = FraAction.Top + FraAction.Height + 30 ' calculate new height based on position and size of the last control
.Dock = DockStyle.None ' undock it
.Height = newHeight ' set new height
.Refresh()
.SetBounds(pos.X, pos.Y, owidth, newHeight) ' Set position and size, temporarily
.Refresh()
End With
'Create Bitmap based on panel.ClientRectangle
Dim myBmp As New Bitmap(Painel_Detalhe_NC.ClientRectangle.Width, Painel_Detalhe_NC.ClientRectangle.Height)
'Paint the bitmap
Painel_Detalhe_NC.DrawToBitmap(myBmp, Painel_Detalhe_NC.ClientRectangle)
'Create pdf
Dim _pdf As New C1.C1Pdf.C1PdfDocument
_pdf.Clear()
_pdf.Landscape = False
_pdf.PaperKind = PaperKind.A4
Dim rec As New RectangleF ' Set 5% margin around the page
rec = _pdf.PageRectangle
rec.X = 0.05 * rec.Width
rec.Y = 0.05 * rec.Height
rec.Width = 0.9 * _pdf.PageRectangle.Width
rec.Height = 0.9 * _pdf.PageRectangle.Height
_pdf.DrawImage(myBmp, rec) ' paint/resize bitmap to that size on the pdf
'Save it and show it
_pdf.Save(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.pdf")
Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp & "\temp.pdf")
myBmp.Dispose() ' Clear it
With Outside_Splitter ' put it back to where it was
.Left = pos.X
.Top = pos.Y
.Dock = xDock ' Back to filling the form
.Refresh()
End With
End Sub