Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to create an structure using abcpdf that suppose to be like this:
header
content
footer
P.S: content needs to be "front of" header and footer
In other words, I need to have my content starting from y = 0 to y = 100%; My header starting from y = 0 to y = 200; My footer starting from y = 700 to y = 100%. (Values here are just samples)
I hope I am being clear.
At the moment I have those methods:
private void CreateDocHeader(Doc theDoc, int theCount, string content)
{
theDoc.Rect.String = "0 660 600 825";
theDoc.MediaBox.String = theDoc.Rect.String;
for (int i = 1; i <= theCount; i++)
{
theDoc.PageNumber = i;
theDoc.AddImageHtml(content);
}
}
private void CreateDocFooter(Doc theDoc, int theCount, string content)
{
theDoc.Rect.String = "0 200 600 10";
theDoc.MediaBox.String = theDoc.Rect.String;
for (int i = 1; i <= theCount; i++)
{
theDoc.PageNumber = i;
theDoc.AddImageHtml(content);
}
}
private void CreateDocContent(Doc theDoc, int theID, string theContent, ref int theCount)
{
theDoc.Rect.String = "0 800 600 10";
theDoc.MediaBox.String = theDoc.Rect.String;
theID = theDoc.AddImageHtml(theContent);
while (theDoc.Chainable(theID))
{
theDoc.Page = theDoc.AddPage();
theID = theDoc.AddImageToChain(theID);
}
theCount = theDoc.PageCount;
}
Anyone?
Use Hpos and Vpos properties to do that :-
For header, do this:
theDoc.HPos = 0.5;
theDoc.VPos = 1.0;
this will keep your header in left alignment.
For footer, do this:
theDoc.HPos = 1.0;
theDoc.VPos = 0.5;
this will keep your footer in right alignment.
Hope this helps.
Addition:
For having the Z position, that is have the different tiers for the header/footer and content, use the Layer property. This property alongwith the LayerCount property, you can have the solution.
For more reference go through this documentation:-
http://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/2-properties/layer.htm
http://www.websupergoo.com/helppdfnet/source/5-abcpdf/doc/2-properties/layercount.htm
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
I want to remove bytes from an array, I don't want to remove all bytes 0x6f I just want to remove two only of them. This is my code:
string msg = "gooooooal";
byte[] oldArray = Encoding.GetEncoding(1256).GetBytes(msg);
byte[] newArray = oldArray.Where(b => b != 0x6f).ToArray();
You can first find the position and then remove them
byte[] oldArray = Encoding.GetEncoding(1256).GetBytes(msg);
int howManyToRemove = 2; //How many items to remove
var positions = new List<int>();
int lastPos = -1;
for (int i = 0; i < howManyToRemove; i++)
{
var position = Array.IndexOf(oldArray, (byte)0x6f,lastPos+1);
if (position == -1)
{
break;
}
lastPos=position;
positions.Add(position);
}
byte[] newArray = oldArray.Where((val, idx) => !positions.Contains(idx)).ToArray();
If I understood your problem then if want to delete two occurrences of the letter o from your string because the 0x6f ASCII value is 111 which is the letter o.
and for that, you are making the solution very complex.
if can simply do like this.
string s = "gooooooal";
string output = removeChar(s, 'o'); //output will be gooool
static string removeChar(string s,
char ch)
{
int count = 2;
for (int i = 0; i < s.Length; i++)
{
// If ch is found
if (s[i] == ch && count > 0)
{
s = s.Substring(0, i) +
s.Substring(i + 1);
count--;
}
}
return s;
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 months ago.
Improve this question
I'm designing an answer sheet scorer and currently only have 1 major issue left to deal with and its the answer bubbles. People can fill these in all sorts of ways Filled Answer Bubbles, I have tried using Cv2.HoughCircles() but it doesn't pick up the weird circles and since you have to specific a radius if its too small or too big it wont pick them up Example of HoughCircles attempt. If I was able to at least get all the circles I could probably use Cv2.CountNonZero() after finding the range of white space to consider an answer good/bad. Does anyone have any suggestions I could give a try? Any help is appreciated.
Here's the portion that makes them.
//Gray Image
Mat GrayImage = new Mat();
Cv2.CvtColor(startingImage, GrayImage, ColorConversionCodes.BGR2GRAY);
//Making clear
Mat thresholdImage = new Mat();
Cv2.Threshold(GrayImage, thresholdImage, 100, 255, ThresholdTypes.BinaryInv);
Mat guassianBlurImage = new Mat();
Cv2.GaussianBlur(thresholdImage, guassianBlurImage, new OpenCvSharp.Size(5, 5), 0);
Mat cannyImage = new Mat();
int lower = (int)Math.Max(0, (1.0 - 0.33) * 126);
int upper = (int)Math.Min(255, (1.0 + 0.33) * 126);
Cv2.Canny(guassianBlurImage, cannyImage, lower, upper);
//Finding the Question circles
Mat copy = guassianBlurImage.Clone();
//Image (gray), type, dp, minDist, param1, param2, minRadius, maxRadius
var circles = Cv2.HoughCircles(copy, HoughModes.Gradient, 1, 10, 1, 25, 13, 18);
//Just so we can see the circles
Foreach (var cir in circles)
{
//Debug.Print(cir.Radius.ToString());
Cv2.Circle(startingImage, (int)cir.Center.X, (int)cir.Center.Y, (int)cir.Radius, Scalar.Green, 4);
}
I cleaned up my adobe template which had the circles. They were spaced wrongly so I fixed that. This then got me better images of each singular bubble using my custom method to tile the image.
Below is how I call my method and a small example of what it produces:
List<Mat> questionMats = new List<Mat>();
utils.TileImage(WarpThresholdImage, 3, 8, false, questionMats);
List<Mat> bubbleMats = new List<Mat>();
int n = 0;
foreach (var mat in questionMats)
{
utils.TileImage(mat, 8, 1, false, bubbleMats, "bubble" + n);
n++;
}
After this I am able to determine the min/max of white pixels using Cv2.CountNonZero() kind of jankly by changing the test image with 3 different versions which have empty bubbles, all filled, and ones that are invalid. I used the following code.
//Sample each bubble get nonzero count find min and max for normal versions of filled and unfilled. Filter based on results
int min = 20000;
int max = 0;
/* These represent the test I did to confirm ranges
* lowerNonZeroUnFilled = 849;
* upperNonZeroUnFilled = 1328;
* lowerNonZeroNormalFilled = 643;
* upperNonZeroNormalFilled = 1261;
* lowerNonZeroBadFilled = 602;
* upperNonZeroBadFilled = 2201;
*/
for (int i = 0; i < bubbleMats.Count(); i++)
{
int total = Cv2.CountNonZero(bubbleMats[i]);
//Empty Spaces
if (total == 0) { }
// 600 is the lowest value a filled circle will be
if(total > 600)
{
if(total < min)
{
min = total;
}
if(max < total)
{
max = total;
}
//Cv2.ImShow("Bubble" + i + "-" + total, bubbleMats[i]);
}
}
So this gets me what I want. This probably has issues but I'm confident I can deal with it later on.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
The following is the ShowTab() method, how to apply dynamic numbers and result in to the table?
using System;
const int MAX = 4;
int cage = 500/total;
int month = 1;
int adults = 1;
int babies = 0;
int total = 1;
Console.WriteLine("Month\tAdults\tBabies\tTotal");
Console.WriteLine("{0, -10}{1, -10}{2, -10}{3, -10}", month, adults, babies, total);
for(int i = 0; i < MAX; i++) {
Console.writeLine(
}
Maybe I missed something ; but if it's only about formatting somehow ; something like this should do the job :
int month = 1;
int adults = 1;
int babies = 0;
int total = 1;
Console.WriteLine ("header row"); // optional (if needed)
while (/* there is still cages to hold them */)
{
// print current state (-10 width chosen for example, negative for left align)
Console.WriteLine ($"{month, -10}{adults, -10}{babies, -10}{total, -10}");
// do the maths to update values
month = /* ... */;
adults = /* ... */;
babies = /* ... */;
total = /* ... */;
}
Here is a dummy exemple which illustrate why I choose to use width formatting specifier rather than tabulation (as hinted in one comment link).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have a problem with arrays or something missed in these text..
my program works every 500ms and i want to read first 4 double values and take average of these values and then get next 4 double values and so on... i write something about this and can you pls look on this??
if (u_dcbus_pv_act[i] > 0 && i != 0)
{
u_dcbus_pv = u_dcbus_pv_act[i];
p_dcbus_pv = p_dcbus_pv_act[i];
}
if (i >= 3)
{
for (int j = 0; j < 4; j++)
{
total_u += u_dcbus_pv;
total_p += p_dcbus_pv;
}
average_u = total_u / 4;
average_p = total_p / 4;
u_dcbus_target = average_u;
p_dcbus_pv_avg = average_p;
}
from what I understand of your description, I would do it something like this:
/* add current samples to totals */
total_u += u_dcbus_pv_act[i];
total_p += p_dcbus_pv_act[i];
/* every fourth tick, calc average and reset totals */
if (i % 4 == 0)
{
average_u = total_u / 4;
average_p = total_p / 4;
total_u = 0;
total_p = 0;
}
u_dcbus_target = average_u;
p_dcbus_pv_avg = average_p;
i++;
The problem is a header file, which I have to include on each page of the pdf file generated by abcpdf.
The header file contains more than one image file and several lines of text, which varies from case to case.
The problem is that I do not know how to calculate the size of the header. I need to have its size to allocate the rectangle positions to put the rest of html file on each page together with header. I am using C#.
First off you need to create your document with enough space at the top to allow a header to be added. The settings below are for a normal A4 document with a header of about 1/5 of the page. Remember the coordinates on a PDF are from the bottom right not the top left..
//Setting to create the document using ABCPdf 8
var theDoc = new Doc();
theDoc.MediaBox.String = "A4";
theDoc.HtmlOptions.PageCacheEnabled = false;
theDoc.HtmlOptions.ImageQuality = 101;
theDoc.Rect.Width = 719;
theDoc.Rect.Height = 590;
theDoc.Rect.Position(2, 70);
theDoc.HtmlOptions.Engine = EngineType.Gecko;
The code below out puts a header across each page on the document, with a header image then a colored box under the image with some custom text in.
The header image in this case is 1710 x 381 to keep the resolution of the image as high as possible to stop it looking fuzzy when printed.
private static Doc AddHeader(Doc theDoc)
{
int theCount = theDoc.PageCount;
int i = 0;
//Image header
for (i = 1; i <= theCount; i++)
{
theDoc.Rect.Width = 590;
theDoc.Rect.Height = 140;
theDoc.Rect.Position(0, 706);
theDoc.PageNumber = i;
string imagefilePath = HttpContext.Current.Server.MapPath("/images/pdf/pdf-header.png");
Bitmap myBmp = (Bitmap)Bitmap.FromFile(imagefilePath);
theDoc.AddImage(myBmp);
}
//Blue header box
for (i = 2; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 590 50";
theDoc.Rect.Position(13, 672);
System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#468DCB");
theDoc.Color.Color = c;
theDoc.PageNumber = i;
theDoc.FillRect();
}
//Blue header text
for (i = 2; i <= theCount; i++)
{
theDoc.Rect.String = "20 15 586 50";
theDoc.Rect.Position(25, 660);
System.Drawing.Color cText = System.Drawing.ColorTranslator.FromHtml("#ffffff");
theDoc.Color.Color = cText;
string theFont = "Century Gothic";
theDoc.Font = theDoc.AddFont(theFont);
theDoc.FontSize = 14;
theDoc.PageNumber = i;
theDoc.AddText("Your Text Here");
}
return theDoc;
}