using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
namespace FunctionApp5
{
public class Function1
{
[FunctionName("Function1")]
public void Run([BlobTrigger("pdfcontainer/{name}", Connection = "constr")]Stream myBlob, string name,
[Blob("textcontainer/1.txt", FileAccess.Write, Connection = "constr")] Stream outputBlob,ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
PdfReader reader = new PdfReader(myBlob);
int intPageNum = reader.NumberOfPages;
string[] words;
string line;
string text;
for (int i = 1; i <= intPageNum; i++)
{
text = PdfTextExtractor.GetTextFromPage(reader, i, new LocationTextExtractionStrategy());
using (var writer = new StreamWriter(outputBlob))
{
writer.Write(text);
}
}
}
}
}
结果:*
提取的文本触发一个函数,该函数对结果进行优化并在容器中写入第三个文件
Function2.cs -阅读上传的文本文件并进行一些操作,然后将其保存到另一个容器 *
using System.IO;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
namespace FunctionApp5
{
public class Function2
{
[FunctionName("Function2")]
public void Run([BlobTrigger("textcontainer/{name}", Connection = "constr")] Stream myBlob, string name,
[Blob("finalcontainer/1.txt", FileAccess.Write, Connection = "constr")] Stream outputBlob, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
string finalValue;
using (var reader = new StreamReader(myBlob, Encoding.UTF8))
{
finalValue = reader.ReadLine();
}
using (var writer = new StreamWriter(outputBlob))
{
writer.Write(finalValue.ToUpper());
}
}
}
}
1条答案
按热度按时间piok6c0g1#
从我的结束后再现,这是工作正常,当我按照下面的过程.我已经创建了2 Blob触发函数,其中一个是转换PDF到txt文件,另一个是读取txt文件,做所需的操作,然后保存到另一个容器.
pdf触发一个函数,该函数提取文本并将其保存为容器中的txt
提取的文本触发一个函数,该函数对结果进行优化并在容器中写入第三个文件