Exporting pages as png with InDesign Server - indesign-server

Is there a way to export a page as a png with InDesign server?
The following code works for a text frame. How do I do the same for the complete page contents?
var theDocument = app.documents.add();
var thePage = theDocument.pages[0];
var theTextFrame = thePage.textFrames.add();
theTextFrame.geometricBounds = [5,5,40,40];
theTextFrame.contents = TextFrameContents.placeholderText;
theTextFrame.exportFile(ExportFormat.pngFormat, File("c:\\test.png"));

if you can export as JPG, something like this should work:
//set which page you want to export:
app.jpegExportPreferences.pageString='1';
//export that page from the document:
var myFile = new File('C:/test.jpg');
theDocument.exportFile(ExportFormat.JPG, myFile);
I'm not sure if setting the jpegExportPreferences.pageString would still work or not with exporting as a PNG, but you might be able to test that. Hopefully this at least gets you on the right track!
Note that if you want to export as a PNG, use this export format:
ExportFormat.PNG_Format
EDIT:
Looking at this article from the Adobe Forums, it states that InDesign can export as PNG but doesn't include any options, so it has limitations other than specifying the format. So, if the above code example won't help, maybe try something like this:
app.activeDocument.selection[0].exportFile(ExportFormat.PNG_FORMAT, File(new File("c:\\test.png")));
Hope this helps!

Related

AWS S3 - Display image in HTML

I can't seem to figure out why my image which lives in AWS is not displaying in my HTML. I'ts simply displaying a white image with the small icon in the top right noting there is no image found (And no alt attribute).
If this is the URL to the image:
https://s3.amazonaws.com/mng-moment/test/PA/40.0103647%2C-75.2625353_1492304397972.jpg
Then shouldn't the img src be
https://s3.amazonaws.com/mng-moment/test/PA/40.0103647,-75.2625353_1492304397972.jpg
I have also tried to match the URL exactly. I tried to print out in the HTML exactly what is in the img src. I tried to take out the extension along with other miscellaneous things.
I have done some research on this and it seems like I'm doing it correctly, although clearly i'm not. Any idea what is wrong here?
Thanks for any and all help.
EDIT:
This is the code where I create the object to upload:
var blob = new Blob([dataURItoBlob(picture)], {type: 'image/jpg'});
var file = new File([blob], moment.location);
return core.upload(moment.key, moment);
I figured this out. It was this thing:
var blob = new Blob([dataURItoBlob(picture)], {type: 'image/jpg'});
var file = new File([blob], moment.location);
return core.upload(moment.key, moment);
I was foolishly not passing in the file into my upload function even though I went through the trouble of creating it. It must've been a refactoring mistake I made.

How to show a preview of a file on a panel in a UiApp using GAS

I want to display a preview of a(ny) file on a panel in a UiApp using GAS.
I'm using DriveApp, not DocsList.
Using file.getThumbnail() or file.getAs(mimeType) I can get a Blob of any file.
Documentation at https://developers.google.com/apps-script/reference/drive/file#getThumbnail%28%29 states that (at least) I can get those blobs being converted to 'application/pdf'.
I don't know how to display those blobs (or pdf-files as such) on a panel.
Can anybody tell me what I should do?
You cant display them inside the panel because you would need to iframe it, which isnt possible even with htmlServices.
Use an anchor to open the link on another page. You can link to the original file.
You can convert a spreadsheet with a pdf but i don"t know with any File.
I use this code
var pdf = DocsList.getFileById(newSpreadsheet.getId()).getAs('application/pdf').getBytes();
var attach = {fileName:'Weekly Status.pdf',content:pdf, mimeType:'application/pdf'};
You cna test It with this source if he can help you .
https://gist.github.com/ixhd/3660885

HTML/ display images in a HTML page

I created a HTML page.
Now, I try to display all the pictures that are in a specific folder (/folder1) in this HTML page (Note: I don't know the names of these images).
I try to create a loop, which read all this images, and display it in this HTML.
There is an easy way to do that?
You are looking for something which HTML cannot do. You are going to need some sort of backend language, whether that be Rails, PHP, Python, or something else doesn't really matter.
HTML is and always will be only a Markup Language.
Here is a similar post which has code that might help you:
How To Display All Images in Folder
With php you can use function scandir() to retrieve all the files in a directory, and save them as an array.
Then iterate over that array and display any image with something like:
echo '<img src="path/to/folder1/'$files_array[i]'">
where $files_array contains the names of every image file in that directory.
if your images are stored in a server you can read the directory and get the image name them send to the font end.
if you are work in a local file system such as
/dir/index.html
/dir/images/
/dir/images/xxx.png
/dir/images/aaa.png
/dir/images/other image.png
you can rename all images in batch to 1.png 2.png 3.png ...and so on then use javascript in html to
generate the image
var body = document.getElementsByTagName("body")[0];
for (var i = 0; i < 100; ++i) {
var img = document.createElement("img");
img.src = "images/" + i + ".png";
body.appendChild(img);
}

How do I export InlineDrawing as an image in Document?

I have an InlineDrawing in my document, which I can access as an element, and get it as "InlineDrawing".. I also know how to access an InlineImage and write it to a file as bytes. How would I export an InlineDrawing as an image of some kind, the formats available from the UI are svg, pdf, jpeg and png.
Google Apps script cannot do such image conversions for now... You could ask for an enhancement on the issue tracker
You could copy the paragraph into a new document. Then you can convert the new document to pdf. Something like this:
var temporaryFileName = Math.random().toString(36);
var doc = DocumentApp.create(temporaryFileName);
// Child is the element with the InlineDrawing.
var originalParagraph = child.getParent().copy();
doc.getBody().appendParagraph(originalParagraph);
doc.saveAndClose();
// Save image.
var blob = doc.getAs('application/pdf');
blob.setName("bla.pdf");
folder.createFile(blob);

Using HTML file to output a PDF

So I've got a HTML file, that I am using to send emails, but in some instances I want it simply to use that file to create a PDF of the same template.
I've got it functioning for the most part - it creates the file, runs the evaluations and gets the content, but it doesn't actually render the html. It simply leaves all the html notation in place.
For example, it outputs a pdf but it reads:
Dear Martin, <br />
instead of:
Dear Martin
How do I make sure it renders the HTML so that the PDF is laid out correctly, and doesn't have the html code noted in the text?
Here's the code:
var docName = "test";
var htmlBody = HtmlService.createHtmlOutput(template.evaluate().getContent()).getContent()
var doc = DocumentApp.create(docName);
doc.appendParagraph(htmlBody);
doc.saveAndClose();
DocsList.createFile(doc.getAs('application/pdf')).rename(docName);
You can use your existing HTML as a blob, and convert it to PDF like this:
var htmlBody = HtmlService.createHtmlOutputFromFile('my_file_within_script_project.html').getContent();
var blob = Utilities.newBlob(htmlBody, 'text/html').getAs('application/pdf').setName('my_output_in_drive.pdf');
DriveApp.createFile(blob);
The best option when you want to create a PDF from a template is to use Google Docs directly so that no formatting is lost and also avoid the problem you are facing.
Why don't you just create your template directly in Google Docs. Have some placeholders such as {name} instead of the actual name. Instead of using template.evaluate(), you can do a find and replace in the doc.