Hi @FalconArt, I have written a script to do this. I assumed that you will want to apply an Object Style to each anchored frame—this allows you to set the frame size and frame fitting options as well as anchored object options, and to edit *all* the frames at once later on.
So before running the script, first create a suitable object style called "My Object Style" (you can change the name by editing the script). Then put your insertion point in a text frame (or just select the text frame) and run the script. It will ask you to choose a pdf file.
Please try it out and let me know how it goes.
- Mark
/**
* Placed multipage pdf into text flow.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/placing-a-multi-page-pdf-into-the-text-flow-like-inline-images/m-p/14455140
*/
function main() {
// edit this for your document
var objectStyleName = 'My Object Style',
doc = app.activeDocument,
myObjectStyle = doc.objectStyles.itemByName(objectStyleName);
if (!myObjectStyle.isValid)
return alert('Failed: Could not find Object Style "' + objectStyleName + '".');
var pdf;
if (undefined == pdf) {
pdf = chooseFile('pdf');
if (!pdf)
return;
}
if (!pdf.exists)
return alert('File "' + decodeURI(pdf.name) + '" doesn\'t exist.');
importPDFAsAnchoredGraphics(pdf, doc.selection[0], function (frame) {
// apply object style to pdf's parent frame
frame.appliedObjectStyle = myObjectStyle
// add a carriage return after the anchored frame
frame.parent.insertionPoints[-1].contents = '\r';
// return the insertionPoint after the carriage return
return frame.parent.parent.characters
.nextItem(frame.parent).insertionPoints[-1];
});
} // end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Anchor Multipage PDF');
/**
* Places every page of a PDF file into the
* text flow as anchored graphics.
*
* Note: the `doToFrame` may, optionally return
* a new insertionPoint, which is where the
* next frame will be placed.
* @author m1b
* @version 2024-02-29
* @param {File} pdf - the pdf file.
* @param {InsertionPoint|TextFrame} textThing - an InsertionPoint or ancestor of one.
* @param {Function} [frameFunction] - a function that executes for each placed page of the pdf (default: nothing).
*/
function importPDFAsAnchoredGraphics(pdf, textThing, frameFunction) {
// convert into insertionPoint
if (undefined == textThing)
return;
else if (
textThing.hasOwnProperty('insertionPoints')
&& textThing.insertionPoints.length > 0
)
textThing = textThing.insertionPoints[-1];
else if (textThing.hasOwnProperty('story'))
textThing = textThing.story.insertionPoints[-1];
else
return alert('Could not place pdf there.');
app.pdfPlacePreferences.pdfCrop = PDFCrop.CROP_MEDIA;
var firstImagePageNumber = 1,
pageCounter = 0,
placedImage,
insertionPoint = textThing;
insertionPoint.showText();
while (true) {
app.pdfPlacePreferences.pageNumber = firstImagePageNumber + pageCounter;
placedImage = insertionPoint.place(/* file */ pdf, /* showingOptions */ false, /* autoflowing */ false)[0];
if (frameFunction)
insertionPoint = frameFunction(placedImage.parent);
if (!insertionPoint)
insertionPoint = placedImage.parent.parent.insertionPoints[-1];
if (
pageCounter > 0
&& placedImage.pdfAttributes.pageNumber == firstImagePageNumber
) {
placedImage.parent.parent.remove();
break;
};
pageCounter++;
}
};
/**
* Shows open file dialog and
* filters for file extension.
* @author m1b
* @version 2023-08-17
* @param {String} [fileExtension] - the file extension to look for (default: '').
* @param {Boolean} [multiselect] - whether to allow multiple file selections (default: false).
* @param {String} [path] - starting path for the dialog.
* @returns {File}
*/
function chooseFile(fileExtension, multiselect, path) {
fileExtension == fileExtension.replace('.', '') || '';
multiselect = multiselect === true;
var fsFilter;
if ($.os.match("Windows")) {
fsFilter = "*." + fileExtension;
}
else {
var regex = RegExp('\.' + fileExtension + '$', 'i');
fsFilter = function (f) { return (regex.test(decodeURI(f.name)) || f.constructor.name == 'Folder') };
};
var f;
if (File(path).exists)
// start the dialog from path
f = File(path).openDlg("Choose file: " + fileExtension, fsFilter, multiselect);
else
// no start location specified
f = File.openDialog("Choose file: " + fileExtension, fsFilter, multiselect);
return f;
};