Setting a font on a PSD text item in javascript?
Hi there,
I'm new to photoshop scripting and am having a bit of trouble editing a text layer in Photoshop using javascript.
I have a few PSD templates in which I'd like to replace text on specific layers with javascript before generating hundreds of animated GIFs. I have placeholder text on the target layers and have been able to replace it with:
"textItemRef.contents = "Hello, world";
however this loses ALL text formatting. Is there a different way to replace existing text keeping sizes/colors/fonts in tact? All examples I can find create new layers needing all the attributes. I've tried assigning a paragraph style to the placeholder text using Photoshop cc 2014 stylesheets but that doesn't retain styles when the text is replaced, either.
I also can't find mention of TEXT STYLESHEETS in the scripting guides or photoshop DOM references, presumably because they're so new? If anyone has been able to assign TEXT styles, what is the syntax? Or is there one for clearing overrides if that's possible?
If the only way IS to style everything one attribute at a time, I am having problems with the font attribute. var myFont = app.fonts.getByName("Arial"); does not seem to work.
A follow-up for anyone experiencing this dropped style on a layer when importing new content... it turns out using paragraph styles AT ALL on a layer will make that layer lose its style when new text is imported with javascript (for some reason photoshop then incorrectly assumes you want to reset the formatting of the new layer to the DEFAULT paragraph style). This is the complete opposite of the results you'd want to use stylesheets to attain in the first place. But, starting with a layer that has only been manually styled with the font menus and character menu items will hold its attributes when importing new text.
I've recorded and copied below the ActionManager script happening behind the scenes when importing text, and all Photoshop does with the stylesheets because I've used a paragraph style:
// =======================================================
var idAdobeScriptAutomationScripts = stringIDToTypeID( "AdobeScriptAutomation Scripts" );
var desc459 = new ActionDescriptor();
var idjsCt = charIDToTypeID( "jsCt" );
desc459.putPath( idjsCt, new File( "/Applications/Adobe Photoshop CC 2014/Presets/Scripts/one-text-line-to-hdln.jsx" ) );
var idjsMs = charIDToTypeID( "jsMs" );
desc459.putString( idjsMs, """this is text""" );
executeAction( idAdobeScriptAutomationScripts, desc459, DialogModes.NO );
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc460 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref36 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );
ref36.putProperty( idPrpr, idparagraphStyle );
var idTxLr = charIDToTypeID( "TxLr" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref36.putEnumerated( idTxLr, idOrdn, idTrgt );
desc460.putReference( idnull, ref36 );
var idT = charIDToTypeID( "T " );
var desc461 = new ActionDescriptor();
var idstyleSheetName = stringIDToTypeID( "styleSheetName" );
desc461.putString( idstyleSheetName, """Basic Paragraph""" );
var idtypeStyleOperationType = stringIDToTypeID( "typeStyleOperationType" );
desc461.putInteger( idtypeStyleOperationType, 1 );
var idparagraphStyle = stringIDToTypeID( "paragraphStyle" );
desc460.putObject( idT, idparagraphStyle, desc461 );
executeAction( idsetd, desc460, DialogModes.NO );
Now the same actions with no style applied to the layer getting new text.
Similar Messages
-
How to set cursor at the end of text item?
If I use Go_Item, it will go to the item but select the whole content of the item(displayed in blue color). How can I set the cursor at the end of the text item and not to make the content selected?
You may be seeing <Bug:1186653> which is fixed in 6.0.5.36 however if running on windows awprkaoutnd may be to use d2kwutil.
Place the following code within a when-new-item-instance trigger on the
item(s) you wish to disable highlighting:
DECLARE
v_handle pls_integer;
BEGIN
win_api_shell.sendkeys(V_HANDLE,'{home}',FALSE);
END;
The above code will result in no highlighting occurring and the cursor will be
placed on the first character of the item. If you wish the cursor to appear at
the end of the item, replace the word home to end. For more information,
please refer to the d2kwutil documentation.
Note that this solution will only work on windows in a client server environment.
For a web solution you will have to create a java bean that will perform the
necessary functionality.
Regards
Grant Ronald -
Set diferent font in a paragraph text.
In xml file,there is the following element:
When I open the xml file in FrameMaker,the font of string "ZCCC2.1" should Times new roman,the font of string "ADCCCCCCCC" should another font.
In EDD,title element is a framemaker element.How Can I deal with the problem when I open the xml file?Bummer! Thanks for letting me know, so I can stop banging my head against the wall trying to figure it out.
Your approach with the dummy font is clever, but won't help me in this case. I'm trying to automate the "Find Font" process for a group of users. They've used a particular group of fonts for thousands of files, and are switching to a different family of fonts. They want to have ONLY the new family installed. So I wanted to create a script they could run the first time they open each file that would find each old font and replace it with the new font. My script works great for all the text in the file, but not the Paragraph and Character styles.
Can anyone think of another approach? I'm out of ideas on this one. -
Different fonts in same text item....
Hi Everyone,
We have a requirement that we should use more than one font in the same text item. We have shortcut to toggle between the fonts (if you are familiar its NUDI used for Kannada Font). So we should make it possible that they can edit both kannada and english in the same field. And, after toggling between the fonts, previously added data should not change.
Thanks in advance,
YathishFor any fonts you will use you OAS must support it, but as I said in my previous post, you cannot have two different types of fonts in the same text item natively.
It may be possible if you use a PJC.
Regards,
Tony -
How to set custom font family in qml label in black berry 10 os
how to set custom font family in label text qml in black berry 10 OS
AFAIK, this is not the correct way to set the image location.
We call the working directory as context, so inside the context root along with WEB-INF, maintain a folder with name img and put all the images in that directory.
You can use either .\<image_folder> or the optimum way would be (if you are using JSPs) to use getContext() method and traverse accordingly.
FYI,,, using getContext() will give you context root directory, from there it is as simple as accessing any other folder.
Hope this answers your question.
Cheers,
Jeets. -
Set value of a display only item using javascript
I was trying to find an answer in the forum but my searches gave me no results. How do
I set a value of a display only item using javascript (ajax)?
Denes Kubicek
http://deneskubicek.blogspot.com/
http://htmldb.oracle.com/pls/otn/f?p=31517:1
-------------------------------------------------------------------Vikas,
Thanks for a fast responding. The type is Saves State. However, I tried to set the value
of a display only item using:
<script>
function f_setDisplayOnly ()
{$x('P80_X').parentNode.childNodes[4].nodeValue = 1;
</script>without a result (or error). What am I doing wrong?
Denes Kubicek
http://deneskubicek.blogspot.com/
http://htmldb.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
How to set the desired font to the selected text in textframe?
Hi,
I want to change the font(let's say Times New Roman) of selected text in textframe when I click on menu-item of my plug-in.
I went through the Adobe Text Engine documentation and tried some code for setting font but failed. I don't see any member function in IFont class to set desired font, so unable to move forward.
plz see the code. I would like to know one more thing that how can we set a particular font for a textframe?
TextRangesRef rangesRef = NULL;
result = sAIDocument->GetTextSelection(&rangesRef);
aisdk::check_ai_error(result);
ITextRanges ranges(rangesRef);
if (ranges.GetSize() > 0)
ITextRange range = ranges.Item(0);
ICharFeatures features = range.GetUniqueLocalCharFeatures();
IFont font; // I don't see any method to put desired font.
// features.SetFont();
Thanks.
D.AFirst, get the font:
AIFontKey fontKey = 0;
AIErr error = sAIFont->FindFont("Times New Roman Regular", kAIAnyFontTechnology, kNativeAIScript, 0, &fontKey);
// do something with error
ATE::FontRef fontRef = 0;
error = sAIFont->FontFromFontKey(fontKey, &fontRef);
// do something with error
ATE::IFont font(fontRef);
Then, apply it like this:
ATE::TextRangeRef textRangeRef = 0;
AIErr error = sAITextFrame->GetATETextRange(handle_to_artwork, &textRangeRef);
// check error
ATE::ITextRange textRange(textRangeRef);
ATE::ICharFeatures charFeatures = textRange.GetUniqueLocalCharFeatures();
charFeatures.SetFont(font);
textRange.ReplaceOrAddLocalCharFeatures(charFeatures);
There are a few other ways to set the text, but you need to understand how character & paragraph styles interact with each other to understand the differneces. This is the most straight forward way to do it though. -
Setting Font for converting multiple text files into PDF using VB 6.0
Dear All,
Am converting multiple text files into PDF using VB6.0. Currently, am unable to control the font face and size for the generated files. Below is the procedure am using for each file;
Public Sub proc_convert_to_PDF(srcFilename As String, destFilename As String)
Dim p_AcroApp As CAcroApp
Dim p_VDoc As CAcroAVDoc
Dim p_DDoc As CAcroPDDoc
Dim IsOk As Boolean
Set p_AcroApp = CreateObject("AcroExch.App")
Set p_VDoc = CreateObject("AcroExch.AVDoc")
Call p_VDoc.Open(srcFilename, "")
Set p_VDoc = p_AcroApp.GetActiveDoc
If p_VDoc.IsValid Then
Set p_DDoc = p_VDoc.GetPDDoc
' Fill in pdf properties.
p_DDoc.SetInfo "Title", Format(Date, "dd-mm-yyy")
p_DDoc.SetInfo "Subject", srcFilename
If p_DDoc.Save(1 Or 4 Or 32, destFilename) <> True Then
MsgBox "Failed to save " & srcFilename
End If
p_DDoc.Close
End If
'Close the PDF
p_VDoc.Close True
p_AcroApp.Exit
'Clear Variables
Set p_DDoc = Nothing
Set p_VDoc = Nothing
Set p_AcroApp = Nothing
End Sub
What I need;
1) to be able to set the font face of the destination file ( destFilename)
2) to be able to set the font size of the destination file ( destFilename)
Am using Adobe Acrobat 7.0 Type Library
Kindly Help.
Thanks in advanceWe didn't say it doesn't work. We said it isn't supported.
There are a number of other ways to make a PDF. The one which would
give the most control is if your application directly printed to GDI,
controlling the font directly. This could print to Adobe PDF.
You could look for an application that gives control of font for
printing.
You could use a text-to-PostScript system and distill the result. You
could even look for a non-Adobe text-to-PDF.
Working in the unsupported and dangerous world you chose, the font
size for text conversion is set (and this is very bad design from
Adobe) in the settings for Create PDF > From Web Page. There is no API
to this.
Aandi Inston -
How to add text in .ai file and set position, font, size and colour
I want to place multiple lines of of text (individually) into .ai file and set size, font, colour and position for each.
Preferably text should have origin in a single point (rather than be framed)
Hope anyone can help me out.
Thank you in advance.Here's what's in the Scripting Reference
Creating and modifying text frames
// Creates a document with text frames displaying path, area and point
// text, changes the content of each frame then deletes the 2nd frame
// create a new document
var docRef = documents.add();
// create 3 new textFrames (area, line, point)
// Area Text
var rectRef = docRef.pathItems.rectangle(700, 50, 100, 100);
var areaTextRef = docRef.textFrames.areaText(rectRef);
areaTextRef.contents = "TextFrame #1";
areaTextRef.selected = true;
// Line Text
var lineRef = docRef.pathItems.add();
lineRef.setEntirePath( Array(Array(200, 700), Array(300, 550) ) );
var pathTextRef = docRef.textFrames.pathText(lineRef);
pathTextRef.contents = "TextFrame #2";
pathTextRef.selected = true;
// Point Text
var pointTextRef = docRef.textFrames.add();
pointTextRef.contents = "TextFrame #3";
pointTextRef.top = 700;
pointTextRef.left = 400;
pointTextRef.selected = true;
redraw();
// count the TextFrames
var iCount = docRef.textFrames.length;
var sText = "There are " + iCount + " TextFrames.\r"
sText += "Changing contents of each TextFrame.";
// change the content of each
docRef.textFrames[0].contents = "Area TextFrame.";
docRef.textFrames[1].contents = "Path TextFrame.";
docRef.textFrames[2].contents = "Point TextFrame.";
redraw();
docRef.textFrames[1].remove();
redraw();
// count again
var iCount = docRef.textFrames.length;
Your are looking stuff with the pointTextRef. -
Font size dependent text item size calculation
Hello there always helping hand !!
I have a requirement like this
1. Depending on the Form Co-ordinate system
2. Depending on the Font name and size of the Text Item
3. For a multiline text item
4. Given the context string to display in it
I want to calculate the optimal width and hight for that text
item.
Please give me sugestion on the calculation formulae and or
pointer to the detailed discussion....
Thanking you in anticipation
Santosh
[email protected]
null>
Naresh Kumar Malik wrote:
> Hi
>
>
>
>
> You can use <h1> HTML tag. Here
> concatenate '<h1>' item_eform_reqno '</h1>' into head.
> wd_context->set_attribute( exporting name = 'EFORM_HEAD' value = head ).
>
>
> Here attribute EFORM_HEAD is bounded to the text view element.
>
> Regards
> Naresh
This should NOT work! The UI elements should safe encode all input values - thereby eliminating the value of any HTML tags. If you system isn't doing this already then it is a bug and if you rely on such a thing it will stop working at some point in the future.
You are basically restricted to different values available via the design parameter. The overall font sizes come from the underlying themes and the client applications (browser or NetWeaver Business Client) that host the Web Dynpro Application. Therefore no direct specification of the font size is possible in order to stay within the controls of theme. If you don't like any of the designs available, you might consider altering the Portal Theme you are using - but that is a rather drastic approach. -
I have a one textframe in which i want to set three different pointsize(font size) for three different text ranges. I have set different tag name for different text ranges . So How can I set different pointsize in the single texmframe.
Please reply me if anyone is aware of it.
Thanks,Jack,
Extending Martti's post, you can create an XSLT that will add an element around the ASD2.1 part when you import the XML file into FrameMaker. Then FrameMaker's EDD can format this added element with a font different from the one used in the content element.
Van -
Set Text Item To SQL Query Result
I am trying to set a text item to a SQL query result. Something like the following:
(I am trying to accomplish this in the SOURCE portion, set to 'SQL Query' source type, of the text item properties)
SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
This only displays as the literal text when the application renders and not the value from the SQL query.
I apologize if this has already been posted but I could not find what I am looking for. I have seen posts that reference a pre-region computation but do not know the exact steps to accomplish the results I want.
Thanks in advance for anyone's time to help me with my issue.
KyleScott,
The literal that displayed (I have fixed it) was the actual SQL statement: SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
I have resolved the issue, using SQL Query as the "Source Type" and Always, replacing any existing value in session state as the "Source Used" for the properties of the item.
What I was trying to accomplish is a search text item that would return the data for that record in a table into other text items, for each column in that record, for update; based on the search text item as a unique SQL query search for that record.
Thank you for your quick reply!
Kyle -
Hi,
I have a text item. I also have an application item.
I want to set this text item with the value of the application item every time the page is redirected.
Is thos possible????
How do I do this?
Plase suggest.
Thanks.
Edited by: machan on Feb 9, 2010 1:03 PMMachan,
You should be able to set the Text item with the value of the Application item if Source Type = "Item (Application or Page Item Name)".
Ittichai -
How i assign chinese font to a text item
Hi,
I have a chinese font and i want assign that in a text box.
how i do that??
plez kindely help me out..Is the chinese font installed in your system? If yes, then it'd come in the drop down menu under the font property of the text box item.
-
Setting the text of a text item
Hi.
I am new to forms. This must be simple! How do you set the contents of a text item programmatically at run time? I want to put the value of a parameter into a text item that appears on my form.
Thanks.In an appropriate trigger (WHEN-NEW-FORM-INSTANCE, perhaps), you can set the value of a field on a block by simply assigning a value to it, thus:
:BLOCK.FIELD := value ;
Remember to make sure the datatypes are compatible by casting if necessary.
Maybe you are looking for
-
How to get the dID of any Content from SS_DATAFILE in Site Studio 10gR4?
Hi, I am trying to get the dID of a Contributor Data File from its dDocName (SS_DATAFILE). I can do a search based on this Content ID but if I am able to get the dID using one of the Site Studio variables, it will be great. Thanks, Justin
-
Hi all, I read the help.sap.com and found that all materials information (classes, characterisctics and characteristic values) can be downloaded via the adapter object SCE if a knowledge base object and its run-time version is created in R/3. Ha
-
I am writing a date generating routine based on the default DateFormat timestamp masks/time pattern Strings. This cycles through different Locales, and gives you the mask for each Locale for short, medium, long, and full format. For an API to an exte
-
SmartView when Office is embedded
Hello, I'm currently using - "Hyperion Smart View for Office, Fusion Edition version 11.2.1.00 (Build 271 - Build Date Mar 28 2011 11:51:25)". - "Office Excel 2007 (12.0.6565.5003) SP2 x86" I'm using "Late Binding" technique to embed Office like desc
-
Doubt with Oracle Reports Format Trigger
Hi friends, I have created a format trigger in oracle reports the code is Function F_Department_NameFormatTrigger return Boolean is v_report_url varchar2(300); Begin v_report_url :='http://localhost:8888/reports/rwservlet? report=empReport.rdf&useri