I'm accessing a ai file from wpf Application and it runs and adds a text just fine
I need to change the font but I coudln't find any intuitive way to do so nor finding resources to help me out
any directions are welcome:
Illustrator.Application app = new Illustrator.Application();
//Illustrator.Document doc = app.Documents.Add(Illustrator.AiDocumentColorSpace.aiDocumentCMYKColor, 400, 240);
Illustrator.Document doc=app.Open(#"C:\folder\illu_1.ai");
Illustrator.Layer layer1 = doc.Layers.Add();
layer1.Name = "1";
Illustrator.TextFrame textFrame = layer1.TextFrames.Add();
object[] position = new object[2] { 0, 300 };
textFrame.Position = position;
textFrame.Contents = "Some text";
textFrame.Height = 100;
textFrame.Width = doc.Width;
textFrame.CreateOutline();
You can try this to change the font family of your TextFrame.
textFrame[FrameNumber].textRange.characterAttributes.textFont.name = app.textFonts.getByName("FontFamilyName");
Related
Is there a way to convert string to UIElement? I'm trying to add text to my graph's legend using an Interactive data display. The legend needs to not correlate with a plotted graph so I'm making my own like so:
LegendItemsPanel legendItemsPanel = new LegendItemsPanel()
{
};
Legend legend = new Legend()
{
Content = legendItemsPanel
};
Rectangle rectUP = new Rectangle()
{
Width = 10,
Height = 10,
Fill = new SolidColorBrush(Colors.Red),
Stroke = new SolidColorBrush (Colors.Red),
};
UIElement element()
{
UIElement output = new UIElement();
output.Equals(rectUP + " Upstream band");
return output;
}
legendItemsPanel.Children.Add(element());
I've tried a lot of possibilities but every time I get the same error "Cannot convert from 'string' to 'Windows.System.UIElement'". Could someone please help me out with this one? Thank you
I'm currently trying to animate Lights, that are inside the Source property of a CompositeEffect inside a BlendEffect using Windows.UI.Composition. This is my code:
var graphicsEffect = new BlendEffect
{
Mode = BlendEffectMode.Multiply,
Background = new CompositeEffect()
{
Name = "comp",
Mode = Microsoft.Graphics.Canvas.CanvasComposite.Add,
Sources =
{
new PointDiffuseEffect()
{
Name = "Light1",
DiffuseAmount = 1f,
},
new PointDiffuseEffect()
{
Name = "Light2",
DiffuseAmount = 1f,
},
},
},
Foreground = new GaussianBlurEffect()
{
Name = "Blur",
Source = new CompositionEffectSourceParameter("Backdrop"),
BlurAmount = 12f,
BorderMode = EffectBorderMode.Hard,
}
};
The issue is that when I try to animate the position or color of those lights, I'm told that "Animate property refers to an effect not in the graph". Is this even possible? If not, what kind of workaround would there be? I've tried calling Light1.Lightposition, comp.Light1.Lightposition, and comp.Sources.Light1.Lightposition, but none of those work.
Please check your reply in your MSDN thread:
https://social.msdn.microsoft.com/Forums/windowsapps/en-US/65a1f1a0-8c8c-414e-9734-ec5f407b3c6e/uwpanimating-effect-properties-that-are-inside-other-effects-using-windowsuicomposition?forum=wpdevelop.
Thanks.
My travails in trying to use both "generic" textbox-type controls and multiline ones (that have greater height/are taller) are detailed here
What can I do to use an iTextSharp Textfield (or its basic equivalent), with the only difference being that it is multiline (covers more vertical space on the form)?
This gives me back the "textboxes" that I want:
public class DynamicTextbox : IPdfPCellEvent
{
private string fieldname;
public DynamicTextbox(string name)
{
fieldname = name;
}
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].PdfWriter;
iTextSharp.text.pdf.TextField text = new iTextSharp.text.pdf.TextField(writer, rectangle, fieldname);
//Microsoft.SharePoint.WebControls.TextField text = new TextField(writer, rectangle, fieldname);
PdfFormField field = text.GetTextField();
writer.AddAnnotation(field);
}
}
...but this derivation on that theme, attempting to generate a "taller" version of that, fails:
public class DynamicMultilineTextbox : IPdfPCellEvent
{
private string fieldname;
public DynamicMultilineTextbox(string name)
{
fieldname = name;
}
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
Rectangle wreckTangle = new Rectangle(30, 60); // changed from 300, 600
PdfWriter writer = canvases[0].PdfWriter;
iTextSharp.text.pdf.TextField text = new iTextSharp.text.pdf.TextField(writer, wreckTangle, fieldname);
PdfFormField field = text.GetTextField();
writer.AddAnnotation(field);
}
}
The failure is in that, if I use a rectangle of 300, 600, it produces a monstrous Blob that threatens to cover this county and the next. If I use 30,60 it shows nothing - and in either case, where I expect the "tall textboxes" to be just sports horizontal lines, like so:
Am I barking up the wrong tree? How is what I'm trying to accomplish (add multline controls to a PDF file) possible?
UPDATE
Awedly enough, if I just give the textboxes any old literal string, it works:
The code for that is this:
PdfPCell cellNotesMultilineTextBox = new PdfPCell()
{
CellEvent = new DynamicTextbox("multilineTextboxNotes"),
Phrase = new Phrase("I will be darned like a sock", timesRoman9Font)
};
tblMultilineTextAreas.AddCell(cellNotesMultilineTextBox);
Phrase blankPhrase = new Phrase();
PdfPCell blankCell = new PdfPCell(blankPhrase);
blankCell.BorderWidth = 0;
tblMultilineTextAreas.AddCell(blankCell);
PdfPCell cellAccountCodesMultilineTextBox = new PdfPCell()
{
CellEvent = new DynamicTextbox("multilineTextboxAccountCodes"),
Phrase = new Phrase("I will be dammed like a reservoir", timesRoman9Font)
};
tblMultilineTextAreas.AddCell(cellAccountCodesMultilineTextBox);
Phrase blankPhrase2 = new Phrase();
PdfPCell blankCell2 = new PdfPCell(blankPhrase2);
blankCell2.BorderWidth = 0;
tblMultilineTextAreas.AddCell(blankCell2);
PdfPCell cell1099TaxReportableMultilineTextBox = new PdfPCell()
{
CellEvent = new DynamicTextbox("multilineTextbox1099TaxReportable"),
Phrase = new Phrase("I will be the uncle of a monkey", timesRoman9Font)
};
tblMultilineTextAreas.AddCell(cell1099TaxReportableMultilineTextBox);
doc.Add(tblMultilineTextAreas);
...but, of couse, that won't do. Accessing the InnerText of the HtmlTextArea controls on the WebPart, which are coded up like this:
HtmlTextArea txtarNotes = null;
. . .
txtarNotes = new HtmlTextArea();
txtarNotes.Cols = 40;
txtarNotes.Rows = 6;
...results in the "no-usable-height" controls as shown in the first scream shot.
And referencing a Textbox control on the WebPart (instead of a HtmlTextArea control) also results in the "horizontal lines" only. Is this a result of the value being empty (if the string is empty, no space is allotted for it)?
UPDATE 2
Apparently so, because doing this:
String s = txtarAccountCodes.InnerText;
if (String.IsNullOrEmpty(s))
{
s = " ";
}
PdfPCell cellNotesMultilineTextBox = new PdfPCell()
{
CellEvent = new DynamicTextbox("multilineTextboxNotes"),
Phrase = new Phrase(s, timesRoman9Font)
};
...works (the textboxes, albeit empty, display in their expected sizes/heights).
UPDATE 3
It dawned on me that maybe I needed to incrase the size of the cell first (prior to worrying about the size of the "multiline textbox" within the cell). SO I changed the code to this:
PdfPCell cellNotesMultilineTextBox = new PdfPCell()
{
CellEvent = new DynamicTextbox("multilineTextboxNotes"),
Phrase = new Phrase(notes, timesRoman9Font),
MinimumHeight = 120,
NoWrap = false,
Rowspan = 40
};
(the MinimumHeight, NoWrap, and Rowspan values are new). This, though, does not solve the "won't wrap" problem that I've got - the area is large enough, but I can only enter one line of text; the more text I enter, the smaller the text gets:
Is there a solution to this conundrum? It seems what I need is a way to tell the "Textbox" being created to "be multiline" (increase its height, or "rowcount", or make it wrappable, as in the case with the Cell itself above) but there seems to be no such capability "on the surface" - is there something beneath the covers that exposes this functionality?
I have a similar requirement and achieved with the following code. Let me know if I misunderstood something or your requirement is something else.
TextField tf = new TextField(stamper.Writer, new Rectangle(llx, lly, urx, ury), property.ControlId)
{
Options = TextField.MULTILINE | TextField.READ_ONLY,
FontSize = 11
};
Screenshot from Adobe Acrobat:
I have been trying to lay an image in black/gray over a background, and I would like the background to show through on the transparent sections of the image. The image is definitely saved as a transparent png correctly. What is wrong with the code below?
this.pictureBox14.BackColor = System.Drawing.Color.Transparent;
this.pictureBox14.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox14.BackgroundImage")));
this.pictureBox14.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.pictureBox14.Cursor = System.Windows.Forms.Cursors.Hand;
this.pictureBox14.Location = new System.Drawing.Point(486, 337);
this.pictureBox14.Name = "pictureBox14";
this.pictureBox14.Size = new System.Drawing.Size(69, 62);
this.pictureBox14.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox14.TabIndex = 18;
this.pictureBox14.TabStop = false;
this.pictureBox14.Click += new System.EventHandler(this.pictureBox14_Click);
i have a wpf usercontrol with bellow properties:
Width=170mm(642px)
Height=85mm(321px)
i want to print that on a paper with above size(Width=170mm and Height=85mm)
my problem is:when i print it,some items print out of the paper,i think the paper size if Letter by default,if it is correct,how can i change it to above Width and Height?
my code is bellow:
var p = new myUserControl();
var pDoc = new System.Windows.Controls.PrintDialog();
if (pDoc.ShowDialog().Value)
{
pDoc.PrintVisual(p, "MyPrint");
}
maybe something like this needs(this is a settings for System.Windows.Forms.PrintDialog but i use System.Windows.Controls.PrintDialog that it has no PrinterSettings property):
var printerSettings = new PrinterSettings();
var labelPaperSize = new PaperSize { RawKind = (int)PaperKind.A6, Height = 148, Width = 105 };
printerSettings.DefaultPageSettings.PaperSize = labelPaperSize;
var labelPaperSource = new PaperSource { RawKind = (int)PaperSourceKind.Manual };
printerSettings.DefaultPageSettings.PaperSource = labelPaperSource;
if (printerSettings.CanDuplex)
{
printerSettings.Duplex = Duplex.Default;
}
In WPF 1 unit = 1/96 of inch, so you can calculate your size in inches using this formula
you can set printDlg.PrintTicket.PageMediaSize to the size of the Paper and then transform your window to print in that area as below:
private void _print()
{
PrintDialog printDlg = new System.Windows.Controls.PrintDialog();
PrintTicket pt = printDlg.PrintTicket;
Double printableWidth = pt.PageMediaSize.Width.Value;
Double printableHeight = pt.PageMediaSize.Height.Value;
Double xScale = (printableWidth - xMargin * 2) / printableWidth;
Double yScale = (printableHeight - yMargin * 2) / printableHeight;
this.Transform = new MatrixTransform(xScale, 0, 0, yScale, xMargin, yMargin);
//now print the visual to printer to fit on the one page.
printDlg.PrintVisual(this, "Print Page");
}