Alfresco PDF-Toolkit Javascript - pdf

i've recently installed Alfresco's PDF-Toolkit. My actual intension is to use it in a Javascript manner. This is because the value i need or want to watermark will be based on the Document's Property/Aspect.
i failed to find any tutorial or guide regarding this issue. if anyone can please give me a walkthrough, i'd really appreciate it.
my current script looks like this:
var watermark_action = actions.create("pdf-watermark");
watermark_action.parameters["destination-folder"] = ????;
watermark_action.parameters["watermark-type"] = "text";
watermark_action.parameters["watermark-text"] = aspect.ajie;
watermark_action.parameters["watermark-pages"] = "all";
watermark_action.parameters["watermark-depth"] = "over";
watermark_action.parameters["position"] = "center";
watermark_action.execute(document);
NOTE: i actually found one, the problem is that this one is an image watermark and what i want or need is a text watermark. also i need the script to save the watermarked copy to the same directory which i believe is not what the guide seems to do.
the last thing i need is the value for the destination-folder parameter. i really have no clue on how or what i'll place here just to save the pdf to the same folder. hoping to get some guide, tips, and tricks here. thanks

The code should look like this:
var watermark_action = actions.create("pdf-watermark");
watermark_action.parameters["inplace"] = true;
watermark_action.parameters["destination-folder"] = document.parent;
watermark_action.parameters["watermark-type"] = "text";
watermark_action.parameters["watermark-text"] = "Lorem Ipsum";
watermark_action.parameters["watermark-font"] = "Helvetica";
watermark_action.parameters["watermark-size"] = "14";
watermark_action.parameters["page"] = "all";
watermark_action.parameters["watermark-depth"] = "over";
watermark_action.parameters["position"] = "center";
watermark_action.execute(document);
You were missing watermark-font, watermark-size, and page.

Related

PDFBox_Facing issue while extracting a certain image from the top of each page

Recently I had asked THIS QUESTION to be able to save all the images present in a PDF file on the File System and I was able to save the images successfully.
I tested my code on a lot of pdf files and it ran just fine. But, today I came accross THIS pdf file from where it is not able to extract some images(attached below).
Can anyone please tell me what else I can do to extract these images? Is it even possible to extract them? Are they really images or something else? I would really appreciate the help.
My code(Please ignore the hardcoding as I am still testing this out):
function fn_getAllImages()
{
var strPdf = "C:\\Users\\a614923\\Desktop\\haka\\Work\\2017\\10. October\\31\\test.PDF";
var strout = "C:\\Users\\a614923\\Desktop\\haka\\Work\\2017\\10. October\\31\\Newfolder\\img"
intPage = 2; //for the 2nd page(the image is present in the 2nd page)
var objPdf = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3(strPdf);
var objPage = objPdf.getDocumentCatalog().getAllPages().get(intPage-1);
var objImages = objPage.getResources().getXObjects().values().toArray();
var objImage, objImgBuffer, objImageFile;
for(var i=0; i<objImages.length; i++)
{
objImage = objImages.items(i);
Log.Message(objImage.toString());
if(aqString.Find(objImage.toString(),"PDXObjectForm",0,false)>0)
{
continue;
}
else
{
objImage.write2file_2(strout+i);
//objImgBuffer = objImage.getRGBImage();
//objImageFile = JavaClasses.java_io.File.newInstance(strout+i+".png");
//JavaClasses.javax_imageio.ImageIO.write(objImgBuffer,"png",objImageFile);
}
}
}
The image in the PDF file which I want to save(the one inside the red box below):

How to clean existing properties and replace with metadata template on Photoshop (scripting)?

While creating a script that would automate all the different tasks I do when I start working on a new picture on Photoshop, I encountered the following problem.
Manually, I would Ctrl + Alt + Shift + I, click on the template I want and choose the option "Clear existing properties and replace with template properties".
I can't find the way to do precisely this. The best thing I managed to find is something like this :
app.activeDocument.info.author = "test";
app.activeDocument.info.caption = "";
app.activeDocument.info.captionWriter = "";
app.activeDocument.info.headline = "";
app.activeDocument.info.instructions = "";
app.activeDocument.info.keywords = "";
app.activeDocument.info.authorPosition = "";
app.activeDocument.info.credit = "";
app.activeDocument.info.source = "";
app.activeDocument.info.category = "";
app.activeDocument.info.supplementalCategories = "";
app.activeDocument.info.title = "";
// etc.
And it actually doesn't really work like the "Clear existing properties and replace with template properties".
I didn't find anything on the Photoshop scripting guide, nor on the internet. Any help would be greatly appreciated !
What I think is the problem is Photoshop separates file-metadata from its activeDocument-metadata. What you see in "File info..." (via Ctrl+Alt+Shift+I) is supposed to represent the file in the filesystem, which metadata is embedded in.
There are several scripting guides to Photoshop scripting. I think the one relevant for you would be "Javascript Tools Guide", specifically the chapter 10 "Scripting Access to XMP Metadata".
Is it important for you to set up the metadata already when creating a new picture? If not, you may want to look at a solution using a customized export script.
It customizes XMP-metadata upon exporting like
Create a basic metadata object:
var meta = new XMPMeta();
Provide a namespaceURI (see XMP specs) known to photoshop along with tag name, and value:
meta.setProperty(XMPConst.NS_XMP, "CreatorTool", app.version);
Save the image temporarily (using other script):
var imgFile = new File(fileName);
saveImage(fileName);
Finish saving by adding the metadata-object:
var metaFile = new XMPFile(imgFile.fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
if (metaFile.canPutXMP(meta)) { metaFile.putXMP(meta); }
metaFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
Doing it this way also erases any existing or default metadata.

AS2 Attaching a Bitmap to Dynamic created Variables

I'm stuck with this problem and simply cannot get it solved, sorry if there was another post about this already but I couldn't find it as well.
On to the problem then: I'm trying to make a simple function capable of initializing and updating bitmaps, and a few other variables I haven't thought of yet, when needed.
I created on the stage some MovieClips called slot0, slot1, slot2 etc... inside another MovieClip called ButtonRootPannel in order to have a visual of where I'll be putting the images without having to guess numbers in the code.
Together with those I set up this code:
var buttons_rootArray:Array = new Array;
for(var i=0;i<=11;i++){
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = eval("_root.ButtonRootPannel.slot"+i)._x;
this["slot"+i]._y = eval("_root.ButtonRootPannel.slot"+i)._y;
this["slot"+i]._width = eval("_root.ButtonRootPannel.slot"+i)._width;
this["slot"+i]._height = eval("_root.ButtonRootPannel.slot"+i)._height;
buttons_rootArray.push(this["slot"+i]);
}
UpdateButtonsSlot(0,"BuildButton");
UpdateButtonsSlot(1,"CancelButton");
function UpdateButtonsSlot(slot:Number, newImage:String):Void{
var tempData:BitmapData = BitmapData.loadBitmap(newImage);
var tempClip:MovieClip = eval(buttons_rootArray[slot]);
//buttons_rootArray[slot].unloadMovie();
//buttons_rootArray[slot].clear();
tempClip.attachBitmap(tempData,this.getNextHighestDepth(),"auto",true);
}
Anyone knows what I might be doing wrong?
Thanks in advance.
Well, problem solved, this now seems to be working for some strange reason:
for(var i=0;i<=11;i++){
var currentMC = eval("_root.ButtonRootPannel.slot"+i);
this["slot"+i] = this.ButtonRootPannel.createEmptyMovieClip("slot"+i, i);
this["slot"+i].customState = "Inactive"; //Active, Inactive or Unavaiable
this["slot"+i]._x = currentMC._x;
this["slot"+i]._y = currentMC._y;
//this["slot"+i]._width = currentMC._width;
//this["slot"+i]._height = currentMC._height;
buttons_rootArray.push(this["slot"+i]);
}
Only those commented lines makes the MovieClip disappear if I uncomment them. Will just leave them out then and problem solved.

Clearing FlipTileData BackBackgroundImage

I have a periodic task that updates my live tile. Basically it looks like this:
var tileData = new FlipTileData()
{
BackgroundImage = mediumFrontUrl,
BackBackgroundImage = mediumBackUrl,
WideBackgroundImage = wideFrontUrl,
WideBackBackgroundImage = wideBackUrl
};
ShellTile primaryTile = ShellTile.ActiveTiles.First();
if (primaryTile != null)
{
primaryTile.Update(tileData);
}
There are certain occasions where I would like to not display the BackBackgroundImage and WideBackBackgroundImage. How do I clear the values? Simply setting things to null doesn't work (it just keeps what was there previously). According to the docs if I use XAML to create the live tile I can set Action="Clear". How do I set that in code?
You can clear the property for each Tile property.
For BackBackgroundImaga it's Empty URI:
BackBackgroundImage = new Uri("", UriKind.Relative)
More info on msdn page Tiles Overview for Windows Phone:
http://msdn.microsoft.com/en-us/library/hh202948%28v=vs.92%29.aspx
Hope this help
Best regards
And Zik
Just one trick.
Playing with WideBackContent and putting my own image (I have a lot of more possibilities with this apporach) I have problem with resetting WideBackContent. The thing that help me is not WideBackContent ="", then WideBackContent = " "
So, one empty space solved my problem.
Best regards

CKEditor custom select menu

I am trying to add my own custom select menu to the new CKEditor. The API is a little confusing so I am unsure how to get this working. I am using the ui dialog function, but really not sure how to get it working.
So far I have:
CKEDITOR.ui.dialog.select(dialogObj, elementDefinition, htmlList);
Anyone hav ideas on how to actually get a custom select to work?
I am trying understand this API: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.dialog.select.html
Try this Code,
It's something like creating the element dynamically just like in javascript, the SELECT control will be created whenever you are pressing Enter key...
var editor1 = CKEDITOR.replace('editor');
CKEDITOR.instances["editor"].on("instanceReady" , function(){
var e = this.document;
this.document.on("keyup", function(event){
domEvent = event.data;
key = domEvent.getKey();
switch(key){
case 13:
e = CKEDITOR.instances.editor.document;
b = e.getBody();
s = e.createElement('select');
o = e.createElement('option');
o.appendHtml("hi");
s.append(o);
o = e.createElement('option');
o.appendHtml("hello");
s.append(o);
b.append(s);
s.focus();
break;
default:
}
});
});
Why don't you check the _source folder?
Go into the plugins directory and pick a plugin which shows dropdown selects e.g. stylescombo. The code may shed some light into it. Create a copy of the folder and start modifying the code top down and you'll have your select in no time.
Cheers,
m^e