Hi Noah,
True, I don't think the solution is perfect for the reasons you've stated, but here's my final solution below. I had to add a second function on top of the initial wrapped text in order to break really long continuous strings that exceeded the preferred character max. For example, if you included a long hyperlink like "https://community.esri.com/t5/arcgis-api-for-javascript-questions/print-task-not-printing-textsymbol..."
function addLineBreaks(textLabel) {
//apply line breaks to wrap text with max width of 50 characters
const wrappedText = textLabel.replace(
/(?![^\n]{1,50}$)([^\n]{1,50})\s/g, '$1\n'
);
return wrappedText.replace(/(.{80})/g, "$1\n");
}
My text symbol is defined as follows:
var textSymbolGeneric = {
type: "text", // autocasts as new TextSymbol()
color: "white",
haloColor: selectedColor,
haloSize: "1px",
text: "",
xoffset: 0,
yoffset: 0,
font: {
size: 12,
family: "sans-serif",
weight: "bold"
},
lineWidth: 300,
horizontalAlignment: "left",
verticalAlignment: "bottom"
};
This is how it looks for verticalAlignment: "bottom"
Note the orange circle edit point which indicates the starting point for where I clicked to add the text.
This is how it looks if I accept the default verticalAlignment value of "baseline"
While the baseline setting is preferred, since it goes downward based on where you clicked and started your text, the problem is when our users go to export the map to pdf. They expect whatever is showing on the map, with all their redline markups and text, will be sent to another person and appear the same way. I am forced to make text start from the "bottom" only because it's reliable in the output pdf.
The result of printing the last image above, with "baseline" as the vertical alignment, will be the following.
I realize it's difficult to compare to the one above without the line and point features, but you can see the text shifted to way above the thick white (highway) line.
Side note: all the layers you're seeing turned on in this output pdf are not visible (unchecked in the layer list). This is a JS 4.20 application, way too large to share all the code broken up into many files. This is either another bug or something going on with my code. Either way it's not obvious to me yet, because the Web Map JSON string does not include those layers you see shown (blue and red lines, the yellow points, etc.). I would think the print task is including too much, but again maybe an oversight by me somewhere.
For the sake of staying on topic with the original post I will not go further with this issue.
I'm unfortunately out of time to offer anything else for now. It may be days before I can return to this discussion.