Gets the number of attachments to this file.
public int AttachmentCount {get;} public:property Int32 AttachmentCount{Int32 get()}
AttachmentCount # get (CodecsImageInfo)
Number of attachments to this file, if this file has any; otherwise, 0. The default value is 0.
LEADTOOLS supports attachments for the following file formats:
Therefore, AttachmentCount will contain a valid value only if the file is one of the formats listed above.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;private static void ReadAttachmentsExample(string fileName, string outputDir){using (RasterCodecs rasterCodecs = new RasterCodecs()){int attachmentCount;// Get information on the owner file// This step is optional if we are not interested in determining whether the owner file format// or whether it is a PDF portfolio.using (CodecsImageInfo imageInfo = rasterCodecs.GetInformation(fileName, true)){Debug.WriteLine("Information");Debug.WriteLine("Format:" + imageInfo.Format);// If PDF, check if it is portfolioif (imageInfo.Format == RasterImageFormat.RasPdf)Debug.WriteLine("IsPortfolio:" + imageInfo.IsPortfolio);attachmentCount = imageInfo.AttachmentCount;Debug.WriteLine("Attachments:" + imageInfo.AttachmentCount);}// Read the properties of the attachments embedded in this fileCodecsAttachments attachments = rasterCodecs.ReadAttachments(fileName);if (attachments == null){// The format either:// - Does not support attachments// - LEADTOOLS does not support reading its attachmentsDebug.WriteLine("Attachments is not supported for this file format");return;}// Sanity checkDebug.Assert(attachments.Count == attachmentCount);Debug.Assert(attachments.OriginalFormat == RasterImageFormat.Unknown);if (attachments.Count == 0){Debug.WriteLine("No attachments to extract");return;}// Create the output directory if it does not existif (!Directory.Exists(outputDir))Directory.CreateDirectory(outputDir);// Extract the attachmentsforeach (CodecsAttachment attachment in attachments){// Get the output file namestring outputFileName = Path.Combine(outputDir, attachment.FileName);var description = attachment.Description;var displayName = attachment.DisplayName;var fileLength = attachment.FileLength;var metaData = attachment.Metadata;var timeCreated = attachment.TimeCreated;var timeModified = attachment.TimeModified;Debug.WriteLine("Extracting attachment to output file: " + outputFileName);rasterCodecs.ExtractAttachment(fileName, attachment.AttachmentNumber, outputFileName);// Show information on this attachmenttry{using (CodecsImageInfo imageInfo = rasterCodecs.GetInformation(outputFileName, true)){Debug.WriteLine($" attachment format is {imageInfo.Format} and has {imageInfo.TotalPages} pages");}}catch (Exception ex){Debug.WriteLine($" attachment format could not be obtained, error {ex.Message}");}}}}
import java.io.*;import java.net.*;import java.nio.file.Paths;import java.util.*;import java.time.Instant;import java.time.Duration;import org.junit.*;import org.junit.runner.JUnitCore;import org.junit.runner.Result;import org.junit.runner.notification.Failure;import static org.junit.Assert.*;import leadtools.*;import leadtools.codecs.*;import leadtools.codecs.RasterCodecs.FeedCallbackThunk;import leadtools.drawing.internal.*;import leadtools.imageprocessing.*;import leadtools.imageprocessing.color.ChangeIntensityCommand;import leadtools.svg.*;public void readAttachmentsExample() throws IOException {final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";String fileName = combine(LEAD_VARS_IMAGES_DIR, "pdfsegmentation.pdf");String outputDir = combine(LEAD_VARS_IMAGES_DIR, "attachments_test.pdf");RasterCodecs rasterCodecs = new RasterCodecs();int attachmentCount;// Get information on the owner file// This step is optional if we are not interested in determining whether the// owner file format// or whether it is a PDF portfolio.CodecsImageInfo imageInfo = rasterCodecs.getInformation(fileName, true);System.out.println("Information");System.out.println("Format:" + imageInfo.getFormat());// If PDF, check if it is portfolioif (imageInfo.getFormat() == RasterImageFormat.RAS_PDF)System.out.println("IsPortfolio:" + imageInfo.isPortfolio());attachmentCount = imageInfo.getAttachmentCount();System.out.println("Attachments:" + imageInfo.getAttachmentCount());// Read the properties of the attachments embedded in this fileCodecsAttachments attachments = rasterCodecs.readAttachments(fileName);if (attachments == null) {// The format either:// - Does not support attachments// - LEADTOOLS does not support reading its attachmentsSystem.out.println("Attachments is not supported for this file format");return;}// Sanity checkassertTrue(attachments.size() == attachmentCount);assertTrue(attachments.getOriginalFormat() == RasterImageFormat.UNKNOWN);if (attachments.size() == 0) {System.out.println("No attachments to extract");return;}// Create the output directory if it does not existFile outputDirFile = new File(outputDir);if (!outputDirFile.exists())outputDirFile.createNewFile();// Extract the attachmentsfor (CodecsAttachment attachment : attachments) {// Get the output file nameString outputFileName = combine(outputDir, attachment.getFileName());String description = attachment.getDescription();String displayName = attachment.getDisplayName();long fileLength = attachment.getFileLength();Map<String, String> metaData = attachment.getMetadata();Date timeCreated = attachment.getTimeCreated();Date timeModified = attachment.getTimeModified();System.out.println("Description: " + description);System.out.println("Display name: " + displayName);System.out.println("File length: " + fileLength);System.out.println("Meta data: " + metaData);System.out.println("Time created: " + timeCreated);System.out.println("Time modified: " + timeModified);System.out.println("Extracting attachment to output file: " + outputFileName);rasterCodecs.extractAttachment(fileName, attachment.getAttachmentNumber(), outputFileName);// Show information on this attachmenttry {imageInfo = rasterCodecs.getInformation(outputFileName, true);System.out.println(" attachment format is {imageInfo.Format} and has {imageInfo.TotalPages} pages");} catch (Exception ex) {System.out.println(" attachment format could not be obtained, error {ex.Message}");}}}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
