I use a jxs script than can import all pages from one pdf, into one photoshop document. But I can't find how to import all pictures without text (Work with option 2 if I do it manually). It's possible ? How ?
Thank for your help.
Code: Select all
var idopen = stringIDToTypeID( "open" );
var desc227 = new ActionDescriptor();
var idas = stringIDToTypeID( "as" );
var desc228 = new ActionDescriptor();
var idsuppressWarnings = stringIDToTypeID( "suppressWarnings" );
desc228.putBoolean( idsuppressWarnings, true );
var idreverse = stringIDToTypeID( "reverse" );
desc228.putBoolean( idreverse, true );
var idselection = stringIDToTypeID( "selection" );
var idpdfSelection = stringIDToTypeID( "pdfSelection" );
var idimage = stringIDToTypeID( "image" );
desc228.putEnumerated( idselection, idpdfSelection, idimage );
var idpageNumber = stringIDToTypeID( "pageNumber" );
desc228.putInteger( idpageNumber, 1 ); // The image to extract
var idPDFGenericFormat = stringIDToTypeID( "PDFGenericFormat" );
desc227.putObject( idas, idPDFGenericFormat, desc228 );
var idnull = stringIDToTypeID( "null" );
desc227.putPath( idnull, new File( "~/Desktop/my-pdf-file.pdf" ) ); // The path to the file
executeAction( idopen, desc227, DialogModes.NO );
Code: Select all
#target photoshop
// Function to open a page from PDF
function openPDFPage(pdfFilePath, pageNumber) {
var idopen = stringIDToTypeID("open");
var desc227 = new ActionDescriptor();
var idas = stringIDToTypeID("as");
var desc228 = new ActionDescriptor();
var idsuppressWarnings = stringIDToTypeID("suppressWarnings");
desc228.putBoolean(idsuppressWarnings, true);
var idreverse = stringIDToTypeID("reverse");
desc228.putBoolean(idreverse, true);
var idselection = stringIDToTypeID("selection");
var idpdfSelection = stringIDToTypeID("pdfSelection");
var idimage = stringIDToTypeID("image");
desc228.putEnumerated(idselection, idpdfSelection, idimage);
var idpageNumber = stringIDToTypeID("pageNumber");
desc228.putInteger(idpageNumber, pageNumber);
var idPDFGenericFormat = stringIDToTypeID("PDFGenericFormat");
desc227.putObject(idas, idPDFGenericFormat, desc228);
desc227.putPath(stringIDToTypeID("null"), new File(pdfFilePath));
try {
executeAction(idopen, desc227, DialogModes.NO);
} catch (e) {
//Do nothing if there is an error when opening the page
// You can add a log message here if necessary
return false; // show that the opening failed
}
return true; // show that the opening success
}
//Function to save image as TIFF
function saveAsTIFF(saveFolderPath, pageNumber) {
var tiffFileName = "page-" + pageNumber + ".tif";
var saveFolder = new Folder(saveFolderPath);
if (!saveFolder.exists) {
saveFolder.create();
}
var tiffFile = new File(saveFolderPath + "/" + tiffFileName);
var tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.imageCompression = TIFFEncoding.NONE; // chose the compressor type
try {
activeDocument.saveAs(tiffFile, tiffSaveOptions, true, Extension.LOWERCASE);
} catch (e) {
// Do nothing if there is an error when save the page
// You can add a log message here if necessary
return false; // show that the save failed
}
// Close the document without saving changes
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
return true; // show that the save success
}
// Specify the path of the PDF file
var pdfFilePath = "YourFile.pdf";
// Specify the backup folder
var saveFolderPath = "YourFolder/";
// Number of pages in PDF (you should adjust this based on the number of pages(images option 2) in your PDF)
var totalPages = 230;
// Loop to open and save each page
for (var page = 1; page <= totalPages; page++) {
if (openPDFPage(pdfFilePath, page)) {
saveAsTIFF(saveFolderPath, page);
}
}
Code: Select all
/*
Save raster images from the selected PDF as TIFF files.jsx
Based on:
https://www.ps-scripts.com/viewtopic.php?p=172190#p172190
*/
#target photoshop
(function () {
// Specify the path of the PDF file
var pdfFilePath = File.openDialog("Select the PDF file:");
if (pdfFilePath === null) {
//alert('Script cancelled!');
return;
}
// Specify the save folder
var saveFolderPath = Folder.selectDialog("Select the save folder:");
if (saveFolderPath === null) {
//alert('Script cancelled!');
return;
}
// Loop the input prompt until a number is entered
var theInput;
while (isNaN(theInput = prompt("Enter the number of images to extract:", "3")));
if (theInput === null) {
//alert('Script cancelled!');
return;
}
var totalPages = parseInt(theInput);
// Set the file saving counter
var counter = 0;
// Loop to open and save each page
for (var page = 1; page <= totalPages; page++) {
if (openPDFPage(pdfFilePath, page)) {
saveAsTIFF(saveFolderPath, page);
}
// Increment the counter
counter++;
}
alert('Script completed!' + '\r' + counter + ' TIFF files saved to:' + '\r' + saveFolderPath.fsName);
// Functions
function openPDFPage(pdfFilePath, pageNumber) {
var idopen = stringIDToTypeID("open");
var desc227 = new ActionDescriptor();
var idas = stringIDToTypeID("as");
var desc228 = new ActionDescriptor();
var idsuppressWarnings = stringIDToTypeID("suppressWarnings");
desc228.putBoolean(idsuppressWarnings, true);
var idreverse = stringIDToTypeID("reverse");
desc228.putBoolean(idreverse, true);
var idselection = stringIDToTypeID("selection");
var idpdfSelection = stringIDToTypeID("pdfSelection");
var idimage = stringIDToTypeID("image");
desc228.putEnumerated(idselection, idpdfSelection, idimage);
var idpageNumber = stringIDToTypeID("pageNumber");
desc228.putInteger(idpageNumber, pageNumber);
var idPDFGenericFormat = stringIDToTypeID("PDFGenericFormat");
desc227.putObject(idas, idPDFGenericFormat, desc228);
desc227.putPath(stringIDToTypeID("null"), new File(pdfFilePath));
try {
executeAction(idopen, desc227, DialogModes.NO);
} catch (e) {
//Do nothing if there is an error when opening the page
// You can add a log message here if necessary
return false; // show that the opening failed
}
return true; // show that the opening success
}
function saveAsTIFF(saveFolderPath, pageNumber) {
var tiffFileName = pdfFilePath.name.replace(/\.[^\.]+$/, '') + "_image-" + pageNumber + ".tif";
var saveFolder = new Folder(saveFolderPath);
if (!saveFolder.exists) {
saveFolder.create();
}
var tiffFile = new File(saveFolderPath + "/" + tiffFileName);
var tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.imageCompression = TIFFEncoding.NONE; // TIFFLZW | TIFFZIP | JPEG
/*
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.byteOrder = ByteOrder.IBM;
tiffSaveOptions.transparency = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.layerCompression = LayerCompression.ZIP;
tiffSaveOptions.interleaveChannels = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.annotations = true;
tiffSaveOptions.spotColors = true;
tiffSaveOptions.saveImagePyramid = false;
*/
try {
activeDocument.saveAs(tiffFile, tiffSaveOptions, true, Extension.LOWERCASE);
} catch (e) {
// Do nothing if there is an error when save the page
// You can add a log message here if necessary
return false; // show that the save failed
}
// Close the document without saving changes
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
return true; // show that the save success
}
}());