예제 #1
0
 public Image(PDF pdf, PDFobj obj)
 {
     pdf.newobj();
     pdf.Append("<<\n");
     pdf.Append("/Type /XObject\n");
     pdf.Append("/Subtype /Image\n");
     pdf.Append("/Filter ");
     pdf.Append(obj.getValue(PDFobj.FILTER));
     pdf.Append('\n');
     pdf.Append("/Width ");
     pdf.Append(obj.getValue(PDFobj.WIDTH));
     pdf.Append('\n');
     pdf.Append("/Height ");
     pdf.Append(obj.getValue(PDFobj.HEIGHT));
     pdf.Append('\n');
     pdf.Append("/ColorSpace ");
     pdf.Append(obj.getValue(PDFobj.COLORSPACE));
     pdf.Append('\n');
     pdf.Append("/BitsPerComponent ");
     pdf.Append(obj.getValue(PDFobj.BITSPERCOMPONENT));
     pdf.Append('\n');
     pdf.Append("/Length ");
     pdf.Append(obj.stream.Length);
     pdf.Append('\n');
     pdf.Append(">>\n");
     pdf.Append("stream\n");
     pdf.Append(obj.stream, 0, obj.stream.Length);
     pdf.Append("\nendstream\n");
     pdf.endobj();
     pdf.images.Add(this);
     objNumber = pdf.objNumber;
 }
예제 #2
0
        // Constructor for standard fonts
        public Font(PDF pdf, String fontName)
        {
            this.pdf  = pdf;
            this.name = fontName;

            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type1\n");
            pdf.Append("/BaseFont /");
            pdf.Append(fontName);
            pdf.Append('\n');
            if (fontName.Equals("Symbol") || fontName.Equals("ZapfDingbats"))
            {
                // Use the built-in encoding
            }
            else
            {
                pdf.Append("/Encoding /WinAnsiEncoding\n");
            }
            pdf.Append(">>\n");
            pdf.endobj();
            objNumber = pdf.objNumber;

            CoreFont font = (CoreFont)Activator.CreateInstance(Type.GetType("PDFjet.NET." + name.Replace('-', '_')));

            bBoxLLx     = font.getBBoxLLx();
            bBoxLLy     = font.getBBoxLLy();
            bBoxURx     = font.getBBoxURx();
            bBoxURy     = font.getBBoxURy();
            metrics     = font.getMetrics();
            ascent      = bBoxURy * size / unitsPerEm;
            descent     = bBoxLLy * size / unitsPerEm;
            body_height = ascent - descent;

            fontUnderlineThickness = font.getUnderlineThickness();
            fontUnderlinePosition  = font.getUnderlinePosition();

            underlineThickness = fontUnderlineThickness * size / unitsPerEm;
            underlinePosition  = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2.0;

            pdf.fonts.Add(this);
        }
예제 #3
0
 private void addImage(
     PDF pdf,
     byte[] data,
     int imageType,
     String colorSpace,
     int bitsPerComponent)
 {
     // Add the image
     pdf.newobj();
     pdf.Append("<<\n");
     pdf.Append("/Type /XObject\n");
     pdf.Append("/Subtype /Image\n");
     if (imageType == ImageType.JPEG)
     {
         pdf.Append("/Filter /DCTDecode\n");
     }
     else if (imageType == ImageType.PNG || imageType == ImageType.BMP)
     {
         pdf.Append("/Filter /FlateDecode\n");
     }
     pdf.Append("/Width ");
     pdf.Append(( int )w);
     pdf.Append('\n');
     pdf.Append("/Height ");
     pdf.Append(( int )h);
     pdf.Append('\n');
     pdf.Append("/ColorSpace /");
     pdf.Append(colorSpace);
     pdf.Append('\n');
     pdf.Append("/BitsPerComponent ");
     pdf.Append(bitsPerComponent);
     pdf.Append('\n');
     pdf.Append("/Length ");
     pdf.Append(data.Length);
     pdf.Append('\n');
     pdf.Append(">>\n");
     pdf.Append("stream\n");
     pdf.Append(data, 0, data.Length);
     pdf.Append("\nendstream\n");
     pdf.endobj();
     pdf.images.Add(this);
     objNumber = pdf.objNumber;
 }
예제 #4
0
        // Constructor for CJK fonts
        public Font(PDF pdf, String fontName, int codePage)
        {
            this.pdf      = pdf;
            this.name     = fontName;
            this.codePage = codePage;
            isCJK         = true;
            isStandard    = false;
            isComposite   = true;

            firstChar = 0x0020;
            lastChar  = 0xFFEE;

            // Font Descriptor
            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /FontDescriptor\n");
            pdf.Append("/FontName /");
            pdf.Append(fontName);
            pdf.Append('\n');
            pdf.Append("/Flags 4\n");
            pdf.Append("/FontBBox [0 0 0 0]\n");
            pdf.Append(">>\n");
            pdf.endobj();

            // CIDFont Dictionary
            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /CIDFontType0\n");
            pdf.Append("/BaseFont /");
            pdf.Append(fontName);
            pdf.Append('\n');
            pdf.Append("/FontDescriptor ");
            pdf.Append(pdf.objNumber - 1);
            pdf.Append(" 0 R\n");
            pdf.Append("/CIDSystemInfo <<\n");
            pdf.Append("/Registry (Adobe)\n");
            if (fontName.StartsWith("AdobeMingStd"))
            {
                pdf.Append("/Ordering (CNS1)\n");
                pdf.Append("/Supplement 4\n");
            }
            else if (fontName.StartsWith("AdobeSongStd"))
            {
                pdf.Append("/Ordering (GB1)\n");
                pdf.Append("/Supplement 4\n");
            }
            else if (fontName.StartsWith("KozMinPro"))
            {
                pdf.Append("/Ordering (Japan1)\n");
                pdf.Append("/Supplement 4\n");
            }
            else if (fontName.StartsWith("AdobeMyungjoStd"))
            {
                pdf.Append("/Ordering (Korea1)\n");
                pdf.Append("/Supplement 1\n");
            }
            else
            {
                throw new Exception("Unsupported font: " + fontName);
            }
            pdf.Append(">>\n");
            pdf.Append(">>\n");
            pdf.endobj();

            // Type0 Font Dictionary
            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type0\n");
            pdf.Append("/BaseFont /");
            if (fontName.StartsWith("AdobeMingStd"))
            {
                pdf.Append(fontName + "-UniCNS-UTF16-H\n");
                pdf.Append("/Encoding /UniCNS-UTF16-H\n");
            }
            else if (fontName.StartsWith("AdobeSongStd"))
            {
                pdf.Append(fontName + "-UniGB-UTF16-H\n");
                pdf.Append("/Encoding /UniGB-UTF16-H\n");
            }
            else if (fontName.StartsWith("KozMinPro"))
            {
                pdf.Append(fontName + "-UniJIS-UCS2-H\n");
                pdf.Append("/Encoding /UniJIS-UCS2-H\n");
            }
            else if (fontName.StartsWith("AdobeMyungjoStd"))
            {
                pdf.Append(fontName + "-UniKS-UCS2-H\n");
                pdf.Append("/Encoding /UniKS-UCS2-H\n");
            }
            else
            {
                throw new Exception("Unsupported font: " + fontName);
            }
            pdf.Append("/DescendantFonts [");
            pdf.Append(pdf.objNumber - 1);
            pdf.Append(" 0 R]\n");
            pdf.Append(">>\n");
            pdf.endobj();
            objNumber = pdf.objNumber;

            ascent      = size;
            descent     = -ascent / 4;
            body_height = ascent - descent;

            pdf.fonts.Add(this);
        }
예제 #5
0
        // Constructor for standard fonts
        public Font(PDF pdf, String fontName)
        {
            this.pdf = pdf;
            this.name = fontName;

            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type1\n");
            pdf.Append("/BaseFont /");
            pdf.Append(fontName);
            pdf.Append('\n');
            if (fontName.Equals("Symbol") || fontName.Equals("ZapfDingbats")) {
            // Use the built-in encoding
            } else {
            pdf.Append("/Encoding /WinAnsiEncoding\n");
            }
            pdf.Append(">>\n");
            pdf.endobj();
            objNumber = pdf.objNumber;

            CoreFont font = (CoreFont) Activator.CreateInstance(Type.GetType("PDFjet.NET." + name.Replace('-', '_')));
            bBoxLLx = font.getBBoxLLx();
            bBoxLLy = font.getBBoxLLy();
            bBoxURx = font.getBBoxURx();
            bBoxURy = font.getBBoxURy();
            metrics = font.getMetrics();
            ascent = bBoxURy * size / unitsPerEm;
            descent = bBoxLLy * size / unitsPerEm;
            body_height = ascent - descent;

            fontUnderlineThickness = font.getUnderlineThickness();
            fontUnderlinePosition = font.getUnderlinePosition();

            underlineThickness = fontUnderlineThickness * size / unitsPerEm;
            underlinePosition = fontUnderlinePosition * size / -unitsPerEm + underlineThickness / 2.0;

            pdf.fonts.Add(this);
        }
예제 #6
0
        // Constructor for CJK fonts
        public Font(PDF pdf, String fontName, int codePage)
        {
            this.pdf = pdf;
            this.name = fontName;
            this.codePage = codePage;
            isCJK = true;
            isStandard = false;
            isComposite = true;

            firstChar = 0x0020;
            lastChar = 0xFFEE;

            // Font Descriptor
            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /FontDescriptor\n");
            pdf.Append("/FontName /");
            pdf.Append(fontName);
            pdf.Append('\n');
            pdf.Append("/Flags 4\n");
            pdf.Append("/FontBBox [0 0 0 0]\n");
            pdf.Append(">>\n");
            pdf.endobj();

            // CIDFont Dictionary
            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /CIDFontType0\n");
            pdf.Append("/BaseFont /");
            pdf.Append(fontName);
            pdf.Append('\n');
            pdf.Append("/FontDescriptor ");
            pdf.Append(pdf.objNumber - 1);
            pdf.Append(" 0 R\n");
            pdf.Append("/CIDSystemInfo <<\n");
            pdf.Append("/Registry (Adobe)\n");
            if (fontName.StartsWith("AdobeMingStd")) {
            pdf.Append("/Ordering (CNS1)\n");
            pdf.Append("/Supplement 4\n");
            } else if (fontName.StartsWith("AdobeSongStd")) {
            pdf.Append("/Ordering (GB1)\n");
            pdf.Append("/Supplement 4\n");
            } else if (fontName.StartsWith("KozMinPro")) {
            pdf.Append("/Ordering (Japan1)\n");
            pdf.Append("/Supplement 4\n");
            } else if (fontName.StartsWith("AdobeMyungjoStd")) {
            pdf.Append("/Ordering (Korea1)\n");
            pdf.Append("/Supplement 1\n");
            } else {
            throw new Exception("Unsupported font: " + fontName);
            }
            pdf.Append(">>\n");
            pdf.Append(">>\n");
            pdf.endobj();

            // Type0 Font Dictionary
            pdf.newobj();
            pdf.Append("<<\n");
            pdf.Append("/Type /Font\n");
            pdf.Append("/Subtype /Type0\n");
            pdf.Append("/BaseFont /");
            if (fontName.StartsWith("AdobeMingStd")) {
            pdf.Append(fontName + "-UniCNS-UTF16-H\n");
            pdf.Append("/Encoding /UniCNS-UTF16-H\n");
            } else if (fontName.StartsWith("AdobeSongStd")) {
            pdf.Append(fontName + "-UniGB-UTF16-H\n");
            pdf.Append("/Encoding /UniGB-UTF16-H\n");
            } else if (fontName.StartsWith("KozMinPro")) {
            pdf.Append(fontName + "-UniJIS-UCS2-H\n");
            pdf.Append("/Encoding /UniJIS-UCS2-H\n");
            } else if (fontName.StartsWith("AdobeMyungjoStd")) {
            pdf.Append(fontName + "-UniKS-UCS2-H\n");
            pdf.Append("/Encoding /UniKS-UCS2-H\n");
            } else {
            throw new Exception("Unsupported font: " + fontName);
            }
            pdf.Append("/DescendantFonts [");
            pdf.Append(pdf.objNumber - 1);
            pdf.Append(" 0 R]\n");
            pdf.Append(">>\n");
            pdf.endobj();
            objNumber = pdf.objNumber;

            ascent = size;
            descent = -ascent/4;
            body_height = ascent - descent;

            pdf.fonts.Add(this);
        }
예제 #7
0
 private void addImage(
     PDF pdf,
     byte[] data,
     int imageType,
     String colorSpace,
     int bitsPerComponent)
 {
     // Add the image
     pdf.newobj();
     pdf.Append("<<\n");
     pdf.Append("/Type /XObject\n");
     pdf.Append("/Subtype /Image\n");
     if (imageType == ImageType.JPEG) {
     pdf.Append("/Filter /DCTDecode\n");
     }
     else if (imageType == ImageType.PNG || imageType == ImageType.BMP) {
     pdf.Append("/Filter /FlateDecode\n");
     }
     pdf.Append("/Width ");
     pdf.Append(( int ) w);
     pdf.Append('\n');
     pdf.Append("/Height ");
     pdf.Append(( int ) h);
     pdf.Append('\n');
     pdf.Append("/ColorSpace /");
     pdf.Append(colorSpace);
     pdf.Append('\n');
     pdf.Append("/BitsPerComponent ");
     pdf.Append(bitsPerComponent);
     pdf.Append('\n');
     pdf.Append("/Length ");
     pdf.Append(data.Length);
     pdf.Append('\n');
     pdf.Append(">>\n");
     pdf.Append("stream\n");
     pdf.Append(data, 0, data.Length);
     pdf.Append("\nendstream\n");
     pdf.endobj();
     pdf.images.Add(this);
     objNumber = pdf.objNumber;
 }
예제 #8
0
 public Image(PDF pdf, PDFobj obj)
 {
     pdf.newobj();
     pdf.Append("<<\n");
     pdf.Append("/Type /XObject\n");
     pdf.Append("/Subtype /Image\n");
     pdf.Append("/Filter ");
     pdf.Append(obj.getValue(PDFobj.FILTER));
     pdf.Append('\n');
     pdf.Append("/Width ");
     pdf.Append(obj.getValue(PDFobj.WIDTH));
     pdf.Append('\n');
     pdf.Append("/Height ");
     pdf.Append(obj.getValue(PDFobj.HEIGHT));
     pdf.Append('\n');
     pdf.Append("/ColorSpace ");
     pdf.Append(obj.getValue(PDFobj.COLORSPACE));
     pdf.Append('\n');
     pdf.Append("/BitsPerComponent ");
     pdf.Append(obj.getValue(PDFobj.BITSPERCOMPONENT));
     pdf.Append('\n');
     pdf.Append("/Length ");
     pdf.Append(obj.stream.Length);
     pdf.Append('\n');
     pdf.Append(">>\n");
     pdf.Append("stream\n");
     pdf.Append(obj.stream, 0, obj.stream.Length);
     pdf.Append("\nendstream\n");
     pdf.endobj();
     pdf.images.Add(this);
     objNumber = pdf.objNumber;
 }