PdfEmbeddedFile Constructor(PdfDocument,String,PdfCompression)
Инициализирует новый экземпляр класса
PdfEmbeddedFile.
Вот пример, показывающий, как встроить файл в PDF документ:
''' <summary>
''' Embeds specified file into specified PDF document.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
''' <param name="embeddingFilename">The filename of embedding file.</param>
Public Shared Sub EmbedFileIntoPdfDocument(pdfFilename As String, embeddingFilename As String)
' open PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
' if embedded files are absent
If document.EmbeddedFiles Is Nothing Then
' create new dictionary
document.EmbeddedFiles = New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecificationDictionary(document)
End If
' create embedded file instance
Dim embeddedFile As New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile(document, embeddingFilename, Vintasoft.Imaging.Pdf.PdfCompression.Zip)
' create embedded file specification
Dim fileSpecification As New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification(embeddingFilename, embeddedFile)
' set description of the embedded file specification
fileSpecification.Description = "Test embedding"
' add the embedded file specification to the dictionary
document.EmbeddedFiles.Add(embeddingFilename, fileSpecification)
' save changes to the source
document.SaveChanges()
End Using
End Sub
/// <summary>
/// Embeds specified file into specified PDF document.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
/// <param name="embeddingFilename">The filename of embedding file.</param>
public static void EmbedFileIntoPdfDocument(string pdfFilename, string embeddingFilename)
{
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document =
new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
{
// if embedded files are absent
if (document.EmbeddedFiles == null)
// create new dictionary
document.EmbeddedFiles =
new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecificationDictionary(document);
// create embedded file instance
Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile embeddedFile =
new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile(
document, embeddingFilename, Vintasoft.Imaging.Pdf.PdfCompression.Zip);
// create embedded file specification
Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification fileSpecification =
new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification(embeddingFilename, embeddedFile);
// set description of the embedded file specification
fileSpecification.Description = "Test embedding";
// add the embedded file specification to the dictionary
document.EmbeddedFiles.Add(embeddingFilename, fileSpecification);
// save changes to the source
document.SaveChanges();
}
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5