使用 PDF Clown 写入 pdf 文件时如何跳过行?

How can I skip lines when writing to a pdf file using PDF Clown?

如何在使用 PDF Clown 写入 pdf 文件时跳过行?我在 IntelliJ 中使用它。

我将它用于将文本写入 pdf 文件的非常基本的内容,很难想象没有关于如何跳过行的说明。

如有任何帮助,我们将不胜感激。

// Create a document and add a page to it
    try {

        // 1. Instantiate a new PDF document!
        Document document = new File().getDocument();

        // 2. Add a page to the document!
        Page page = new Page(document); // Instantiates the page inside the document context.
        document.getPages().add(page); // Puts the page in the pages collection (you may choose an arbitrary position).

        // 3. Create a content composer for the page!
        PrimitiveComposer composer = new PrimitiveComposer(page);

        // 4. Add contents through the composer!
        composer.setFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 32);
        composer.showText("Hello World!", new Point2D.Double(32, 48));

        // 5. Flush the contents into the page!
        composer.flush();

        // 6. Save the document!
        document.getFile().save(job.getUpdateFileLocalDir() + "/pdfclown.pdf" , SerializationModeEnum.Standard);

    } catch (Exception e) {
        System.out.println("Exception is: ");
    }

使用 BlockComposer 以获得更高级的文本内容。 Click here for a complex example utilizing paragraphs with BlockComposer. There are plenty of other examples and resources在线了解如何使用它。

编辑: 基于您的代码的示例

import java.awt.Dimension;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import org.pdfclown.documents.Document;
import org.pdfclown.documents.Page;
import org.pdfclown.documents.contents.composition.BlockComposer;
import org.pdfclown.documents.contents.composition.PrimitiveComposer;
import org.pdfclown.documents.contents.composition.XAlignmentEnum;
import org.pdfclown.documents.contents.composition.YAlignmentEnum;
import org.pdfclown.documents.contents.fonts.Font;
import org.pdfclown.documents.contents.fonts.StandardType1Font;
import org.pdfclown.files.File;
import org.pdfclown.files.SerializationModeEnum;

public class Main {

    private static final int Margin_X = 50;
    private static final int Margin_Y = 50;

    public static void main(String args[])
    {
        try {

            Document document = new File().getDocument();

            Page page = new Page(document);
            document.getPages().add(page); 

            Dimension2D pageSize = page.getSize();

            PrimitiveComposer composer = new PrimitiveComposer(page);

            BlockComposer blockComposer = new BlockComposer(composer);

            composer.beginLocalState();

            Rectangle2D frame = new Rectangle2D.Double(Margin_X, Margin_Y, pageSize.getWidth() - Margin_X * 2, pageSize.getHeight() - Margin_Y * 2);

            blockComposer.begin(frame,XAlignmentEnum.Left,YAlignmentEnum.Top);

            Dimension breakSize = new Dimension(24, 8); // Indentation (24pt)
                                                        // and top margin (8pt).

            composer.setFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 14);

            blockComposer.begin(frame, XAlignmentEnum.Left, YAlignmentEnum.Top);

            blockComposer.showBreak(breakSize);
            blockComposer.showText("There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, 'Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge.");
            blockComposer.showBreak(breakSize);
            blockComposer.showText("Wassup");

            blockComposer.end();

            composer.flush();

            document.getFile().save(job.getUpdateFileLocalDir() + "/pdfclown.pdf" , SerializationModeEnum.Standard);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}