Skip to main content
Magnetik85
Known Participant
February 21, 2023
Answered

Automatic PDF export

  • February 21, 2023
  • 1 reply
  • 1488 views

Hi community,

 

I would like your opinion on a script for automatic saving in pdf format.

 

to explain my request, I have a document with two layers "Text" and "Background" and I would like to know if a script already exists that could allow me to export a file per sub-layer contained in "Background" while leaving the "Text" layer active and visible on all my documents so that it can save me in pdf format one file per "Background" layer

 

Thank you in advance for your assistance

This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

Try the following version

function main() {
    var _doc = app.activeDocument;
    var _backgroundLayer = _doc.layers['Background'];
    var _pageItems = _backgroundLayer.pageItems;

    var pdfOptions = new PDFSaveOptions();
    pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
    pdfOptions.generateThumbnails = true;
    pdfOptions.preserveEditability = false;
    pdfOptions.preset = "[Smallest File Size]";

    for (var s = 0; s < _pageItems.length; s++) {
        hideItems(_backgroundLayer);
        _pageItems[s].hidden = false;
        var pdfFile = new File(_doc.path + "/" + _pageItems[s].name + '.pdf');
        _doc.saveAs(pdfFile, pdfOptions);

    }
}

function hideItems(_backgroundLayer) {
    for (var s = 0; s < _backgroundLayer.pageItems.length; s++) {
        _backgroundLayer.pageItems[s].hidden = true;
    }
}

main();

 

Adding more links:

https://github.com/mericson/illustrator-scripts/blob/master/MultiExporter.jsx

1 reply

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
February 21, 2023

Hi,

Try the following version

function main() {
    var _doc = app.activeDocument;
    var _backgroundLayer = _doc.layers['Background'];
    var _pageItems = _backgroundLayer.pageItems;

    var pdfOptions = new PDFSaveOptions();
    pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
    pdfOptions.generateThumbnails = true;
    pdfOptions.preserveEditability = false;
    pdfOptions.preset = "[Smallest File Size]";

    for (var s = 0; s < _pageItems.length; s++) {
        hideItems(_backgroundLayer);
        _pageItems[s].hidden = false;
        var pdfFile = new File(_doc.path + "/" + _pageItems[s].name + '.pdf');
        _doc.saveAs(pdfFile, pdfOptions);

    }
}

function hideItems(_backgroundLayer) {
    for (var s = 0; s < _backgroundLayer.pageItems.length; s++) {
        _backgroundLayer.pageItems[s].hidden = true;
    }
}

main();

 

Adding more links:

https://github.com/mericson/illustrator-scripts/blob/master/MultiExporter.jsx

Best regards
Magnetik85
Known Participant
February 21, 2023

Hi @Charu Rajput  and thanks for your help.

 

I just tested this script and nothing happens. I had no error message or exported pdf files. Have you on your side with my file been able to export the pdf files as I wish?

Charu Rajput
Community Expert
Community Expert
February 21, 2023

Hi, @Magnetik85 ,

Yes, I am able to export. I have used attached document background.eps file and PDF file with name BG1.pdf, BG2.pdf and BG3. pdg created at the same path where background.eps file exists.

Best regards