Reputation: 1
I'm writing a program that will allow me to print sales tags in my Bowling Pro Shop. Currently I am doing them manually but I'm looking to make it easier to create. I have created a program with VS2015 that asks for all the fields and saves it to an Access Database, and also prints it to the template I have created. The problem I am running into is formatting the text to appear as it does when I made it in Photoshop. Even if its off just a little bit that is fine but currently I cant figure out how to write it on the template the way I want.This is the template I'm trying to print to, the bottom are formatted using Photoshop and the top is a blank one. Im thinking it may be easiest to create one image and add it to the pdf(5 Times).
Here is my code:
private void print()
{
string dest = @"C:\Users\bwilliams\Desktop\balltest1.pdf";
string src = @"C:\Users\bwilliams\Desktop\BallTags.pdf";
Rectangle[] columns = new Rectangle[]
{
new Rectangle(100,500,150,200),
new Rectangle(250,500,150,200),
new Rectangle(400,500,150,200),
new Rectangle(550,500,150,200)
};
PdfWriter writer = new PdfWriter(dest);
PdfDocument pdf = new PdfDocument(new PdfReader(src), writer);
Document doc = new Document(pdf,PageSize.A4.Rotate());
doc.SetRenderer(new ColumnDocumentRenderer(doc, columns));
doc.Add(new Paragraph("Ebonite").SetPaddings(150, 60, 0, 0).SetFontSize(24).SetFont(Arial).SetFixedLeading(24));
doc.Add(new Paragraph("GB2 MVP").SetPaddings(150, 0, 0, 0).SetFontSize(24).SetFixedLeading(24));
doc.Add(new Paragraph("$114.95").SetPaddings(150, 0, 0, 0).SetFontSize(24).SetFixedLeading(24));
doc.Add(new Paragraph("").SetPaddings(0, 0, 0, 0).SetFontSize(24));
doc.Add(new Paragraph("").SetPaddings(0, 0, 0, 0).SetFontSize(24));
doc.Add(new Paragraph("").SetPaddings(0, 0, 0, 0).SetFontSize(24));
doc.Add(new Paragraph("").SetPaddings(0, 0, 0, 0).SetFontSize(24));
doc.Add(new Paragraph("").SetPaddings(0, 0, 0, 0).SetFontSize(24));
doc.Add(new Paragraph("").SetPaddings(0, 0, 0, 0).SetFontSize(24));
doc.Add(new Paragraph("").SetPaddings(0, 0, 0, 0).SetFontSize(24));
doc.Close();
}
I just have the info hard coded for now instead of using the input from text boxes.. Here is what you get when you click print.
Im not sure how to format the next line over for CORE: COVER: FINISH: RG: DIFF:
I also am not sure how to add the font Arial (Black) to iText7 Font Factory.
Thanks, Brandon
Upvotes: 0
Views: 426
Reputation: 77528
Your post contains different questions.
Fonts:
You want to create a PdfFont
in iText 7. This is done in a very different (and much easier) way when compared to iText 5. In iText 5, you had a Font
class and a BaseFont
class. Those are no longer necessary. You just do this:
PdfFont font = PdfFontFactory.CreateFont(pathToArialBlack, true);
In this line, pathToArialBlack
is a path to ARIBLK.TTF
, e.g. C:\WINDOWS\Fonts\ARIBLK.TTF
.
Columns:
The question about columns is wrong. Looking at the desired result. I can't imagine why you'd use ColumnDocumentRenderer
. I would create a Canvas
object for every rectangle, and pass that Canvas
object to a method that adds the content to the canvas. Make sure you add the image bytes only once by passing the Image
object to the method rather than creating the Image
in the method as many times as you have Canvas
objects.
Upvotes: 1