private void drawArea() { _template.SetColorStroke(BorderColor); _template.SetColorFill(BackgroundColor); _template.Rectangle(0, 0, _template.Width, _template.Height); _template.FillStroke(); }
static private PdfTemplate CreateBarcodeTemplate(PdfContentByte over, Barcode barcode, bool opaque, bool withBorder) { PdfTemplate template = over.CreateTemplate(0, 0); float borderSize = opaque && withBorder ? barcode.X * 3 : 0; // 3 ширины полоски if (opaque) { // Создадим п/у залитый белым цветом template.SetColorFill(BaseColor.WHITE); template.Rectangle(-borderSize, -borderSize, barcode.BarcodeSize.Width + borderSize * 2, barcode.BarcodeSize.Height + borderSize * 2); template.Fill(); } iTextSharp.text.Rectangle boundingBox = barcode.PlaceBarcode(template, BaseColor.BLACK, BaseColor.BLACK); if (borderSize != 0.0) { boundingBox.Right += borderSize; boundingBox.Left -= borderSize; boundingBox.Top += borderSize; if (barcode.Font != null) { // Если текст отображается, то не нужно расширять, потому что там и так место под текстом есть. boundingBox.Bottom -= borderSize; } } // Обрежем шаблон до размера barCode + граница template.BoundingBox = boundingBox; return(template); }
private byte[] CreatePdfWithRotatedXObject(String xobjectText) { MemoryStream baos = new MemoryStream(); Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, baos); writer.CompressionLevel = 0; doc.Open(); doc.Add(new Paragraph("A")); doc.Add(new Paragraph("B")); bool rotate = true; PdfTemplate template = writer.DirectContent.CreateTemplate(20, 100); template.SetColorStroke(BaseColor.GREEN); template.Rectangle(0, 0, template.Width, template.Height); template.Stroke(); Matrix matrix = new Matrix(); if (rotate) { matrix.Translate(0, template.Height); matrix.Rotate(-90); } template.Transform(matrix); template.BeginText(); template.SetFontAndSize(BaseFont.CreateFont(), 12); if (rotate) { template.MoveText(0, template.Width - 12); } else { template.MoveText(0, template.Height - 12); } template.ShowText(xobjectText); template.EndText(); Image xobjectImage = Image.GetInstance(template); if (rotate) { xobjectImage.RotationDegrees = 90; } doc.Add(xobjectImage); doc.Add(new Paragraph("C")); doc.Close(); return(baos.ToArray()); }
public static Image CreateRectangle(PdfWriter writer, float x, float y, float width, float height, BaseColor backColor) { PdfTemplate template = writer.DirectContent.CreateTemplate(width, height); template.SetColorFill(backColor); template.Rectangle(x, y, width, height); template.Fill(); writer.ReleaseTemplate(template); return(Image.GetInstance(template)); }
// --------------------------------------------------------------------------- public void Write(Stream stream) { // step 1 using (Document document = new Document(PageSize.A4)) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 PdfContentByte canvas = writer.DirectContent; // Create a reusable XObject PdfTemplate celluloid = canvas.CreateTemplate(595, 84.2f); celluloid.Rectangle(8, 8, 579, 68); for (float f = 8.25f; f < 581; f += 6.5f) { celluloid.RoundRectangle(f, 8.5f, 6, 3, 1.5f); celluloid.RoundRectangle(f, 72.5f, 6, 3, 1.5f); } celluloid.SetGrayFill(0.1f); celluloid.EoFill(); writer.ReleaseTemplate(celluloid); // Add the XObject ten times for (int i = 0; i < 10; i++) { canvas.AddTemplate(celluloid, 0, i * 84.2f); } // Add the movie posters Image img; Annotation annotation; float x = 11.5f; float y = 769.7f; string RESOURCE = Utility.ResourcePosters; foreach (Movie movie in PojoFactory.GetMovies()) { img = Image.GetInstance(Path.Combine(RESOURCE, movie.Imdb + ".jpg")); img.ScaleToFit(1000, 60); img.SetAbsolutePosition(x + (45 - img.ScaledWidth) / 2, y); annotation = new Annotation( 0, 0, 0, 0, string.Format(IMDB, movie.Imdb) ); img.Annotation = annotation; canvas.AddImage(img); x += 48; if (x > 578) { x = 11.5f; y -= 84.2f; } } } }
public void Sign(String src, String name, String dest, ICollection <X509Certificate> chain, ICipherParameters pk, String digestAlgorithm, CryptoStandard subfilter, String reason, String location) { // Creating the reader and the stamper PdfReader reader = new PdfReader(src); FileStream os = new FileStream(dest, FileMode.Create); PdfStamper stamper = PdfStamper.CreateSignature(reader, os, '\0'); // Creating the appearance PdfSignatureAppearance appearance = stamper.SignatureAppearance; appearance.Reason = reason; appearance.Location = location; appearance.SetVisibleSignature(name); // Creating the appearance for layer 0 PdfTemplate n0 = appearance.GetLayer(0); float x = n0.BoundingBox.Left; float y = n0.BoundingBox.Bottom; float width = n0.BoundingBox.Width; float height = n0.BoundingBox.Height; n0.SetColorFill(BaseColor.LIGHT_GRAY); n0.Rectangle(x, y, width, height); n0.Fill(); // Creating the appearance for layer 2 PdfTemplate n2 = appearance.GetLayer(2); ColumnText ct = new ColumnText(n2); ct.SetSimpleColumn(n2.BoundingBox); Paragraph p = new Paragraph("This document was signed by Bruno Specimen."); ct.AddElement(p); ct.Go(); // Creating the signature IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm); MakeSignature.SignDetached(appearance, pks, chain, null, null, null, 0, subfilter); }
public Chap1013() { Console.WriteLine("Chapter 10 Example 13: Spot Color"); // step 1: creation of a document-object Document document = new Document(); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1013.pdf", FileMode.Create)); BaseFont bf = BaseFont.CreateFont("Helvetica", "winansi", BaseFont.NOT_EMBEDDED); // step 3: we open the document document.Open(); // step 4: we add some content PdfContentByte cb = writer.DirectContent; // Note: I made up these names unless someone give me a PANTONE swatch as gift ([email protected]) PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f)); PdfSpotColor spc_rgb = new PdfSpotColor("PANTONE 147", 0.9f, new Color(114, 94, 38)); PdfSpotColor spc_g = new PdfSpotColor("PANTONE 100 CV", 0.5f, new GrayColor(0.9f)); // Stroke a rectangle with CMYK alternate cb.SetColorStroke(spc_cmyk, .5f); cb.SetLineWidth(10f); // draw a rectangle cb.Rectangle(100, 700, 100, 100); // add the diagonal cb.MoveTo(100, 700); cb.LineTo(200, 800); // stroke the lines cb.Stroke(); // Fill a rectangle with CMYK alternate cb.SetColorFill(spc_cmyk, spc_cmyk.Tint); cb.Rectangle(250, 700, 100, 100); cb.Fill(); // Stroke a circle with RGB alternate cb.SetColorStroke(spc_rgb, spc_rgb.Tint); cb.SetLineWidth(5f); cb.Circle(150f, 500f, 100f); cb.Stroke(); // Fill the circle with RGB alternate cb.SetColorFill(spc_rgb, spc_rgb.Tint); cb.Circle(150f, 500f, 50f); cb.Fill(); // example with colorfill cb.SetColorFill(spc_g, spc_g.Tint); cb.MoveTo(100f, 200f); cb.LineTo(200f, 250f); cb.LineTo(400f, 150f); cb.Fill(); document.NewPage(); String text = "Some text to show"; document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk)))); document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk, 0.5f)))); // example with template PdfTemplate t = cb.CreateTemplate(500f, 500f); // Stroke a rectangle with CMYK alternate t.SetColorStroke(new SpotColor(spc_cmyk, .5f)); t.SetLineWidth(10f); // draw a rectangle t.Rectangle(100, 10, 100, 100); // add the diagonal t.MoveTo(100, 10); t.LineTo(200, 100); // stroke the lines t.Stroke(); // Fill a rectangle with CMYK alternate t.SetColorFill(spc_g, spc_g.Tint); t.Rectangle(100, 125, 100, 100); t.Fill(); t.BeginText(); t.SetFontAndSize(bf, 20f); t.SetTextMatrix(1f, 0f, 0f, 1f, 10f, 10f); t.ShowText("Template text upside down"); t.EndText(); t.Rectangle(0, 0, 499, 499); t.Stroke(); cb.AddTemplate(t, -1.0f, 0.00f, 0.00f, -1.0f, 550f, 550f); } catch (Exception de) { Console.Error.WriteLine(de.Message); Console.Error.WriteLine(de.StackTrace); } // step 5: we close the document document.Close(); }
static int borderThickness = 1; // It's just 1. Won't really change, but whatever. If you change it, things will get fucky. public static bool MakePDF(Ragecomic comic, string pdffile) { using (System.IO.FileStream fs = new FileStream(pdffile, FileMode.Create)) { int rows = (int)Math.Ceiling((double)comic.panels / 2); int width = rowWidth * 2 + borderThickness * 3; int height = rowHeight * rows + borderThickness * rows + borderThickness; // 239 per row, plus 1 pixel border per row, plus 1 pixel extra border ZipFile drawImageZip = new ZipFile(); bool hasDrawImages = comic.items.getDrawImageCount() > 0; if (hasDrawImages) { drawImageZip.Dispose(); string addition = ""; int nr = 1; while (File.Exists(pdffile + ".drawimages" + addition + ".zip")) { addition = "_" + (nr++).ToString(); } drawImageZip = new ZipFile(pdffile + ".drawimages" + addition + ".zip"); } // Create an instance of the document class which represents the PDF document itself. Rectangle pageSize = new Rectangle(width, height); Document document = new Document(pageSize, 0, 0, 0, 0); // Create an instance to the PDF file by creating an instance of the PDF // Writer class using the document and the filestrem in the constructor. PdfWriter writer = PdfWriter.GetInstance(document, fs); document.AddAuthor("Derp"); document.AddCreator("RagemakerToPDF"); document.AddKeywords("rage, comic"); document.AddSubject("A rage comic"); document.AddTitle("A rage comic"); // Open the document to enable you to write to the document document.Open(); PdfContentByte cb = writer.DirectContent; // Fill background with white Rectangle rect = new iTextSharp.text.Rectangle(0, 0, width, height); rect.BackgroundColor = new BaseColor(255, 255, 255); cb.Rectangle(rect); // Draw grid on bottom if it isn't set to be on top. if (!comic.gridAboveAll && comic.showGrid) { DrawGrid(cb, width, height, rows, comic); } //List<MyMedia.FontFamily> families = MyMedia.Fonts.SystemFontFamilies.ToList(); // This was a neat idea, but it's much too slow //List<string> files = FontFinder.GetFilesForFont("Courier New").ToList(); //string filename = FontFinder.GetSystemFontFileName(families[0].) //Draw.Font testFont = new Draw.Font(new Draw.FontFamily("Courier New"),12f,Draw.FontStyle.Regular | Draw.FontStyle.Bold); string courierPath = FontFinder.GetSystemFontFileName("Courier New", true); string courierBoldPath = FontFinder.GetSystemFontFileName("Courier New", true, Draw.FontStyle.Bold); string tahomaPath = FontFinder.GetSystemFontFileName("Tahoma", true, Draw.FontStyle.Bold); // Define base fonts Font[] fonts = new Font[3]; fonts[0] = new Font(BaseFont.CreateFont(courierPath, BaseFont.CP1252, BaseFont.EMBEDDED)); fonts[1] = new Font(BaseFont.CreateFont(courierBoldPath, BaseFont.CP1252, BaseFont.EMBEDDED)); fonts[2] = new Font(BaseFont.CreateFont(tahomaPath, BaseFont.CP1252, BaseFont.EMBEDDED)); /*fonts[0] = BaseFont.CreateFont("fonts/TRCourierNew.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); * fonts[1] = BaseFont.CreateFont("fonts/TRCourierNewBold.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); * fonts[2] = new Font(BaseFont.CreateFont("fonts/Tahoma-Bold.ttf", BaseFont.CP1252, BaseFont.EMBEDDED));*/ int drawimageindex = 0; int index = 0; foreach (var item in comic.items) { if (item is Face) { Face face = (Face)item; Image pdfImage; System.Drawing.Image faceImage; // If mirroring is necessary, we have to read the image via C# and use RotateFlip, as iTextSharp doesn't support mirroring. if (face.mirrored) { // If it's a JPEG, open it with Flux.JPEG.Core, because the internal JPEG decoder (and also LibJpeg.NET) creates weird dithering artifacts with greyscale JPGs, which some of the rage faces are. if (Path.GetExtension(face.file).ToLower() == ".jpeg" || Path.GetExtension(face.file).ToLower() == ".jpg") { FileStream jpegstream = File.OpenRead("images/" + face.file); FluxJpeg.Core.DecodedJpeg myJpeg = new JpegDecoder(jpegstream).Decode(); // Only use this JPEG decoder if the colorspace is Gray. Otherwise the normal one is just fine. if (myJpeg.Image.ColorModel.colorspace == FluxJpeg.Core.ColorSpace.Gray) { myJpeg.Image.ChangeColorSpace(FluxJpeg.Core.ColorSpace.YCbCr); faceImage = myJpeg.Image.ToBitmap(); } else { faceImage = System.Drawing.Image.FromFile("images/" + face.file); } } else { faceImage = System.Drawing.Image.FromFile("images/" + face.file); } // Apply mirroring faceImage.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipX); pdfImage = Image.GetInstance(faceImage, System.Drawing.Imaging.ImageFormat.Png); } else { // Just let iTextSharp handle it if no mirroring is required. Will also save space (presumably) pdfImage = Image.GetInstance("images/" + face.file); } pdfImage.ScalePercent(face.scalex * 100, face.scaley * 100); pdfImage.Rotation = -(float)Math.PI * face.rotation / 180.0f; pdfImage.SetAbsolutePosition(item.x, (height - item.y) - pdfImage.ScaledHeight); // Set opacity to proper value if (face.opacity < 1) { PdfGState graphicsState = new PdfGState(); graphicsState.FillOpacity = face.opacity; cb.SetGState(graphicsState); } cb.AddImage(pdfImage); // Set back to normal if (face.opacity < 1) { PdfGState graphicsState = new PdfGState(); graphicsState.FillOpacity = 1f; cb.SetGState(graphicsState); } } else if (item is DrawImage) { DrawImage drawimage = (DrawImage)item; drawImageZip.AddEntry("drawimage_" + (drawimageindex++).ToString() + ".png", drawimage.imagedata); System.Drawing.Image pngImage = System.Drawing.Image.FromStream(new MemoryStream(drawimage.imagedata)); Image pdfImage = Image.GetInstance(pngImage, System.Drawing.Imaging.ImageFormat.Png); // Rotation is NOT to be applied. Ragemaker actually has a bug that causes it to save rotated images in their rotated form, but save the rotation value anyway // Thus rotating the image by the rotation value will actually rotate them double compared to what they originally looked like // The irony is that ragemaker *itself* cannot properly load an xml it created with this rotation value, as it will also apply the rotation // As such, this tool is currently the only way to correctly display that .xml file as it was originally meant to look, not even ragemaker itself can properly load it again. //pdfImage.Rotation = -(float)Math.PI * item.rotation / 180.0f; pdfImage.SetAbsolutePosition(item.x, (height - item.y) - pdfImage.ScaledHeight); // Opacity likewise seems to be baked in, and in fact the opacity value doesn't even exist. // Implementing it anyway, in case it ever becomes a thing. if (drawimage.opacity < 1) { PdfGState graphicsState = new PdfGState(); graphicsState.FillOpacity = drawimage.opacity; cb.SetGState(graphicsState); } cb.AddImage(pdfImage); // Set back to normal if (drawimage.opacity < 1) { PdfGState graphicsState = new PdfGState(); graphicsState.FillOpacity = 1f; cb.SetGState(graphicsState); } } else if (item is Text) { int padding = 4; Text text = (Text)item; // Create template PdfTemplate xobject = cb.CreateTemplate(text.width, text.height); // Background color (if set) if (text.bgOn) { Rectangle bgRectangle = new Rectangle(0, 0, text.width, text.height); System.Drawing.Color bgColor = System.Drawing.ColorTranslator.FromHtml(text.bgColor); rect.BackgroundColor = new BaseColor(bgColor.R, bgColor.G, bgColor.B, (int)Math.Floor(text.opacity * 255)); xobject.Rectangle(rect); } // Create text Rectangle textangle = new Rectangle(padding, 0, text.width - padding, text.height); ColumnText ct = new ColumnText(xobject); ct.SetSimpleColumn(textangle); Paragraph paragraph = new Paragraph(text.text); Font myFont = fonts[text.style]; // More specific treatment if it's an AnyFont element which allows the user to select any font and styles, not just the normal 3 presets // This isn't perfect, as the current FontFinder doesn't indicate whether he actually found an Italic/Bold typeface, hence it's not possible // to determine whether faux-italic/faux-bold should be applied. Currently it will only work correctly if each used font has a specific typeface // for the needed styles (bold or italic), otherwise incorrect results. // TODO Fix, for example let FontFinder return array of strings, one of which is indicating the suffix that was found. if (text is AnyFontText) { AnyFontText anyfont = (AnyFontText)text; string fontname = anyfont.font; string fontfile = ""; if (anyfont.bold) { fontfile = FontFinder.GetSystemFontFileName(fontname, true, Draw.FontStyle.Bold); int fontStyle = 0; if (anyfont.italic) { fontStyle |= Font.ITALIC; } if (anyfont.underline) { fontStyle |= Font.UNDERLINE; } myFont = new Font(BaseFont.CreateFont(fontfile, BaseFont.CP1252, BaseFont.EMBEDDED), 100f, fontStyle); } else if (anyfont.italic) { fontfile = FontFinder.GetSystemFontFileName(fontname, true, Draw.FontStyle.Italic); int fontStyle = 0; if (anyfont.underline) { fontStyle |= Font.UNDERLINE; } myFont = new Font(BaseFont.CreateFont(fontfile, BaseFont.CP1252, BaseFont.EMBEDDED), 100f, fontStyle); } else { fontfile = FontFinder.GetSystemFontFileName(fontname, true, Draw.FontStyle.Regular); int fontStyle = 0; if (anyfont.underline) { fontStyle |= Font.UNDERLINE; } myFont = new Font(BaseFont.CreateFont(fontfile, BaseFont.CP1252, BaseFont.EMBEDDED), 100f, fontStyle); } } myFont.Size = text.size; System.Drawing.Color color = (System.Drawing.Color)(new System.Drawing.ColorConverter()).ConvertFromString(text.color); myFont.Color = new BaseColor(color.R, color.G, color.B, (int)Math.Floor(text.opacity * 255)); paragraph.Font = myFont; paragraph.Alignment = text.align == Text.ALIGN.LEFT ? PdfContentByte.ALIGN_LEFT : (text.align == Text.ALIGN.RIGHT ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER); paragraph.SetLeading(0, 1.12f); ct.AddElement(paragraph); ct.Go(); // Angle to radians float angle = (float)Math.PI * text.rotation / 180.0f; // Calculate Bounding Box size for correct placement later GraphicsPath gp = new GraphicsPath(); gp.AddRectangle(new System.Drawing.Rectangle(0, 0, (int)Math.Round(text.width), (int)Math.Round(text.height))); Matrix translateMatrix = new Matrix(); translateMatrix.RotateAt(text.rotation, new System.Drawing.PointF(text.width / 2, text.height / 2)); gp.Transform(translateMatrix); var gbp = gp.GetBounds(); float newWidth = gbp.Width, newHeight = gbp.Height; // Create correct placement // Background info: I rotate around the center of the text box, thus the center of the text box is what I attempt to place correctly with the initial .Translate() AffineTransform transform = new AffineTransform(); transform.Translate(item.x + newWidth / 2 - text.width / 2, height - (item.y + newHeight / 2 - text.height / 2) - text.height); transform.Rotate(-angle, text.width / 2, text.height / 2); cb.AddTemplate(xobject, transform); } index++; } if (comic.gridAboveAll && comic.showGrid) { DrawGrid(cb, width, height, rows, comic); } //document.Add(new Paragraph("Hello World!")); // Close the document document.Close(); // Close the writer instance writer.Close(); // Always close open filehandles explicity fs.Close(); if (hasDrawImages) { drawImageZip.Save(); } drawImageZip.Dispose(); } return(false); }
public void Clear(Color2 color) { template.SetRGBColorFill(color.R, color.G, color.B); template.Rectangle(0, 0, template.Width, template.Height); template.FillStroke(); }
public Chap1014() { Console.WriteLine("Chapter 10 Example 14: colored patterns"); // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); Document.Compress = false; try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1014.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we add some content PdfContentByte cb = writer.DirectContent; PdfTemplate tp = cb.CreateTemplate(400, 300); PdfPatternPainter pat = cb.CreatePattern(15, 15, null); pat.Rectangle(5, 5, 5, 5); pat.Fill(); PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f)); SpotColor spot = new SpotColor(spc_cmyk); tp.SetPatternFill(pat, spot, .9f); tp.Rectangle(0, 0, 400, 300); tp.Fill(); cb.AddTemplate(tp, 50, 50); PdfPatternPainter pat2 = cb.CreatePattern(10, 10, null); pat2.SetLineWidth(2); pat2.MoveTo(-5, 0); pat2.LineTo(10, 15); pat2.Stroke(); pat2.MoveTo(0, -5); pat2.LineTo(15, 10); pat2.Stroke(); cb.SetLineWidth(1); cb.SetColorStroke(new Color(System.Drawing.Color.Black)); cb.SetPatternFill(pat2, new Color(System.Drawing.Color.Red)); cb.Rectangle(100, 400, 30, 210); cb.FillStroke(); cb.SetPatternFill(pat2, new Color(System.Drawing.Color.LightGreen)); cb.Rectangle(150, 400, 30, 100); cb.FillStroke(); cb.SetPatternFill(pat2, new Color(System.Drawing.Color.Blue)); cb.Rectangle(200, 400, 30, 130); cb.FillStroke(); cb.SetPatternFill(pat2, new GrayColor(0.5f)); cb.Rectangle(250, 400, 30, 80); cb.FillStroke(); cb.SetPatternFill(pat2, new GrayColor(0.7f)); cb.Rectangle(300, 400, 30, 170); cb.FillStroke(); cb.SetPatternFill(pat2, new GrayColor(0.9f)); cb.Rectangle(350, 400, 30, 40); cb.FillStroke(); } catch (Exception de) { Console.Error.WriteLine(de.Message); Console.Error.WriteLine(de.StackTrace); } // step 5: we close the document document.Close(); }
// =========================================================================== public void Write(Stream stream) { // step 1 using (Document document = new Document(PageSize.A4)) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.CompressionLevel = 0; // step 3 document.Open(); // step 4 PdfContentByte canvas = writer.DirectContent; // Create the XObject PdfTemplate celluloid = canvas.CreateTemplate(595, 84.2f); celluloid.Rectangle(8, 8, 579, 68); for (float f = 8.25f; f < 581; f += 6.5f) { celluloid.RoundRectangle(f, 8.5f, 6, 3, 1.5f); celluloid.RoundRectangle(f, 72.5f, 6, 3, 1.5f); } celluloid.SetGrayFill(0.1f); celluloid.EoFill(); // Write the XObject to the OutputStream writer.ReleaseTemplate(celluloid); // Add the XObject 10 times for (int i = 0; i < 10; i++) { canvas.AddTemplate(celluloid, 0, i * 84.2f); } // Go to the next page document.NewPage(); // Add the XObject 10 times for (int i = 0; i < 10; i++) { canvas.AddTemplate(celluloid, 0, i * 84.2f); } // Get the movies from the database IEnumerable <Movie> movies = PojoFactory.GetMovies(); Image img; float x = 11.5f; float y = 769.7f; string RESOURCE = Utility.ResourcePosters; // Loop over the movies and add images foreach (Movie movie in movies) { img = Image.GetInstance(Path.Combine(RESOURCE, movie.Imdb + ".jpg")); img.ScaleToFit(1000, 60); img.SetAbsolutePosition(x + (45 - img.ScaledWidth) / 2, y); canvas.AddImage(img); x += 48; if (x > 578) { x = 11.5f; y -= 84.2f; } } // Go to the next page document.NewPage(); // Add the template using a different CTM canvas.AddTemplate(celluloid, 0.8f, 0, 0.35f, 0.65f, 0, 600); // Wrap the XObject in an Image object Image tmpImage = Image.GetInstance(celluloid); tmpImage.SetAbsolutePosition(0, 480); document.Add(tmpImage); // Perform transformations on the image tmpImage.RotationDegrees = 30; tmpImage.ScalePercent(80); tmpImage.SetAbsolutePosition(30, 500); document.Add(tmpImage); // More transformations tmpImage.Rotation = (float)Math.PI / 2; tmpImage.SetAbsolutePosition(200, 300); document.Add(tmpImage); } }