Exemple #1
0
        // ExStart:PrefixToImportDirectivesHelper
        private static void Strategy_10_CSS_WriteCssToResourceFolder(HtmlSaveOptions.CssSavingInfo resourceInfo)
        {
            // -------------------------------------------------------
            // This is only one of possible implementation of saving
            // You can write and use Your own implementation if You will
            // -------------------------------------------------------

            // Get CSS file name from requested file.
            // Some trick required cause we get in parameters of this method
            // Not pure file name but full URL that
            // Created with usage of our template returned in Strategy_9_CSS_ReturnResultPathInPredefinedTestFolder()
            // So, knowing of that template we must extract from it CSS file name itself
            string guid             = System.Guid.NewGuid().ToString();
            string fullPathWithGuid = Strategy_10_CSS_ReturnResultPathInPredefinedTestFolder(new HtmlSaveOptions.CssUrlRequestInfo());

            fullPathWithGuid = string.Format(fullPathWithGuid, guid);
            int    prefixLength = fullPathWithGuid.IndexOf(guid);
            int    suffixLength = fullPathWithGuid.Length - (fullPathWithGuid.IndexOf(guid) + guid.Length);
            string fullPath     = resourceInfo.SupposedURL;

            fullPath = fullPath.Substring(prefixLength);
            string cssFileNameCore = fullPath.Substring(0, fullPath.Length - suffixLength);

            // Get final file name for saving
            string cssFileName = "style" + cssFileNameCore + ".css";
            string path        = _folderForReferencedResources_36435 + cssFileName;

            // Saving itself
            System.IO.BinaryReader reader = new BinaryReader(resourceInfo.ContentStream);
            System.IO.File.WriteAllBytes(path, reader.ReadBytes((int)resourceInfo.ContentStream.Length));
        }
Exemple #2
0
        // ExStart:SplitCSSToPagesHelpers
        private static void Strategy_4_CSS_MULTIPAGE_SAVING_RIGHT_WAY(HtmlSaveOptions.CssSavingInfo partSavingInfo)
        {
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();

            string outPath = dataDir + "style_xyz_page" + partSavingInfo.CssNumber.ToString() + ".css";

            System.IO.BinaryReader reader = new BinaryReader(partSavingInfo.ContentStream);
            System.IO.File.WriteAllBytes(outPath, reader.ReadBytes((int)partSavingInfo.ContentStream.Length));
        }
Exemple #3
0
        private static void CustomSavingOfCss(HtmlSaveOptions.CssSavingInfo resourceInfo)
        {
            System.IO.BinaryReader reader = new BinaryReader(resourceInfo.ContentStream);
            byte[] cssAsBytes             = reader.ReadBytes((int)resourceInfo.ContentStream.Length);
            Console.WriteLine("Css page processed with handler. Length of css in bytes is " + cssAsBytes.Length.ToString());

            // Here You can put code that will save page's HTML to some storage, f.e database
            MemoryStream targetStream = new MemoryStream();

            targetStream.Write(cssAsBytes, 0, cssAsBytes.Length);
        }
        private static void Strategy_11_CSS_WriteCssToPredefinedFolder(HtmlSaveOptions.CssSavingInfo resourceInfo)
        {
            if (!Directory.Exists(_folderForReferencedResources_34748))
            {
                Directory.CreateDirectory(_folderForReferencedResources_34748);
            }
            string path = _folderForReferencedResources_34748 + Path.GetFileName(resourceInfo.SupposedURL);

            System.IO.BinaryReader reader = new BinaryReader(resourceInfo.ContentStream);
            System.IO.File.WriteAllBytes(path, reader.ReadBytes((int)resourceInfo.ContentStream.Length));
        }