gpt4 book ai didi

c# - ABCpdf 只渲染第一页

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:01 32 4
gpt4 key购买 nike

当我尝试使用 ABCpdf 将每个页面保存为 GIF 时,只保存了第一页。

例如:我有一个包含 3 页的 PDF。我使用 ABCpdf 将每个页面呈现为流,并保存到磁盘。当我打开目标文件夹中的文件时,所有 3 个文件都显示第一页内容。

这是我的代码:

using (Doc theDoc = new Doc())
{
XReadOptions options = new XReadOptions { ReadModule = ReadModuleType.Pdf };
theDoc.Read(inputbytearray, options);

using (MemoryStream ms = new MemoryStream())
{
theDoc.Rendering.DotsPerInch = 150;
int n = theDoc.PageCount;

for (int i = 1; i <= n; i++)
{
Guid FileName = Guid.NewGuid();

theDoc.Rect.String = theDoc.CropBox.String;
theDoc.Rendering.SaveAppend = (i != 1);
theDoc.Rendering.SaveCompression = XRendering.Compression.G4;
theDoc.PageNumber = i;



theDoc.Rendering.Save(string.Format("{0}.gif", FileName), ms);

using (var streamupload = new MemoryStream(ms.GetBuffer(), writable: false))
{
_BlobStorageService.UploadfromStream(FileName.ToString(), streamupload, STR_Gif, STR_Imagegif);
}



}
// theDoc.Clear();
}
}

最佳答案

Rendering.SaveAppend 属性仅在保存 TIFF 图像时适用。对于 GIF,您需要为每个 PDF 页面保存单独的图像。

private void button1_Click(object sender, System.EventArgs e)
{
string theDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + @"\files\";

// Create test PDF

using (Doc doc = new Doc())
{
for (int i = 1; i <= 3; i++)
{
doc.Page = doc.AddPage();
doc.AddHtml("<font size=24>PAGE " + i.ToString());
}
doc.Save(Path.Combine(theDir, "test.pdf"));
}

// Save PDF pages to GIF streams

using (Doc doc = new Doc())
{
doc.Read(Path.Combine(theDir, "test.pdf"));
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
doc.Rect.String = doc.CropBox.String;
using (MemoryStream ms = new MemoryStream())
{
doc.Rendering.Save("dummy.gif", ms);
using (FileStream fs = File.Create(Path.Combine(theDir, "p" + i.ToString() + ".gif")))
{
ms.Seek(0, SeekOrigin.Begin);
ms.CopyTo(fs);
}
}
}
}
}

关于c# - ABCpdf 只渲染第一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33089893/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com