예제 #1
0
        // ExStart:PrefixForURLsHelper
        private static string Custom_processor_of_embedded_images(SaveOptions.ResourceSavingInfo resourceSavingInfo)
        {
            // ____________________________________________________________________________
            //    This sample method saving strategy method saves image-files in some folder
            //    (including raster image files that are exctracted from that SVGs)
            //    Then it returns specific custom artificial  path
            //    to be used as value of 'src' or 'data' relevant attribute in generated host-SVG(or HTML)
            // ____________________________________________________________________________

            //---------------------------------------------------------
            // 1) All other files(f.e. fonts) will be processed with converter itself cause for them flag
            //   resourceSavingInfo.CustomProcessingCancelled is set to 'true'
            //---------------------------------------------------------
            if (!(resourceSavingInfo is HtmlSaveOptions.HtmlImageSavingInfo))
            {
                resourceSavingInfo.CustomProcessingCancelled = true;
                return("");
            }
            //---------------------------------------------------------
            // 1) Create target folder if not created yet
            //---------------------------------------------------------
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
            string outDir  = dataDir + @"output\36297_files\";
            string outPath = outDir + Path.GetFileName(resourceSavingInfo.SupposedFileName);

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }
            //---------------------------------------------------------
            // 3) Write supplied image to that folder
            //---------------------------------------------------------
            System.IO.BinaryReader reader = new BinaryReader(resourceSavingInfo.ContentStream);
            System.IO.File.WriteAllBytes(dataDir, reader.ReadBytes((int)resourceSavingInfo.ContentStream.Length));
            //---------------------------------------------------------
            // 4) Return customized specific URL to be used to refer
            //    just created image in parent SVG (or HTML)
            //---------------------------------------------------------
            HtmlSaveOptions.HtmlImageSavingInfo asHtmlImageSavingInfo = resourceSavingInfo as HtmlSaveOptions.HtmlImageSavingInfo;
            if (asHtmlImageSavingInfo.ParentType == HtmlSaveOptions.ImageParentTypes.SvgImage)
            {
                return("http://localhost:255/" + resourceSavingInfo.SupposedFileName);
            }
            else
            {
                return("http://localhost:GetImage/imageID=" + resourceSavingInfo.SupposedFileName);
            }
        }
        // ExStart:SpecifyPrefixForImagesHelper
        private static string SavingTestStrategy_1(SaveOptions.ResourceSavingInfo resourceSavingInfo)
        {
            // This sample method saving strategy method saves only svg-files in some folder and returns specific path
            // To be used as value of 'src' or 'data' relevant attribute in generated HTML
            // All other files will be processed with converter itself cause for them flag
            // ResourceSavingInfo.CustomProcessingCancelled is set to 'true'
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();

            if (!(resourceSavingInfo is HtmlSaveOptions.HtmlImageSavingInfo))
            {
                resourceSavingInfo.CustomProcessingCancelled = true;
                return("");
            }

            HtmlSaveOptions.HtmlImageSavingInfo asHtmlImageSavingInfo = (HtmlSaveOptions.HtmlImageSavingInfo)resourceSavingInfo;

            if ((asHtmlImageSavingInfo.ImageType != HtmlSaveOptions.HtmlImageType.Svg) &&
                (asHtmlImageSavingInfo.ImageType != HtmlSaveOptions.HtmlImageType.ZippedSvg)
                )
            {
                resourceSavingInfo.CustomProcessingCancelled = true;
                return("");
            }

            string outFile        = dataDir + "SpecifyImages_out.html";
            string imageOutFolder = Path.GetFullPath(Path.GetDirectoryName(outFile)
                                                     + @"\35956_svg_files\");

            // ImageOutFolder="C:\AsposeImagesTests\";
            if (!Directory.Exists(imageOutFolder))
            {
                Directory.CreateDirectory(imageOutFolder);
            }

            string outPath = imageOutFolder + Path.GetFileName(resourceSavingInfo.SupposedFileName);

            System.IO.BinaryReader reader = new BinaryReader(resourceSavingInfo.ContentStream);
            System.IO.File.WriteAllBytes(outPath, reader.ReadBytes((int)resourceSavingInfo.ContentStream.Length));

            return("/document-viewer/GetImage?path=CRWU-NDWAC-Final-Report-12-09-10-2.pdf&name=" + resourceSavingInfo.SupposedFileName);
        }