将图像导出为 PDF
我有一个必须将图像导出为 PDF 的项目。图像和文本都需要导出为 pdf。有没有办法通过使用 silverPDF.dll 和 PdfReader 来做到这一点?
代码在这里。
private void btnOutlook_Click(object sender, System.Windows.RoutedEventArgs e)
{
XBrush xbrush;
SaveFileDialog savePDF = new SaveFileDialog();
savePDF.Filter = "PDF file format | *.pdf";
if (savePDF.ShowDialog() == true)
{
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
XFont font = new XFont("Huxtable", 20, XFontStyle.Bold, options);
for (int x = 0; x < 10; x++)
{
if (x % 2 == 0)
{
xbrush = XBrushes.Red;
}
else
xbrush = XBrushes.Black;
gfx.DrawString(string.Format("{0}", stringArray[x]), font, xbrush, new XRect(0, (x * 20), page.Width, page.Height), XStringFormats.TopLeft);
}
document.Save(savePDF.OpenFile());
}
}
我可以在这段代码中的哪里插入将其插入到pdf中的图像?有什么办法吗?感谢您的所有回复。
I have a project that has to export images to PDF. Images and text alike are needed to be exported into pdf. is there a way to do this by using silverPDF.dll and PdfReader?
Code here.
private void btnOutlook_Click(object sender, System.Windows.RoutedEventArgs e)
{
XBrush xbrush;
SaveFileDialog savePDF = new SaveFileDialog();
savePDF.Filter = "PDF file format | *.pdf";
if (savePDF.ShowDialog() == true)
{
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
XFont font = new XFont("Huxtable", 20, XFontStyle.Bold, options);
for (int x = 0; x < 10; x++)
{
if (x % 2 == 0)
{
xbrush = XBrushes.Red;
}
else
xbrush = XBrushes.Black;
gfx.DrawString(string.Format("{0}", stringArray[x]), font, xbrush, new XRect(0, (x * 20), page.Width, page.Height), XStringFormats.TopLeft);
}
document.Save(savePDF.OpenFile());
}
}
where in this code can I insert an Image that inserts it to pdf? Is there any way? Thanks for all replies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
必须是 SilverPDF 吗?正如我以前使用 iTextSharp 库在我以前的雇主那里做过类似的事情(否则我会粘贴示例代码)
iTextSharp-Working-with-images
下载链接
Does it need to be SilverPDF? As Iv'e done something similar before at my previous employer using the iTextSharp library (otherwise I would've pasted sample code)
iTextSharp-Working-with-images
Download Link
Tesseract 4.1.1,在 C# 中将图像转换为 PDF 全文
这是一种从 jpg 图像构建具有全文图层的 PDF 的方法,只需使用 Visual Studio 2022 和 DotNet 6 内的 Nugget 包中的 Tesseract 4.1.1。
这是用于创建的函数来自多个 jpg 的 PDF。
只需像这样调用此方法:
PDFRenderer_OCR_MutipleJPG("C:\temp\outp","tilte","Document", 20);
"C:\temp\outp" ->不带扩展名的最终 pdf 的名称和路径,它将是“C:\temp\outp.pdf”。
Title=“标题”PDF 元信息
文档 ->是我的图像文件夹源和每个图像名称的一部分,没有索引。
这里要转换的图像文件夹是:
C:\temp\document\ ->里面:->文档1.jpg、文档2.jpg、文档3.jpg、...
20 是索引,表示要转换的图像数量。
可选的进度条,用于在处理过程中查看 UI 中的页码
最好的祝福
来自法国的弗朗西斯
Tesseract 4.1.1, converting Images to PDF Full Text in C#
Here is a way to build PDF with full text layer from jpg images, just using Tesseract 4.1.1 from Nugget package inside visual Studio 2022 and DotNet 6.
Here is Function for creating PDF from multiple jpg.
Just call this method like this:
PDFRenderer_OCR_MutipleJPG("C:\temp\outp","tilte","Document", 20);
"C:\temp\outp" -> name and path for final pdf without extension,it will be "C:\temp\outp.pdf".
Title= "title" meta information on PDF
Document -> is my image folder source and part of each image name without index.
Here the Folder of images to convert is:
C:\temp\document\ -> inside: -> Document1.jpg, Document2.jpg, Document3.jpg, ...
20 is the index, represent the number of images to convert.
Optional progressBar for watching page number in UI during processing
Best Regards
Francis from France