2

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();
    }
}
4

1 に答える 1

0

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);
                            }
                        }
                    }
                }
            }
于 2015-10-15T17:44:37.780 に答える