Adding sticky note to existing PDF. losing original PDF content [duplicate] - c#-4.0

I want to add Annotations comment in existing PDF file using iTextSharp with C#.
Please give sample code to add Annotations in existing PDF file.
Here PS Script for my Annotation:
[/Contents (My Text contents) /Rect [100 600 150 550] /SrcPg 1 /Title (My Title text) /Color [0 0 1] /Subtype /Caret /ANN pdfmark

The iText(Sharp) example TimetableAnnotations1.java / TimetableAnnotations1.cs from chapter 7 of iText in Action — 2nd Edition shows how to add annotations to existing PDFs in general.
The central code is (in the C# example):
rect = GetPosition(screening);
annotation = PdfAnnotation.CreateText(
stamper.Writer, rect, movie.MovieTitle,
string.Format(INFO, movie.Year, movie.Duration),
false, "Help"
);
annotation.Color = WebColors.GetRGBColor(
"#" + movie.entry.category.color
);
stamper.AddAnnotation(annotation, page);
where stamper is a PdfStamper working on your PDF file; movie is a data structure the example retrieves title, text and color of the annotation from.
PdfAnnotation offers multiple other Create... methods to create other types of annotations.

rect = GetPosition(screening);
can someone plz explain why is this is used..is there any way to find the current cursor position (top,bottom,height,width)
as with the annotation,
Document doc = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(#"C:\Users\Asus\Desktop\Test.pdf", FileMode.OpenOrCreate));
doc.AddDocListener(writer);
doc.Open();
doc.Add(new Annotation("annotation", "The text displayed in the sticky note", 100f, 500f, 200f, 600f));
doc.Close();
this works fine to me..

Related

How to create Apache POI stacked Barchart

I want to create "stacked bar chart" using apache poi library. Need some documentation.
row1 = worksheet.createRow(r);
row['data'].flatten.each_with_index do |data, index|
cell = row1.createCell(index);
cell.setCellValue(data);
end
drawing = worksheet.createDrawingPatriarch();
anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 8, 20);
chart = drawing.createChart(anchor);
ctChart = chart.getCTChart();
ctPlotArea = ctChart.getPlotArea();
ctBarChart = ctPlotArea.addNewBarChart();
ctBoolean = ctBarChart.addNewVaryColors();
ctBoolean.setVal(true);
ctBarChart.addNewBarDir().setVal(STBarDir.BAR);
ctBarChart.addNewGrouping().setVal(STBarGrouping.STACKED);
ctBarSer = ctBarChart.addNewSer();
ctSerTx = ctBarSer.addNewTx();
ctStrRef = ctSerTx.addNewStrRef();
ctStrRef.setF("Sheet1!$A$#{r+1}");
ctBarSer.addNewIdx().setVal(r+1);
cttAxDataSource = ctBarSer.addNewCat();
ctStrRef = cttAxDataSource.addNewStrRef();
length = row['data'].flatten.length
ctStrRef.setF("Sheet1!$B$#{r+1}:$#{CellReference.convertNumToColString(length-1)}$#{r + 1}");
ctNumDataSource = ctBarSer.addNewVal();
ctNumRef = ctNumDataSource.addNewNumRef();
ctNumRef.setF("Sheet1!$B$#{r+1}:$#{CellReference.convertNumToColString(length-1)}$#{r+1}");
ctBarSer.addNewSpPr().addNewLn().addNewSolidFill().addNewSrgbClr().setVal([0,0,0]);
Using above code I am getting bar chart but need to convert to stacked bar chart.
enter image description here
While I can't tell you exactly what the magic incantation to make your chart work is, I can help you work through your issue.
If the type of chart you want to create is not supported by POI. You are going to have to create it manually. Seems you have a good start on that. You can find specification documents here http://www.ecma-international.org/publications/standards/Ecma-376.htm. POI uses the 1st edition of the spec.
While these documents are very good, you might need some help determining just how to structure the XML. The way I go about it is to create a simple document using Excel or Word, then rename the saved document as *.zip. Now you can inspect the xml package using Notepad++ or some other viewer.
Once you have something generated with POI, you can also view the resulting XML in a similar manner to se what the differences are if the results are not as expected.

Adding title text inside gauge Dojo

i need to insert a title (not a tooltip, a text on the top) inside the svg rendered by Dojo. How can i do that?
Here my Dgauge:
http://jsfiddle.net/MacroX/pZU93/1/
PD: The line
gauge.title = 'Test Report'
doesnt show the title
EDIT: The question is regarding a label at the top of the gauge, not the title attribute as I originally thought.
You can use a TextIndicator much like you did for the value label below the needle, but you can set a labelFunc property that defines a function called to set a label and displays whatever string is returned from it.
var labelText = new TextIndicator();
labelText.set('x', 73.3);
labelText.set('y', 55);
labelText.set('labelFunc', function() {return 'Test Report';});
gauge.addElement('labelText', labelText);
Here is a modified version of your fiddle with the title text in place.
Original answer remans below in case someone else needs it
Pass the title in when you create the gauge:
var gauge = new CircularLinearGauge({
title: 'Test Report'
}, dojo.byId("gauge"));
You can also use set to set it after the gauge is created:
gauge.set('title', 'Test Report'); //does work :)
The reason for this is that the gauge widget needs to set the text you give as the title on a specific element within the widget's template. gauge.title just sets the title property of the gauge widget, and the widget has no idea when or with what value that property is being set and thus is not able to make it show up as a title attribute on the gauge.
Finally i got a way to resolve this, and this is useful when you need to personalize your dgauge. Here the example:
http://jsfiddle.net/MacroX/THJqV/
What i did is basicly create a gauge, fill it with background white, and then add elements inside
var baseWidth = 400;
gauge.addElement("background", function (g) {
var auxHeight = baseWidth * objGauge.offsetHeight / objGauge.offsetWidth;
g.createRect({
width: 400, height: auxHeight
//width: 400, height: 300
}).setFill("#FFF");
});
I dont know if is the best way, but works and i didnt find something similar in other sites
And what I think is great, this support multiple chart dgauges in only one SVG
I hope this will useful to someone else

How to Convert Emgu.Cv.Image<Gray,byte> to System.Image

I was new to Emgu Cv and i was wondering if someone could let me know how i change Emgu.Cv.Image to System.Image?If there is a need for further explanation, let me know and i will do it.The language i am using is C#.
You can just use the ToImage() method to get a System.Drawing.Bitmap (which is a derived class of System.Drawing.Image), so something like this
// create an Emgu image of 400x200 filled with Blue color
Image<Bgr, Byte> img = new Image<Bgr, byte>(400, 200, new Bgr(255, 0, 0));
// copy to a .NET image
System.Drawing.Image pMyImage = img.ToBitmap();
Is that what you mean?

Aspose.Words...calculating widt of text in pixels

I have an MVC3 C# .Net web app. I am using Aspose.Words to create an MS Word document. I have a requirement to not include tables in the document. However, on several lines of the document the alignment of the text is mis-aligned depending on the width of the text.
For example:
This looks good
Proposal Name: My Proposal Date:04/24/2012
This does not
Proposal Name: My Prop Date:04/24/2012
It should be
Proposal Name: My Prop Date:04/24/2012
Based on the width of the first bit of text, I need to calculate the width in pixels (I think) and insert a TAB if necessary.
Any ideas how to do this?
you can use Graphics.MeasureString function which gives you the width of your string in pixels based on your font. for more info go Here
Cheers,
Ehsan
The following code example returns the bounding rectangle of the current entity relative to the page top left corner.
Document doc = new Document(MyDir + "in.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
var renderObject = layoutCollector.GetEntity(para);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
Console.WriteLine(location);
}
src: https://www.aspose.com/community/forums/thread/541215/replace-run-text-with-string-of-spaces-of-same-pixel-length.aspx

trying to extract formatted images from indesign into a separate folder

I'm looking for a way to extract images from an ID file in a 'formatted' / cropped form.
i.e: a. I have placed numerous, hi-res (tiff, psd) images into an InDesign CS5 file
b. The image boxes that they have been placed into, are smaller than the actual image (pretty intense cropping occurred) c. I am trying to collect these images in their new stage (cropped to the image box) and export them as jpg at 72dpi.
Are there any plug-ins out there that would automatically collect "formatted" images from ID for me? Or is there some other way?
If you're familiar with Indesign Scripting, this can very easily be done via a script. I use Javascript but this can be done with VBSript or AppleScript as well. Here is a basic example of a script that will open a document, and export a rectangle (your image box) as a JPG. Basically, you can just loop through the pictures in your document and export each one to a location/filename you choose (see the myFile variable below). There are several "jpegExportPreferences" you can pick from to determine how your output JPG will be (i.e. DPI).
test();
function test(){
var myDoc = app.open('c:/user/desktop/testDocument.indd');
var myGroups = myDoc.groups;
//for each group...
for (var i = 0;i < myGroups.length; i++){
// for each rectangle in the group...
for(var r = 0; r< myGroups[i].rectangles.length; r++){
var myRect = myGroups[i].rectangles[r];
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;
//give it a unique name
var myFile = new File('c:/users/desktop/newJPG' + myRect.id + '.jpg');
myRect.exportFile(ExportFormat.JPG, myFile);
}
}
}
For a list of the other optional JPG Export preferences, see this link:
http://indesignscriptingreference.com/cs2/javascript-cs2/jpegexportpreference.htm
Hope this helps!

Resources