【发布时间】:2021-09-09 12:21:23
【问题描述】:
我正在尝试使用 syncfusion 创建一个 pdf,并使用此链接上显示的示例: https://www.syncfusion.com/kb/10673/how-to-create-a-pdf-document-in-aws-lambda
我创建了一个小型控制台应用程序,但在读取带有 HELP 注释的行中的数据时遇到问题。它正在寻找路径而不是读取示例链接中显示的字符串。 任何使用过类似产品的人都可以提出修复建议吗?谢谢
using System;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Drawing;
using System.IO;
using System.Text.Json;
using Newtonsoft.Json;
namespace pdf
{
class Program
{
static void Main(string[] args)
{
var result = GetData();
var stream = new StreamReader(result); //----> How do I read this? HELP
JsonReader reader = new JsonTextReader(stream);
var serilizer = new Newtonsoft.Json.JsonSerializer();
var responseText = serilizer.Deserialize(reader);
//Convert Base64String into PDF document
byte[] bytes = Convert.FromBase64String(responseText.ToString());
FileStream fileStream = new FileStream("Sample.pdf", FileMode.Create);
BinaryWriter writer = new BinaryWriter(fileStream);
writer.Write(bytes, 0, bytes.Length);
writer.Close();
System.Diagnostics.Process.Start("Sample.pdf");
}
static string GetData()
{
//Create a new PDF document
PdfDocument document = new PdfDocument();
//Add a page to the document
PdfPage page = document.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Set the standard font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
//Draw the text
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
string imagePath = Path.GetFullPath(@"Data\logo.png");
//Load the image from the disk
FileStream imageStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
PdfBitmap image = new PdfBitmap(imageStream);
//Draw the image
graphics.DrawImage(image, 30, 30, 100, 25);
//Save the document into stream
MemoryStream stream = new MemoryStream();
//Save the PDF document
document.Save(stream);
document.Close();
return (Convert.ToBase64String(stream.ToArray()));
}
}
}
【问题讨论】: