如何设置 ImageMagick PDF 的标题

发布于 2025-01-13 02:56:29 字数 1210 浏览 3 评论 0原文

当我在浏览器中查看 PDF 时,它有一个以 Magic 开头的图块... 有没有办法设置生成的 PDF 文件的标题?

        public MemoryStream ConvertToTiff(Stream inputStream)
        {
            try
            {
                inputStream.Seek(0, SeekOrigin.Begin);
                MemoryStream outputStream = new MemoryStream();
                using (MagickImageCollection imageMagickOut = new MagickImageCollection())
                using (MagickImageCollection imageMagickIn = new MagickImageCollection())
                {
                    imageMagickIn.Read(inputStream, _readSettings);
                    foreach (MagickImage img in imageMagickIn)
                    {
                        img.Format = MagickFormat.Tif;
                        img.SetCompression(CompressionMethod.Group4);
                        imageMagickOut.Add(img);
                    }
                    imageMagickOut.Write(outputStream, MagickFormat.Tif);
                }
                outputStream.Seek(0, SeekOrigin.Begin);
                return outputStream;
            }catch( Exception e )
            {
                throw e;
            }
        }

使用 nuget 包 Magick.Net.Core & Magick.Net-Q16-x64 版本 10.0.0

When I view the PDF in a browser it has a tile that starts with Magic... Is there a way to set the title of the resulting PDF file?

        public MemoryStream ConvertToTiff(Stream inputStream)
        {
            try
            {
                inputStream.Seek(0, SeekOrigin.Begin);
                MemoryStream outputStream = new MemoryStream();
                using (MagickImageCollection imageMagickOut = new MagickImageCollection())
                using (MagickImageCollection imageMagickIn = new MagickImageCollection())
                {
                    imageMagickIn.Read(inputStream, _readSettings);
                    foreach (MagickImage img in imageMagickIn)
                    {
                        img.Format = MagickFormat.Tif;
                        img.SetCompression(CompressionMethod.Group4);
                        imageMagickOut.Add(img);
                    }
                    imageMagickOut.Write(outputStream, MagickFormat.Tif);
                }
                outputStream.Seek(0, SeekOrigin.Begin);
                return outputStream;
            }catch( Exception e )
            {
                throw e;
            }
        }

Using nuget packages Magick.Net.Core & Magick.Net-Q16-x64 version 10.0.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱自由 2025-01-20 02:56:29

我将代码更改为以下内容。

                    foreach (MagickImage img in imageMagickIn)
                    {
                        img.Format = MagickFormat.Tif;
                        img.SetCompression(CompressionMethod.Group4);

                        img.Settings.SetDefine(MagickFormat.Pdf, "Title", "");
                        img.Settings.SetDefine(MagickFormat.Pdf, "Producer", "");
                        img.Settings.SetDefine(MagickFormat.Pdf, "Author", "");

                        imageMagickOut.Add(img);
                    }

I changed the code to the following.

                    foreach (MagickImage img in imageMagickIn)
                    {
                        img.Format = MagickFormat.Tif;
                        img.SetCompression(CompressionMethod.Group4);

                        img.Settings.SetDefine(MagickFormat.Pdf, "Title", "");
                        img.Settings.SetDefine(MagickFormat.Pdf, "Producer", "");
                        img.Settings.SetDefine(MagickFormat.Pdf, "Author", "");

                        imageMagickOut.Add(img);
                    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文