public void FillImage(float x, float y, float w, float h, PdfXObject xobj) { InnerWrite("ET\nq\n" + PdfNumber.doubleOut(((float)w) / 1000f) + " 0 0 " + PdfNumber.doubleOut(((float)h) / 1000f) + " " + PdfNumber.doubleOut(((float)x) / 1000f) + " " + PdfNumber.doubleOut(((float)(y - h)) / 1000f) + " cm\n" + "/" + xobj.Name.Name + " Do\nQ\nBT\n"); }
public PdfXObject AddImage(FonetImage img) { // check if already created string url = img.Uri; PdfXObject xObject = (PdfXObject)this.xObjectsMap[url]; if (xObject == null) { PdfICCStream iccStream = null; ColorSpace cs = img.ColorSpace; if (cs.HasICCProfile()) { iccStream = new PdfICCStream(doc.NextObjectId(), cs.GetICCProfile()); iccStream.NumComponents = new PdfNumeric(cs.GetNumComponents()); iccStream.AddFilter(new FlateFilter()); this.objects.Add(iccStream); } // else, create a new one PdfName name = new PdfName("XO" + xObjectsMap.Count); xObject = new PdfXObject(img.Bitmaps, name, doc.NextObjectId()); xObject.SubType = PdfName.Names.Image; xObject.Dictionary[PdfName.Names.Width] = new PdfNumeric(img.Width); xObject.Dictionary[PdfName.Names.Height] = new PdfNumeric(img.Height); xObject.Dictionary[PdfName.Names.BitsPerComponent] = new PdfNumeric(img.BitsPerPixel); // Check for ICC color space if (iccStream != null) { PdfArray ar = new PdfArray(); ar.Add(PdfName.Names.ICCBased); ar.Add(iccStream.GetReference()); xObject.Dictionary[PdfName.Names.ColorSpace] = ar; } else { xObject.Dictionary[PdfName.Names.ColorSpace] = new PdfName(img.ColorSpace.GetColorSpacePDFString()); } xObject.AddFilter(img.Filter); this.objects.Add(xObject); this.xObjectsMap.Add(url, xObject); } return(xObject); }
public void ClipImage(float cx1, float cy1, float cx2, float cy2, float imgX, float imgY, float imgW, float imgH, PdfXObject xobj) { InnerWrite("ET\nq\n" + // clipping PdfNumber.doubleOut(cx1) + " " + PdfNumber.doubleOut(cy1) + " m\n" + PdfNumber.doubleOut(cx2) + " " + PdfNumber.doubleOut(cy1) + " l\n" + PdfNumber.doubleOut(cx2) + " " + PdfNumber.doubleOut(cy2) + " l\n" + PdfNumber.doubleOut(cx1) + " " + PdfNumber.doubleOut(cy2) + " l\n" + "W\n" + "n\n" + // image matrix PdfNumber.doubleOut(((float)imgW) / 1000f) + " 0 0 " + PdfNumber.doubleOut(((float)imgH) / 1000f) + " " + PdfNumber.doubleOut(((float)imgX) / 1000f) + " " + PdfNumber.doubleOut(((float)imgY - imgH) / 1000f) + " cm\n" + "s\n" + // the image itself "/" + xobj.Name.Name + " Do\nQ\nBT\n"); }
public PdfXObject AddImage(FonetImage img) { // check if already created string url = img.Uri; PdfXObject xObject = (PdfXObject)this.xObjectsMap[url]; if (xObject == null) { PdfICCStream iccStream = null; ColorSpace cs = img.ColorSpace; if (cs.HasICCProfile()) { iccStream = new PdfICCStream(doc.NextObjectId(), cs.GetICCProfile()); iccStream.NumComponents = new PdfNumeric(cs.GetNumComponents()); iccStream.AddFilter(new FlateFilter()); this.objects.Add(iccStream); } // else, create a new one PdfName name = new PdfName("XO" + xObjectsMap.Count); xObject = new PdfXObject(img.Bitmaps, name, doc.NextObjectId()); xObject.SubType = PdfName.Names.Image; xObject.Dictionary[PdfName.Names.Width] = new PdfNumeric(img.Width); xObject.Dictionary[PdfName.Names.Height] = new PdfNumeric(img.Height); xObject.Dictionary[PdfName.Names.BitsPerComponent] = new PdfNumeric(img.BitsPerPixel); // Check for ICC color space if (iccStream != null) { PdfArray ar = new PdfArray(); ar.Add(PdfName.Names.ICCBased); ar.Add(iccStream.GetReference()); xObject.Dictionary[PdfName.Names.ColorSpace] = ar; } else { xObject.Dictionary[PdfName.Names.ColorSpace] = new PdfName(img.ColorSpace.GetColorSpacePDFString()); } xObject.AddFilter(img.Filter); this.objects.Add(xObject); this.xObjectsMap.Add(url, xObject); } return xObject; }