public void AddXObject(PdfXObject xObject) { xObjects.Add(xObject.Name, xObject.GetReference()); }
protected internal override void Write(PdfWriter writer) { PdfDictionary dict = new PdfDictionary(); if (parent == null) { // root Outlines object if (first != null && last != null) { dict.Add(PdfName.Names.First, first.GetReference()); dict.Add(PdfName.Names.Last, last.GetReference()); } } else { dict.Add(PdfName.Names.Title, new PdfString(title)); dict.Add(PdfName.Names.Parent, parent.GetReference()); if (first != null && last != null) { dict.Add(PdfName.Names.First, first.GetReference()); dict.Add(PdfName.Names.Last, last.GetReference()); } if (prev != null) { dict.Add(PdfName.Names.Prev, prev.GetReference()); } if (next != null) { dict.Add(PdfName.Names.Next, next.GetReference()); } if (count > 0) { dict.Add(PdfName.Names.Count, new PdfNumeric(count)); } if (actionRef != null) { dict.Add(PdfName.Names.A, actionRef); } } writer.Write(dict); }
public void AddFont(PdfFont font) { fonts.Add(font.Name, font.GetReference()); }
public void Add(string name, PdfIndirectObjectReference reference) { _dictionary.Add(name, reference); }
public async Task WriterTest() { var documentCatalogDict = new PdfDictionary(); var documentCatalog = new PdfIndirectObject(documentCatalogDict); var infoDict = new PdfDictionary(); var info = new PdfIndirectObject(infoDict); var pageTreeDict = new PdfDictionary(); var pageTree = new PdfIndirectObject(pageTreeDict); var pageReferences = new PdfArray(); documentCatalogDict.Add("Type", new PdfName("Catalog")); documentCatalogDict.Add("Pages", new PdfIndirectObjectReference(pageTree)); infoDict.Add("Producer", "LittlePdf"); infoDict.Add("CreationDate", new PdfDate(DateTime.UtcNow)); infoDict.Add("ModDate", new PdfDate(DateTime.UtcNow)); infoDict.Add("Title", new PdfString("Test Pdf")); infoDict.Add("Author", new PdfString("Salil Ponde")); pageTreeDict.Add("Type", new PdfName("Pages")); pageTreeDict.Add("Kids", pageReferences); pageTreeDict.Add("Count", new PdfInteger(0)); pageTreeDict.Add("MediaBox", new PdfArray(new List <PdfObject> { new PdfReal(0), new PdfReal(0), new PdfReal(595), new PdfReal(842) })); var font1Dict = new PdfDictionary(); var font1 = new PdfIndirectObject(font1Dict); font1Dict.Add("Type", new PdfName("Font")); font1Dict.Add("Subtype", new PdfName("Type1")); font1Dict.Add("BaseFont", new PdfName("Helvetica-Oblique")); font1Dict.Add("Encoding", new PdfName("WinAnsiEncoding")); var fontsDict = new PdfDictionary(); var resourcesDict = new PdfDictionary(); resourcesDict.Add("Font", fontsDict); fontsDict.Add("F1", new PdfIndirectObjectReference(font1)); pageTreeDict.Add("Resources", resourcesDict); var pageDict = new PdfDictionary(); var page = new PdfIndirectObject(pageDict); pageReferences.Add(new PdfIndirectObjectReference(page)); pageDict.Add("Type", new PdfName("Page")); pageDict.Add("Parent", new PdfIndirectObjectReference(pageTree)); //var c = Encoding.ASCII.GetBytes("0.9 0.5 0.0 rg q 10 10 m 500 10 l 5 w [3] 0 d S Q 500 10 m 500 500 l S "); var c = Encoding.ASCII.GetBytes("BT /F1 24 Tf 100 742 Td (Hey, this is amazing!) Tj ET "); var pageContentStream = new PdfStream(c); var pageContent = new PdfIndirectObject(pageContentStream); pageDict.Add("Contents", new PdfIndirectObjectReference(pageContent)); var page2Dict = new PdfDictionary(); var page2 = new PdfIndirectObject(page2Dict); pageReferences.Add(new PdfIndirectObjectReference(page2)); page2Dict.Add("Type", new PdfName("Page")); page2Dict.Add("Parent", new PdfIndirectObjectReference(pageTree)); page2Dict.Add("MediaBox", new PdfArray(new List <PdfObject> { new PdfReal(0), new PdfReal(0), new PdfReal(842), new PdfReal(595) })); // Write var fileName = @"c:\temp\ddd.pdf"; File.Delete(fileName); var stream = File.Create(fileName); var writer = new PdfWriter(stream); await writer.WriteAsync(documentCatalog); await writer.WriteAsync(info); await writer.WriteAsync(pageTree); await writer.WriteAsync(font1); await writer.WriteAsync(page); await writer.WriteAsync(pageContent); await writer.WriteAsync(page2); await writer.CloseAsync(documentCatalog, info); }
/// <summary> /// Gets the image. /// </summary> /// <returns></returns> private Image GetImage() { Image image; this.LoadImage(); int num = 0; int num2 = 0; this.palShades = false; if (this.trans != null) { for (int i = 0; i < this.trans.Length; i++) { int num4 = this.trans[i] & 0xff; if (num4 == 0) { num++; num2 = i; } if ((num4 != 0) && (num4 != 0xff)) { this.palShades = true; break; } } } if ((this.colorType & 4) != 0) { this.palShades = true; } this.genBWMask = !this.palShades && ((num > 1) || (this.transRedGray >= 0)); if ((!this.palShades && !this.genBWMask) && (num == 1)) { this.properties.Add(PdfName.Mask, PdfArray.Convert(new int[] { num2, num2 })); } bool flag = (((this.interlaceMethod == 1) || (this.bitDepth == 0x10)) || (((this.colorType & 4) != 0) || this.palShades)) || this.genBWMask; switch (this.colorType) { case 0: this.inputBands = 1; break; case 2: this.inputBands = 3; break; case 3: this.inputBands = 1; break; case 4: this.inputBands = 2; break; case 6: this.inputBands = 4; break; } if (flag) { this.DecodeIdat(); } int inputBands = this.inputBands; if ((this.colorType & 4) != 0) { inputBands--; } int bitDepth = this.bitDepth; if (bitDepth == 0x10) { bitDepth = 8; } if (this.image != null) { image = new RawImage(this.width, this.height, inputBands, bitDepth, this.image); } else { RawImage image2 = new RawImage(this.width, this.height, inputBands, bitDepth, this.idat.ToArray()) { Deflated = true }; image = image2; PdfDictionary dictionary2 = new PdfDictionary(); dictionary2.Add(PdfName.BitsPerComponent, new PdfNumber((double)this.bitDepth)); dictionary2.Add(PdfName.Predictor, new PdfNumber(15.0)); dictionary2.Add(PdfName.Columns, new PdfNumber((double)this.width)); dictionary2.Add(PdfName.Colors, new PdfNumber(((this.colorType == 3) || ((this.colorType & 2) == 0)) ? ((double)1) : ((double)3))); PdfDictionary dictionary = dictionary2; this.properties.Add(PdfName.DecodeParms, dictionary); } if (!this.properties.ContainsKey(PdfName.ColorSpace)) { this.properties.Add(PdfName.ColorSpace, this.GetColorspace()); } if (this.intent != null) { this.properties.Add(PdfName.Intent, this.intent); } if (this.properties.Count > 0) { image.Properties = this.properties; } if (this.palShades) { Image image3 = new RawImage(this.width, this.height, 1, 8, this.smask); image3.MakeMask(); image.ImageMask = image3; } if (this.genBWMask) { Image image4 = new RawImage(this.width, this.height, 1, 1, this.smask); image4.MakeMask(); image.ImageMask = image4; } image.SetDpi(this.dpiX, this.dpiY); image.XYRatio = this.XYRatio; image.OriginalType = ImageType.PNG; return(image); }
/// <summary> /// Gets the colorspace. /// </summary> /// <returns></returns> private PdfObjectBase GetColorspace() { if ((this.gamma == 1f) && !this.hasCHRM) { if ((this.colorType & 2) != 0) { return(PdfName.DeviceRGB); } return(PdfName.DeviceGray); } PdfArray array = new PdfArray(); PdfDictionary item = new PdfDictionary(); if ((this.colorType & 2) == 0) { if (this.gamma == 1f) { return(PdfName.DeviceGray); } array.Add(PdfName.CalGray); item.Add(PdfName.Gamma, new PdfNumber((double)this.gamma)); item.Add(PdfName.WhitePoint, PdfArray.Convert(new int[] { 1, 1, 1 })); array.Add(item); return(array); } PdfArray array2 = PdfArray.Convert(new int[] { 1, 1, 1 }); array.Add(PdfName.CalRGB); if (this.gamma != 1f) { PdfArray array3 = new PdfArray(); PdfNumber number = new PdfNumber((double)this.gamma); array3.Add(number); array3.Add(number); array3.Add(number); item.Add(PdfName.Gamma, array3); } if (this.hasCHRM) { float num = this.yW * ((((this.xG - this.xB) * this.yR) - ((this.xR - this.xB) * this.yG)) + ((this.xR - this.xG) * this.yB)); float num2 = (this.yR * ((((this.xG - this.xB) * this.yW) - ((this.xW - this.xB) * this.yG)) + ((this.xW - this.xG) * this.yB))) / num; float num3 = (num2 * this.xR) / this.yR; float num4 = num2 * (((1f - this.xR) / this.yR) - 1f); float num5 = (-this.yG * ((((this.xR - this.xB) * this.yW) - ((this.xW - this.xB) * this.yR)) + ((this.xW - this.xR) * this.yB))) / num; float num6 = (num5 * this.xG) / this.yG; float num7 = num5 * (((1f - this.xG) / this.yG) - 1f); float num8 = (this.yB * ((((this.xR - this.xG) * this.yW) - ((this.xW - this.xG) * this.yW)) + ((this.xW - this.xR) * this.yG))) / num; float num9 = (num8 * this.xB) / this.yB; float num10 = num8 * (((1f - this.xB) / this.yB) - 1f); float num11 = (num3 + num6) + num9; float num12 = (num4 + num7) + num10; array2 = new PdfArray { new PdfNumber((double)num11), new PdfNumber(1.0), new PdfNumber((double)num12) }; PdfArray array5 = new PdfArray { new PdfNumber((double)num3), new PdfNumber((double)num2), new PdfNumber((double)num4), new PdfNumber((double)num6), new PdfNumber((double)num5), new PdfNumber((double)num7), new PdfNumber((double)num9), new PdfNumber((double)num8), new PdfNumber((double)num10) }; item.Add(PdfName.Matrix, array5); } item.Add(PdfName.WhitePoint, array2); array.Add(item); return(array); }
public override async Task WriteAsync(Stream stream) { var pdfDictionary = new PdfDictionary(); pdfDictionary.Add(PdfSpec.Names.Type, _type); if (FontName != null) { pdfDictionary.Add("FontName", FontName); } if (Flags != null) { pdfDictionary.Add("Flags", Flags); } if (ItalicAngle != null) { pdfDictionary.Add("Encoding", ItalicAngle); } if (Ascent != null) { pdfDictionary.Add("Ascent", Ascent); } if (Descent != null) { pdfDictionary.Add("Descent", Descent); } if (CapHeight != null) { pdfDictionary.Add("CapHeight", CapHeight); } if (AvgWidth != null) { pdfDictionary.Add("AvgWidth", AvgWidth); } if (MaxWidth != null) { pdfDictionary.Add("MaxWidth", MaxWidth); } if (FontWeight != null) { pdfDictionary.Add("FontWeight", FontWeight); } if (XHeight != null) { pdfDictionary.Add("XHeight", XHeight); } if (StemV != null) { pdfDictionary.Add("StemV", StemV); } if (FontBBox != null) { pdfDictionary.Add("FontBBox", FontBBox); } if (FontFile2 != null) { pdfDictionary.Add("FontFile2", FontFile2); } Value = pdfDictionary; await base.WriteAsync(stream); }