无法在带有iText7.0.5.0的页面上放置artbox和trimbox
源状态然后页面上只能存在修剪框或ArtBox。 事实并非如此,它们可以同时存在于页面上。
PdfPage.java的第615行
/**
* Sets the TrimBox object, that define the intended dimensions of the finished page after trimming.
*
* @param rectangle the {@link Rectangle} object to set, expressed in default user space units.
* @return this {@link PdfPage} instance.
*/
public PdfPage setTrimBox(Rectangle rectangle) {
if (getPdfObject().getAsRectangle(PdfName.ArtBox) != null) {
getPdfObject().remove(PdfName.ArtBox);
Logger logger = LoggerFactory.getLogger(PdfPage.class);
logger.warn(LogMessageConstant.ONLY_ONE_OF_ARTBOX_OR_TRIMBOX_CAN_EXIST_IN_THE_PAGE);
}
put(PdfName.TrimBox, new PdfArray(rectangle));
return this;
}
/**
* Sets the ArtBox object, that define the extent of the page’s meaningful content
* (including potential white space) as intended by the page’s creator.
*
* @param rectangle the {@link Rectangle} object to set, expressed in default user space units.
* @return this {@link PdfPage} instance.
*/
public PdfPage setArtBox(Rectangle rectangle) {
if (getPdfObject().getAsRectangle(PdfName.TrimBox) != null) {
getPdfObject().remove(PdfName.TrimBox);
Logger logger = LoggerFactory.getLogger(PdfPage.class);
logger.warn(LogMessageConstant.ONLY_ONE_OF_ARTBOX_OR_TRIMBOX_CAN_EXIST_IN_THE_PAGE);
}
put(PdfName.ArtBox, new PdfArray(rectangle));
return this;
}
提议的解决方案:
/**
* Gets the {@link Rectangle} object specified by page's ArtBox, that define the extent of the page’s
* meaningful content (including potential white space) as intended by the page’s creator.
*
* @return the {@link Rectangle} object specified by page's ArtBox, expressed in default user space units.
* CropBox by default.
*/
public Rectangle getArtBox() {
Rectangle artBox = getPdfObject().getAsRectangle(PdfName.ArtBox);
return artBox == null ? getCropBox() : artBox;
}
/**
* Sets the TrimBox object, that define the intended dimensions of the finished page after trimming.
*
* @param rectangle the {@link Rectangle} object to set, expressed in default user space units.
* @return this {@link PdfPage} instance.
*/
public PdfPage setTrimBox(Rectangle rectangle) {
put(PdfName.TrimBox, new PdfArray(rectangle));
return this;
}