# Document.save(\<new entry\>) does not work (at least for PNG)

**URL:** <https://forums.creativeclouddeveloper.com/t/document-save-new-entry-does-not-work-at-least-for-png/3270>\
**Category:** UXP Plugin API\
**Created:** [July 10, 2021, 4:55pm UTC](https://forums.creativeclouddeveloper.com/t/document-save-new-entry-does-not-work-at-least-for-png/3270 "2021-07-10T16:55:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TestUser](https://avatars.discourse-cdn.com/v4/letter/t/e495f1/32.png) [@TestUser](https://forums.creativeclouddeveloper.com/u/TestUser)\
**Post date:** [July 10, 2021, 4:55pm UTC](https://forums.creativeclouddeveloper.com/t/document-save-new-entry-does-not-work-at-least-for-png/3270/1 "2021-07-10T16:55:44Z")

</div>

Hello! Despite it’s weekend I really hope someone is available to respond and help him me to overcome/workaround this urgent problem.

I need to save the activeDocument (PSD, which is saved on local disk) as PNG multiple times (I make different layers visible/invisible).

I tried the code below without success:

```auto
var output_file = await out_folder.createFile("test.png");
await psd_doc_ref.save(output_file);

```

Then I read in some ticket that the file should be unsaved, it was clarifed by @kerrishotts and it was suggested to create a new document, then copy the layers into it.  
I tried that way but unfortunately it makes problems in my case as smart object contents were not being copied automatically.

I tried to duplicate the document (to create an unsaved doc) with the code below:

```auto
const result = await batchPlay(
    [
      {
          "_obj": "duplicate",
          "_target": [
            {
                "_ref": "document",
                "_enum": "ordinal",
                "_value": "first"
            }
          ],
          "documentID": doc_ref._id,
          "_isCommand": true,
          "_options": {
            "dialogOptions": "dontDisplay"
          }
      }
    ],{
      "synchronousExecution": false,
      "modalBehavior": "fail"
    });
}

```

It seems the duplication works perfect, then I am running this (no success, no error):

```auto
while (app.activeDocument._id === psd_doc_ref._id) {
  await sleep(500);
}
await app.activeDocument.save(output_file);

```

Please help to solve the problem it’s very urgent. @Jarda

P. S. I use PS 22.4.2 Release

---

<div class="post-metadata">

**Author:** ![TestUser](https://avatars.discourse-cdn.com/v4/letter/t/e495f1/32.png) [@TestUser](https://forums.creativeclouddeveloper.com/u/TestUser)\
**Post date:** [July 10, 2021, 4:59pm UTC](https://forums.creativeclouddeveloper.com/t/document-save-new-entry-does-not-work-at-least-for-png/3270/2 "2021-07-10T16:59:01Z")

</div>

Please note that ironically this function works without any problem - PNG file is created, unlike the above mentioned case when I don’t get any error but the file is not saved.

```auto
async function save_ai_label_file(label_file, out_folder, file_name) {
  try {
    var ai_doc_ref = await app.open(label_file);
    var output_file = await out_folder.createFile(file_name);
    await ai_doc_ref.save(output_file);
    await ai_doc_ref.closeWithoutSaving();
  } catch (err) {
    await error("Saving label AI file as png failed", err.message.toString());
  }
}

```

@DavideBarranca @simonhenke

---

<div class="post-metadata">

**Author:** ![TestUser](https://avatars.discourse-cdn.com/v4/letter/t/e495f1/32.png) [@TestUser](https://forums.creativeclouddeveloper.com/u/TestUser)\
**Post date:** [July 11, 2021, 4:46am UTC](https://forums.creativeclouddeveloper.com/t/document-save-new-entry-does-not-work-at-least-for-png/3270/3 "2021-07-11T04:46:33Z")

</div>

My apologies, actually it works, just my document color mode was CMYK (instead of RGB).
