Print PDF Attachments
The InputPdf class has an Attachments property that returns an array of Attachment instances. Then, for each Attachment you can call the TryGetPDF method to get the PDF attachment as an InputPdf instance.
public InputPdf TryGetPdf()
Function TryGetPdf() As InputPdf
info
Only PDF attachments are retrieved, if an attachment is not a PDF then the method returns null.
This final example demonstrates how to retrieve and print PDF attachments from a PDF portfolio.
InputPdf portfolioPDF = new InputPdf(pdfFilePath);
PrintJob printJob = new PrintJob(Printer.Default);
Attachment[] files = portfolioPDF.Attachments;
foreach (Attachment file in files)
{
InputPdf pdfAttachment = file.TryGetPdf();
if (pdfAttachment != null)
printJob.Pages.Add(pdfAttachment);
}
if (printJob.Pages.Count > 0)
printJob.Print();
Dim portfolioPDF As InputPdf = New InputPdf(pdfFilePath)
Dim printJob As PrintJob = New PrintJob(Printer.Default)
Dim files As Attachment() = portfolioPDF.Attachments
For Each file As Attachment In files
Dim pdfAttachment As InputPdf = file.TryGetPdf()
If pdfAttachment IsNot Nothing Then
printJob.Pages.Add(pdfAttachment)
End If
Next
If printJob.Pages.Count > 0 Then
printJob.Print()
End If
[AttachmentsExample.cs](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-cs/AttachmentsExample.cs){#gitlink-id target=_blank}
[AttachmentsExample.vb](https://github.com/DynamicPDF/print-manager-dotnet-core/blob/master/print-manager-dotnet-core-vb/AttachmentsExample.vb){#gitlink-id target=_blank}