RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 879947
Accepted
Юрик Тао
Юрик Тао
Asked:2020-09-11 16:31:25 +0000 UTC2020-09-11 16:31:25 +0000 UTC 2020-09-11 16:31:25 +0000 UTC

打印 PDF 文件,每张多页

  • 772

有一个 PDF 文件,您需要编写一个代码来打印这个文件,并在一张纸上拆分几页(例如,4.8 x 1),我使用库 Spire.PDF、Spire.Document(来源:https:// www.e-iceblue.com/Introduce/pdf-for-net-introduce.html#.W5d0JvYnZPY)和 ZetPdf(来源:https ://zetpdf.com/ )。如果您通过 Spire.Pdf 组件工作,那么我使用这种方法(代码取自文档)

internal static void splitPdfFileByBookmarks()
    {

        using (PdfDocument pdf = new PdfDocument(PdfConformanceLevel.Pdf_A1A))
        {
            pdf.LoadFromFile(@"d:\PdfFiles\10_11_1808_p.pdf");
            pdf.FileInfo.Version = PdfVersion.Version1_7;
            PdfPageBase pageBase = pdf.Pages.Add(PdfPageSize.A4, new PdfMargins());

这里我们一页放4页。我保存文档,也保存不拆分

            pdf.PrintSettings.SelectMultiPageLayout(1,4);

            pdf.SaveToFile(@"d:\PdfFiles\file.pdf",FileFormat.PDF);
        }
    }

如果您使用 ZetPdf 组件,则只有 2 页的拆分。1,但没有更多。

 string filename = "Portable Document Format.pdf";
            File.Copy(Path.Combine("../../../../../PDFs/", filename),
              Path.Combine(Directory.GetCurrentDirectory(), filename), true);

            // Create the output document
            PdfDocument outputDocument = new PdfDocument();

            // Show single pages
            // (Note: one page contains two pages from the source document)
            outputDocument.PageLayout = PdfPageLayout.SinglePage;

            XFont font = new XFont("Verdana", 8, XFontStyle.Bold);
            XStringFormat format = new XStringFormat();
            format.Alignment = XStringAlignment.Center;
            format.LineAlignment = XLineAlignment.Far;
            XGraphics gfx;
            XRect box;

            // Open the external document as XPdfForm object
            XPdfForm form = XPdfForm.FromFile(filename);

            for (int idx = 0; idx < form.PageCount; idx += 2)
            {
            // Add a new page to the output document

在这部分代码中添加了一个页面,我尝试创建 page_2 并添加页面错误“无法将页面添加到此文档,因为该文档已拥有此页面。”

            PdfPage page = outputDocument.AddPage();
            page.Orientation = PageOrientation.Landscape;
            double width = page.Width;
            double height = page.Height;

            int rotate = page.Elements.GetInteger("/Rotate");

                gfx = XGraphics.FromPdfPage(page);

                // Set page number (which is one-based)
                form.PageNumber = idx + 1;

                box = new XRect(0, 0, width/4, height/2);
                // Draw the page identified by the page number like an image
                gfx.DrawImage(form, box);

                // Write document file name and page number on each page
                box.Inflate(0, -10);
                gfx.DrawString(String.Format("- {1} -", filename, idx + 1),
                  font, XBrushes.Red, box, format);

                if (idx + 1 < form.PageCount)
                {
                // Set page number (which is one-based)
                form.PageNumber = idx + 2;

                    box = new XRect(width / 4, 0, width/4 , height/2);
                    // Draw the page identified by the page number like an image
                    gfx.DrawImage(form, box);

                    // Write document file name and page number on each page
                    box.Inflate(0, -10);
                    gfx.DrawString(String.Format("- {1} -", filename, idx + 2),
                      font, XBrushes.Red, box, format);
                }
            }

            // Save the document...
            filename = "TwoPagesOnOne_tempfile.pdf";
            outputDocument.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);

有没有人遇到过这样的问题?现在我在挖掘其他组件,也许有人会告诉你一些解决方案。

c#
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Юрик Тао
    2020-09-12T04:16:43Z2020-09-12T04:16:43Z

    他自己找到了答案,错误地处理了任务,最初我们有一个文档,我们在一张纸上形成 2 页(代码取自这里:http ://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx ) ,当文档形成时,我们再次对 2x1 文档重复相同的操作,结果我们在工作表上有 4 或 8 页

    • 0

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5