Any way to remove an art box

For certain pages in PDF documents we’re receiving, there appear to be art, trim, or bleed boxes added to the page (the pages are outlined in green when enabling the “Show art, trim, and bleed boxes” option is Adobe Acrobat). Is there any way to detect if a page has any of these boxes present as well as a way to remove them?

@omnom

You can analyze the page attributes to check if any art, trim, or bleed boxes are specified. Look into the Page CropBox, BleedBox, TrimBox, and ArtBox properties. If these properties are set to different values, it may indicate the presence of such boxes.

Here is a simplified example in Java to get you started. Please note that this is a general approach and may require additional checks and adjustments depending on the specific PDF files you are working with:

for (int pageNum = 1; pageNum <= pdfDocument.getPages().size(); pageNum++) {
    Page page = pdfDocument.getPages().get_Item(pageNum);

    // Set the CropBox, BleedBox, TrimBox, and ArtBox to match the MediaBox
    Rectangle mediaBox = page.getMediaBox();
    page.setCropBox(mediaBox);
    page.setBleedBox(mediaBox);
    page.setTrimBox(mediaBox);
    page.setArtBox(mediaBox);
}

Hmm, alright. The issue we’re running into is that starting with the page that Adobe Acrobat highlights as having an art, trim, or bleed box, the PdfFileMend class is placing images at a different place on the page compared with other pages even though we’re using identical coordinates for the images across all pages.

I’ve tried checking the page dimensions and the various box sizes in a few different ways, but all pages return identical values:

String pdf = "./001002934598001-initial.pdf";
Document doc = new Document(pdf);

for(int i = 0; i < doc.getPages().size(); i++)
{
	Page page = doc.getPages().get_Item(i+1);
	PageInfo info = page.getPageInfo();
	
	PdfFileInfo file = new PdfFileInfo();
	file.bindPdf(doc);
	
	PdfPageEditor editor = new PdfPageEditor();
	editor.bindPdf(doc);
	
	PageSize size = editor.getPageSize(i+1);
	
	String num = i+1 < 10 ? "Page 0" : "Page ";
	System.out.println(num + (i+1) + ": " + page.getArtBox() + " -- " + page.getMediaBox() + " -- " + page.getTrimBox() + " -- " + page.getBleedBox() + " -- " + page.getCropBox() + " -- " + page.getPageRect(true) + " -- " + info.getHeight() + 
		" -- " + info.getPureHeight() + " -- " + file.getPageHeight(i+1) + " -- " + file.getPageWidth(i+1) + " -- " + file.getPageXOffset(i+1) + " -- " + file.getPageYOffset(i+1) + " -- " + size.getHeight() + " -- " + size.getWidth() + 
		" -- " + editor.getPageRotation(i+1) + " -- " + page.getRotate() + " -- " + page.getHeader() + " -- " + page.getFooter());
}

@omnom

In such case, can you please share your sample PDF and the code snippet of adding images including coordinates values? Also, please share an expected resultant PDF as well. We will test the scenario in our environment and address it accordingly.

Unfortunately I’m not allowed to share these PDFs at this time. I have found a work around in the mean time, but I will probably come back to this once I’m allowed to share an example PDF that has this issue.

@omnom

Sure, please take your time to get back to us with sample file. We will further proceed to assist you accordingly.