Beispiel #1
0
        public void Thumbnail()
        {
            //ExStart
            //ExFor:BuiltInDocumentProperties.Thumbnail
            //ExFor:DocumentProperty.ToByteArray
            //ExSummary:Shows how to add a thumbnail to a document that we save as an Epub.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Writeln("Hello world!");

            // If we save a document, whose "Thumbnail" property contains image data that we added, as an Epub,
            // a reader that opens that document may display the image before the first page.
            BuiltInDocumentProperties properties = doc.BuiltInDocumentProperties;

            byte[] thumbnailBytes = File.ReadAllBytes(ImageDir + "Logo.jpg");
            properties.Thumbnail = thumbnailBytes;

            doc.Save(ArtifactsDir + "DocumentProperties.Thumbnail.epub");

            // We can extract a document's thumbnail image and save it to the local file system.
            DocumentProperty thumbnail = doc.BuiltInDocumentProperties["Thumbnail"];

            File.WriteAllBytes(ArtifactsDir + "DocumentProperties.Thumbnail.gif", thumbnail.ToByteArray());
            //ExEnd

            using (FileStream imgStream = new FileStream(ArtifactsDir + "DocumentProperties.Thumbnail.gif", FileMode.Open))
            {
                TestUtil.VerifyImage(400, 400, imgStream);
            }
        }
        public void Thumbnail()
        {
            //ExStart
            //ExFor:BuiltInDocumentProperties.Thumbnail
            //ExFor:DocumentProperty.ToByteArray
            //ExSummary:Shows how to append a thumbnail to an Epub document.
            // Create a blank document and add some text with a DocumentBuilder
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Writeln("Hello world!");

            // The thumbnail property resides in a document's built in properties, but is used exclusively by Epub e-book documents
            BuiltInDocumentProperties properties = doc.BuiltInDocumentProperties;

            // Load an image from our file system into a byte array
            byte[] thumbnailBytes = File.ReadAllBytes(ImageDir + "Logo.jpg");

            // Set the value of the Thumbnail property to the array from above
            properties.Thumbnail = thumbnailBytes;

            // Our thumbnail should be visible at the start of the document, before the text we added
            doc.Save(ArtifactsDir + "Properties.Thumbnail.epub");

            // We can also extract a thumbnail property into a byte array and then into the local file system like this
            DocumentProperty thumbnail = doc.BuiltInDocumentProperties["Thumbnail"];

            File.WriteAllBytes(ArtifactsDir + "Properties.Thumbnail.gif", thumbnail.ToByteArray());
            //ExEnd

            using (FileStream imgStream = new FileStream(ArtifactsDir + "Properties.Thumbnail.gif", FileMode.Open))
            {
                TestUtil.VerifyImage(400, 400, imgStream);
            }
        }