MigraDoc - Put TextFrame on Dynamically Generated Pages/Sections - migradoc

The red type paragraph generates multiple pages. Is it possible to put a TextFrame (that is not in a header or footer) to show up on each dynamically generated page/section in MigraDoc without putting it in a header or footer?
public static Document CreateWorkOrderPDF2(Document document, string filename, string WorkOrderHeader, string myMessage)
{
Section section = document.AddSection();
section.PageSetup.PageFormat = PageFormat.Letter;
section.PageSetup.StartingNumber = 1;
section.PageSetup.LeftMargin = 40;
//Sets the height of the top margin
section.PageSetup.TopMargin = 100;
section.PageSetup.RightMargin = 40;
section.PageSetup.BottomMargin = 40;
//HeaderFooter
HeaderFooter header = section.Headers.Primary;
header.Format.Font.Size = 16;
header.Format.Font.Color = Colors.DarkBlue;
//Image
MigraDoc.DocumentObjectModel.Shapes.Image headerImage = header.AddImage("../../Fonts/castorgate.regular.png");
headerImage.Width = "2cm";
Paragraph headerParagraph = header.AddParagraph(WorkOrderHeader);
headerParagraph.Format.Font.Name = "Consolas";
//Vertical Text
TextFrame WorkOrderVerticalTextFrame = section.AddTextFrame();
WorkOrderVerticalTextFrame.Orientation = TextOrientation.Downward;
//moves text to the right
WorkOrderVerticalTextFrame.Left = 550;
WorkOrderVerticalTextFrame.Width = 10;
WorkOrderVerticalTextFrame.Top = 0;
WorkOrderVerticalTextFrame.Height = 150;
WorkOrderVerticalTextFrame.WrapFormat.Style = WrapStyle.Through;
Paragraph WorkOrderVerticalParagraph = WorkOrderVerticalTextFrame.AddParagraph();
WorkOrderVerticalParagraph.Format.Alignment = ParagraphAlignment.Left;
WorkOrderVerticalParagraph.Format.Font.Name = "Consolas";
WorkOrderVerticalParagraph.Format.Font.Size = 8;
WorkOrderVerticalParagraph.AddText(WorkOrderHeader);
//WorkOrderVerticalParagraph.Format.Borders.Width = .5;
//BODY PARAGRAPH
Paragraph EstRecordsParagraph = section.AddParagraph(myMessage);
EstRecordsParagraph.Format.Font.Size = 10;
EstRecordsParagraph.Format.Font.Color = Colors.DarkRed;
EstRecordsParagraph.Format.Borders.Width = .5;
EstRecordsParagraph.Format.RightIndent = 0;
Paragraph renderDate = section.AddParagraph();
renderDate = section.AddParagraph("Work Order Generated: ");
renderDate.AddDateField();
return document;
}

No.
You can add a TextFrame to the section; then it will appear once in that section.
You can add a TextFrame to a header or footer; then it will appear on every page where the header or footer appears. You can use absolute positions for textframes to have them anywhere on the page outside the header/footer areas.

Related

Removing a Watermark from the Active document in VSTO Word 2013

I am trying to remove a watermark that I have created previously in my code from the document. Here is the code which creates and applies the watermark:
foreach (Word.Section section in document.Sections)
{
nShape = section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, tag, "Calibri", 10, MsoTriState.msoTrue, MsoTriState.msoFalse, 0, 0);
nShape.Name = "securityTagWaterMark";
nShape.Line.Visible = MsoTriState.msoFalse;
nShape.Fill.Solid();
nShape.Fill.ForeColor.RGB = (Int32)Word.WdColor.wdColorGray20;
nShape.RelativeHorizontalPosition = Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
nShape.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
// bottom right location
nShape.Left = (float)Word.WdShapePosition.wdShapeRight;
nShape.Top = (float)Word.WdShapePosition.wdShapeBottom;
nShape.LockAspectRatio = MsoTriState.msoTrue;
}
How can I check the document to find any shape objects or replace the text of the watermark that is already on the page. Here is what I have tried but It doesnt work:
Word.Document currentDoc = Globals.ThisAddIn.Application.ActiveDocument;
Word.Shapes shapeCollection = Globals.ThisAddIn.Application.ActiveDocument.Shapes;
foreach (Word.Shape shape in shapeCollection)
{
if (shape.Name == "securityTagWaterMark")
{
shape.TextEffect.Text = newText;
}
}
You're adding it to the header but looking for shapes in the main content. Word does not return all shapes in the Document.Shapes object. This is true for objects in the header but also for nested shapes that do exist in the document content.
Word.Document currentDoc = Globals.ThisAddIn.Application.ActiveDocument;
Word.Shapes shapeCollection = Globals.ThisAddIn.Application.ActiveDocument.Shapes;
foreach (Word.Shape shape in currentDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes)
{
if (shape.Name == "securityTagWaterMark")
{
shape.TextEffect.Text = newText;
}
}

Expert Pdf - add footer on all pages except on the first page

I am using Expert PDF to generate PDF from HTML.
I have to generate footer on all pages except on the first page.
I tried with:
PdfConverter pdfConverter = new PdfConverter();
AddFooter(pdfConverter);
private void AddFooter(PdfConverter pdfConverter)
{
string thisPageURL = HttpContext.Current.Request.Url.AbsoluteUri;
string headerAndFooterHtmlUrl = thisPageURL.Substring(0, thisPageURL.LastIndexOf('/')) + "/HeaderAndFooterHtml.htm";
//enable footer
pdfConverter.PdfDocumentOptions.ShowFooter = true;
// set the footer height in points
pdfConverter.PdfFooterOptions.FooterHeight = 60;
//write the page number
pdfConverter.PdfFooterOptions.TextArea = new TextArea(0, 30, "This is page &p; of &P; ",
new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10, System.Drawing.GraphicsUnit.Point));
pdfConverter.PdfFooterOptions.TextArea.EmbedTextFont = true;
pdfConverter.PdfFooterOptions.TextArea.TextAlign = HorizontalTextAlign.Right;
// set the footer HTML area
pdfConverter.PdfFooterOptions.HtmlToPdfArea = new HtmlToPdfArea(0, 0, -1, pdfConverter.PdfFooterOptions.FooterHeight,
headerAndFooterHtmlUrl, 1024, -1);
pdfConverter.PdfFooterOptions.HtmlToPdfArea.FitHeight = true;
}
but this code generate footer on all pages.
Can someone give me idea or solution for this problem?
Thanks in advance!
Add below line in your code:
pdfConverter.PdfFooterOptions.ShowOnFirstPage = false;

How do I create a XAML storyboard animation from C++\CX?

I've defined a Rectangle in the XAML named "MyRectangle" and when clicked I execute this code:
auto animation = ref new Windows::UI::Xaml::Media::Animation::DoubleAnimation();
animation->From = 0.01;
animation->To = 5.50;
animation->AutoReverse = true;
auto beginTime = Windows::Foundation::TimeSpan();
beginTime.Duration = 0;
animation->BeginTime = beginTime;
auto duration = Windows::Foundation::TimeSpan();
duration.Duration = 20000*1000;
animation->Duration = duration;
auto storyboard = ref new Windows::UI::Xaml::Media::Animation::Storyboard();
auto scaleTransform = ref new Windows::UI::Xaml::Media::ScaleTransform();
MyRectangle->RenderTransform = scaleTransform;
storyboard->SetTargetProperty(animation, "(Rectangle.RenderTransform).(ScaleTransform.ScaleX)");
storyboard->SetTarget(animation, MyRectangle);
storyboard->SetTargetName(animation, "MyRectangle");
storyboard->SpeedRatio = 1.0;
storyboard->Begin();
However, nothing happens. What am I doing wrong?
You must add the "animation" (or more animations) to the "storyboard" childrens:
storyboard->Children->Append(animation);
This is the C# equivalent:
https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.animation.storyboard

Flex 3 - Enable context menu for text object under a transparent PNG

Here is the situation. In my app I have an overlay layer that is composed of a transparent PNG. I have replaced the hitarea for the png with a 1x1 image using the following code:
[Bindable]
[Embed(source = "/assets/1x1image.png")]
private var onexonebitmapClass:Class;
private function loadCompleteHandler(event:Event):void
{
// Create the bitmap
var onexonebitmap:BitmapData = new onexonebitmapClass().bitmapData;
var bitmap:Bitmap;
bitmap = event.target.content as Bitmap;
bitmap.smoothing = true;
var _hitarea:Sprite = createHitArea(onexonebitmap, 1);
var rect:flash.geom.Rectangle = _box.toFlexRectangle(sprite.width, sprite.height);
var drawnBox:Sprite = new FlexSprite();
bitmap.width = rect.width;
bitmap.height = rect.height;
bitmap.x = -loader.width / 2;
bitmap.y = -loader.height / 2;
bitmap.alpha = _alpha;
_hitarea.alpha = 0;
drawnBox.x = rect.x + rect.width / 2;
drawnBox.y = rect.y + rect.height / 2;
// Add the bitmap as a child to the drawnBox
drawnBox.addChild(bitmap);
// Rotate the object.
drawnBox.rotation = _rotation;
// Add the drawnBox to the sprite
sprite.addChild(drawnBox);
// Set the hitarea to drawnBox
drawnBox.hitArea = _hitarea;
}
private function createHitArea(bitmapData:BitmapData, grainSize:uint = 1):Sprite
{
var _hitarea:Sprite = new Sprite();
_hitarea.graphics.beginFill(0x900000, 1.0);
for (var x:uint = 0; x < bitmapData.width; x += grainSize)
{
for (var y:uint = grainSize; y < bitmapData.height; y += grainSize)
{
if (x <= bitmapData.width && y <= bitmapData.height && bitmapData.getPixel(x, y) != 0)
{
_hitarea.graphics.drawRect(x, y, grainSize, grainSize);
}
}
}
_hitarea.graphics.endFill();
return _hitarea;
}
This is based off the work done here: Creating a hitarea for PNG Image with transparent (alpha) regions in Flex
Using the above code I am able to basically ignore the overlay layer for all mouse events (click, double click, move, etc.) However, I am unable to capture the right click (context menu) event for items that are beneath the overlay.
For instance I have a spell check component that checks the spelling on any textitem and like most other spell checkers if the word is incorrect or not in the dictionary underlines the word in red and if you right click on it would give you a list of suggestions in the contextmenu. This is working great when the text box is not under the overlay, but if the text box is under the overlay I get nothing back.
If anyone can give me some pointers on how to capture the right click event on a textItem that is under a transparent png that would be great.

Add Drop Shadow to text

How do I add a drop shadow (with defined distance, size etc) using Photoshop scripting?
Current JS Code
var fontSize = 14;
var fontName = "Arial-Bold"; // NB: must be postscript name of font!
// This is the colour of the text in RGB
//Click foreground colour in Photoshop, choose your colour and read off the RGB values
//these can then be entered below.
var textColor = new SolidColor();
textColor.rgb.red = 255;
textColor.rgb.green =255;
textColor.rgb.blue = 255;
var newTextLayer = doc.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.size = fontSize;
newTextLayer.textItem.font = fontName;
newTextLayer.textItem.contents = ++Count;
newTextLayer.textItem.color = textColor;
newTextLayer.textItem.kind = TextType.PARAGRAPHTEXT;
newTextLayer.textItem.height = fontSize;
newTextLayer.textItem.width = doc.width -20;
//The line below is the text position (X Y) IE; 10 Pixels Right 10 Pixels Down
newTextLayer.textItem.position = Array(10, 12);
// Can be RIGHTJUSTFIED LEFTJUSTIFIED CENTERJUSTIFIED
newTextLayer.textItem.justification=Justification.CENTERJUSTIFIED;
I believe there is no API function for this.
The best you can do is to use Scriptlistner.
The code that it generates then can be used in your script.
Here are some similar discussion with Scriptlistner-generated code:
http://ps-scripts.com/bb/viewtopic.php?t=586
or
http://ps-scripts.com/bb/viewtopic.php?t=2207