Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java-ApachePDFBox两篇A3论文比一篇A2?_Java_Apache_Pdf_Pdfbox_Printers - Fatal编程技术网

Java-ApachePDFBox两篇A3论文比一篇A2?

Java-ApachePDFBox两篇A3论文比一篇A2?,java,apache,pdf,pdfbox,printers,Java,Apache,Pdf,Pdfbox,Printers,我有一台打印机不支持我需要的功能 打印机打印A2纸张尺寸。我想打印两个A3大小的页面,将放在一张A2纸上,但我的打印机不支持此功能 我已经打电话给公司的技术支持部门,但他们告诉我需要买一台更新的,因为我的打印机不支持这个功能。(这非常有趣,因为该打印机的更旧版本确实支持此功能) 所以我尝试使用Apache PDFBox,在那里我可以像这样加载我的pdf文件: File pdfFile = new File(path); PDDocument pdfDocument = load(pdfFile)

我有一台打印机不支持我需要的功能

打印机打印
A2
纸张尺寸。我想打印两个
A3
大小的页面,放在一张
A2
纸上,但我的打印机不支持此功能

我已经打电话给公司的技术支持部门,但他们告诉我需要买一台更新的,因为我的打印机不支持这个功能。(这非常有趣,因为该打印机的更旧版本确实支持此功能)

所以我尝试使用Apache PDFBox,在那里我可以像这样加载我的pdf文件:

File pdfFile = new File(path);
PDDocument pdfDocument = load(pdfFile);
我加载的文件是大小
A3
。我想如果我能得到一份纸张大小为
A2
的新PDDocument就足够了。然后将我加载的
pdfFile
放在
A2
纸上两次

总之,我需要在一个页面上加载两次的文件。我只是不知道怎么做


致以最诚挚的问候。

您可能想看看,根据其JavaDoc,它几乎可以满足您的需要:

此示例演示如何将多个页面合并为单个更大的页面(例如 使用XObject[PDF:1.6:4.9]表格将两个A4模块转换为一个A3模块)。 表单XObject是一种方便的方式,可以在多个页面上多次表示内容 模板

中央代码:

// 1. Opening the source PDF file...
File sourceFile = new File(filePath);

// 2. Instantiate the target PDF file!
File file = new File();

// 3. Source page combination into target file.
Document document = file.getDocument();
Pages pages = document.getPages();
int pageIndex = -1;
PrimitiveComposer composer = null;
Dimension2D targetPageSize = PageFormat.getSize(SizeEnum.A4);
for(Page sourcePage : sourceFile.getDocument().getPages())
{
    pageIndex++;
    int pageMod = pageIndex % 2;
    if(pageMod == 0)
    {
        if(composer != null)
        {composer.flush();}

        // Add a page to the target document!
        Page page = new Page(
            document,
            PageFormat.getSize(SizeEnum.A3, OrientationEnum.Landscape)
        ); // Instantiates the page inside the document context.
        pages.add(page); // Puts the page in the pages collection.
        // Create a composer for the target content stream!
        composer = new PrimitiveComposer(page);
    }

    // Add the form to the target page!
    composer.showXObject(
        sourcePage.toXObject(document), // Converts the source page into a form inside the target document.
        new Point2D.Double(targetPageSize.getWidth() * pageMod, 0),
        targetPageSize,
        XAlignmentEnum.Left,
        YAlignmentEnum.Top,
        0
    );
}
composer.flush();

// 4. Serialize the PDF file!
serialize(file, "Page combination", "combining multiple pages into single bigger ones", "page combination");

// 5. Closing the PDF file...
sourceFile.close();

如果使用iText也是一种选择,我建议查看示例。通过一些小的修改(而不是使用原始文档的页面大小缩小目标文档中的页面,您必须保持比例并使用两倍于原始文档页面大小的目标文档)。不过,我假设PDFBox也能做到这一点。请注意:这使用的是pdfclown,而不是问题中要求的PDFBox。当我在pdfbox中搜索相应的类时,我得到了一个很短的时间,但没有找到它们。。。因此,答案可能适用于原始海报,但不适用于那些已经拥有大量依赖pdfbox的代码的人。@cello哦,你是对的。我真的不知道为什么我要以PdfClown为例。。。特别是在我在对原始问题的评论中提到iText之后。。。