विलय नीला Blobs (पीडीएफ़) में एक बूँद और करने के लिए डाउनलोड के माध्यम से उपयोगकर्ता सी# ASP.NET

0

सवाल

मैं एक ASP.NET नीला वेब आवेदन सी# में लिखा है कि शामिल है उपयोगकर्ता अपलोड अलग पीडीएफ़ में Azure ब्लॉब संग्रह. मैं करने के लिए उपयोगकर्ता बाद में डाउनलोड करने के लिए एक संयुक्त पीडीएफ के समावेशी पूर्व में अपलोड किए गए चारों एक विशिष्ट क्रम में. किसी भी विचार पर सबसे अच्छा तरीका है यह पूरा करने के लिए?

asp.net azure blob c#
2021-11-21 19:18:14
1

सबसे अच्छा जवाब

1

यहाँ हैं 2 समाधान है कि तुम कोशिश कर सकते हैं

  1. का उपयोग नीला कार्य करता है ।
  2. डाउनलोड अपने पीडीएफ फाइलों से Azure ब्लॉब के लिए अपने स्थानीय कंप्यूटर में है, तो उन्हें मर्ज.

उपयोग के कार्यों नीला

  1. बनाने के लिए एक नीला समारोह में परियोजना का उपयोग करें और HTTP ट्रिगर.
  2. सुनिश्चित करें कि आप स्थापित करें नीचे दिए गए पैकेज से पहले शुरू हो रही है के साथ कोडन ।
  3. बनाने के लिए समारोह कोड है ।
  4. बनाने नीला समारोह में पोर्टल.
  5. कोड प्रकाशित.

हम कर रहे हैं लेखन शुरू के लिए तैयार कोड है । हम की जरूरत है दो फाइलें:

  1. ResultClass.सीएस – रिटर्न मर्ज किए गए फ़ाइल(एस) एक सूची के रूप में.
  2. Function1.सीएस – CCode लेता है कि फ़ाइल नाम से, यूआरएल पकड़ लेता है उन्हें भंडारण से खाता है, विलीन हो जाती है उन में से एक है, और रिटर्न एक डाउनलोड यूआरएल.

ResultClass.सीएस

using System;
using System.Collections.Generic;

namespace FunctionApp1
{

    public class Result
    {

        public Result(IList<string> newFiles)
        {
            this.files = newFiles;
        }

        public IList<string> files { get; private set; }
    }
}

Function1.सीएस

using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

namespace FunctionApp1
{
    public class Function1
    {

        static Function1()
        {

            // This is required to avoid the "No data is available                         for encoding 1252" exception when saving the PdfDocument
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

        }

        [FunctionName("Function1")]
        public async Task<Result> SplitUploadAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req,
            //container where files will be stored and accessed for retrieval. in this case, it's called temp-pdf
            [Blob("temp-pdf", Connection = "")] CloudBlobContainer outputContainer,
            ILogger log)
        {
            //get query parameters

            string uriq = req.RequestUri.ToString(); 
            string keyw = uriq.Substring(uriq.IndexOf('=') + 1);

            //get file name in query parameters
            String fileNames = keyw.Split("mergepfd&filenam=")[1];

            //split file name
            string[] files = fileNames.Split(',');

            //process merge
            var newFiles = await this.MergeFileAsync(outputContainer, files);

            return new Result(newFiles);

        }

        private async Task<IList<string>> MergeFileAsync(CloudBlobContainer container, string[] blobfiles)
        {
            //init instance
            PdfDocument outputDocument = new PdfDocument();

            //loop through files sent in query
            foreach (string fileblob in blobfiles)
            {
                String intfile = $"" + fileblob;

                // get file
                CloudBlockBlob blob = container.GetBlockBlobReference(intfile);

                using (var memoryStream = new MemoryStream())
                {
                    await blob.DownloadToStreamAsync(memoryStream);

                    //get file content
                    string contents = blob.DownloadTextAsync().Result;
                   
                    //open document
                    var inputDocument = PdfReader.Open(memoryStream, PdfDocumentOpenMode.Import);

                    //get pages
                    int count = inputDocument.PageCount;
                    for (int idx = 0; idx < count; idx++)
                    {
                        //append
                        outputDocument.AddPage(inputDocument.Pages[idx]);
                    }


                }
            }


            var outputFiles = new List<string>();
            var tempFile = String.Empty;

            //call save function to store output in container
            tempFile = await this.SaveToBlobStorageAsync(container, outputDocument);

            outputFiles.Add(tempFile);

            //return file(s) url
            return outputFiles;
        }

        private async Task<string> SaveToBlobStorageAsync(CloudBlobContainer container, PdfDocument document)
        {

            //file name structure
            var filename = $"merge-{DateTime.Now.ToString("yyyyMMddhhmmss")}-{Guid.NewGuid().ToString().Substring(0, 4)}.pdf";

            // Creating an empty file pointer
            var outputBlob = container.GetBlockBlobReference(filename);

            using (var stream = new MemoryStream())
            {
                //save result of merge
                document.Save(stream);
                await outputBlob.UploadFromStreamAsync(stream);
            }

            //get sas token
            var sasBlobToken = outputBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
            {
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5),
                Permissions = SharedAccessBlobPermissions.Read
            });

            //return sas token
            return outputBlob.Uri + sasBlobToken;
        }
    }
}

डाउनलोड अपने पीडीएफ फाइलों से Azure ब्लॉब के लिए अपने स्थानीय कंप्यूटर में है, तो उन्हें मर्ज

 internal static void combineNormalPdfFiles()
        {
            String inputFilePath1 = @"C:\1.pdf";
            String inputFilePath2 = @"C:\2.pdf";
            String inputFilePath3 = @"C:\3.pdf";
            String outputFilePath = @"C:\Output.pdf";
            String[] inputFilePaths = new String[3] { inputFilePath1, inputFilePath2, inputFilePath3 };

            // Combine three PDF files and output.
            PDFDocument.CombineDocument(inputFilePaths, outputFilePath);
        }

संदर्भ:

  1. नीला समारोह गठबंधन करने के लिए पीडीएफ में चारों Azure संग्रहण खाता (बूँद कंटेनर)
  2. C# मर्ज पीडीएफ एसडीके: विलय, गठबंधन में पीडीएफ फाइलों C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
2021-11-22 05:18:46

SwethaKandikonda-मीट्रिक टन, यह एक अद्भुत समाधान और एक है कि मैं सफलतापूर्वक में शामिल किया मेरी वेबसाइट. मेरे कई ईमानदारी से धन्यवाद करने के लिए आप के लिए जवाब! मैं काम नहीं किया था के साथ नीला कार्य करने से पहले, अपनी टिप्पणी, लेकिन मुझे पता है कि इतना अधिक अब. आदेश और संकलन अपलोड नीला बूँद पीडीएफ़ में से एक पीडीएफ था कुछ मैं लगभग छोड़ दिया, पर जब तक यह.
Wallstreetguy

अगर मेरा जवाब मदद की है, तो आप इसे स्वीकार कर सकते हैं एक जवाब के रूप में (क्लिक पर सही का निशान के बगल में जवाब टॉगल करने के लिए इसे से बाहर greyed में भरने के लिए). यह कर सकते हैं फायदेमंद हो करने के लिए अन्य समुदाय के सदस्यों. धन्यवाद
SwethaKandikonda-MT

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में