मैं एक ASP.NET नीला वेब आवेदन सी# में लिखा है कि शामिल है उपयोगकर्ता अपलोड अलग पीडीएफ़ में Azure ब्लॉब संग्रह. मैं करने के लिए उपयोगकर्ता बाद में डाउनलोड करने के लिए एक संयुक्त पीडीएफ के समावेशी पूर्व में अपलोड किए गए चारों एक विशिष्ट क्रम में. किसी भी विचार पर सबसे अच्छा तरीका है यह पूरा करने के लिए?
1
यहाँ हैं 2 समाधान है कि तुम कोशिश कर सकते हैं
- का उपयोग नीला कार्य करता है ।
- डाउनलोड अपने पीडीएफ फाइलों से Azure ब्लॉब के लिए अपने स्थानीय कंप्यूटर में है, तो उन्हें मर्ज.
उपयोग के कार्यों नीला
- बनाने के लिए एक नीला समारोह में परियोजना का उपयोग करें और HTTP ट्रिगर.
- सुनिश्चित करें कि आप स्थापित करें नीचे दिए गए पैकेज से पहले शुरू हो रही है के साथ कोडन ।
- बनाने के लिए समारोह कोड है ।
- बनाने नीला समारोह में पोर्टल.
- कोड प्रकाशित.
हम कर रहे हैं लेखन शुरू के लिए तैयार कोड है । हम की जरूरत है दो फाइलें:
- ResultClass.सीएस – रिटर्न मर्ज किए गए फ़ाइल(एस) एक सूची के रूप में.
- 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);
}
संदर्भ:
SwethaKandikonda-मीट्रिक टन, यह एक अद्भुत समाधान और एक है कि मैं सफलतापूर्वक में शामिल किया मेरी वेबसाइट. मेरे कई ईमानदारी से धन्यवाद करने के लिए आप के लिए जवाब! मैं काम नहीं किया था के साथ नीला कार्य करने से पहले, अपनी टिप्पणी, लेकिन मुझे पता है कि इतना अधिक अब. आदेश और संकलन अपलोड नीला बूँद पीडीएफ़ में से एक पीडीएफ था कुछ मैं लगभग छोड़ दिया, पर जब तक यह.
Wallstreetguy
अगर मेरा जवाब मदद की है, तो आप इसे स्वीकार कर सकते हैं एक जवाब के रूप में (क्लिक पर सही का निशान के बगल में जवाब टॉगल करने के लिए इसे से बाहर greyed में भरने के लिए). यह कर सकते हैं फायदेमंद हो करने के लिए अन्य समुदाय के सदस्यों. धन्यवाद
SwethaKandikonda-MT