//------------------------------------------------------------------------------------------xx.02.2006 /// <summary>Writes the RepObj to the buffer.</summary> /// <param name="e">Environment data</param> public void Write(PdfIndirectObject_PageContents.Environment e) { PdfIndirectObject_PageContents p = e.pdfIndirectObject_PageContents; RepImage repImage = (RepImage)e.repObj; Double rOfsX = repImage.rWidth * repImage.rAlignH; Double rOfsY = repImage.rHeight * (1 - repImage.rAlignV); e.matrixD.Multiply(new MatrixD(1, 0, 0, 1, -rOfsX, rOfsY)); e.matrixD.Scale(repImage.rWidth, repImage.rHeight); p.Command("q"); p.Write_Matrix(e.matrixD); p.Command("cm"); PdfIndirectObject_ImageJpeg pdfIndirectObject_ImageJpeg = (PdfIndirectObject_ImageJpeg)repImage.imageData.oImageResourceX; p.Name("I" + pdfIndirectObject_ImageJpeg.iObjectNumber); p.Command("Do"); p.Command("Q"); }
//------------------------------------------------------------------------------------------xx.02.2006 /// <summary>Writes the object to the buffer.</summary> internal override void Write() { StartObj(); Dictionary_Start(); Dictionary_Key("Type"); Name("Page"); Dictionary_Key("Parent"); IndirectReference(pdfFormatter.pdfIndirectObject_Pages); Dictionary_Key("Resources"); Dictionary_Start(); Dictionary_Key("ProcSet"); ArrayStart(); if (bProcSet_Text) { Name("Text"); } if (bProcSet_PDF) { Space(); Name("PDF"); } if (bProcSet_ImageB) { Space(); Name("ImageB"); } if (bProcSet_ImageC) { Space(); Name("ImageC"); } if (bProcSet_ImageI) { Space(); Name("ImageI"); } ArrayEnd(); Dictionary_Key("Font"); Dictionary_Start(); foreach (FontData fontData in dict_FontData.Values) { PdfIndirectObject_Font pdfIndirectObject_Font = (PdfIndirectObject_Font)fontData.oFontDataX; Dictionary_Key("F" + pdfIndirectObject_Font.iObjectNumber); IndirectReference(pdfIndirectObject_Font); } Dictionary_End(); if (report.ht_ImageData.Count > 0) { Dictionary_Key("XObject"); Dictionary_Start(); foreach (ImageData imageData in report.ht_ImageData.Values) { PdfIndirectObject_ImageJpeg pdfIndirectObject_ImageJpeg = (PdfIndirectObject_ImageJpeg)imageData.oImageResourceX; Dictionary_Key("I" + pdfIndirectObject_ImageJpeg.iObjectNumber); IndirectReference(pdfIndirectObject_ImageJpeg); } Dictionary_End(); } Dictionary_End(); Dictionary_Key("MediaBox"); ArrayStart(); Number(0); Space(); Number(0); Space(); Number(page.rWidth); Space(); Number(page.rHeight); ArrayEnd(); Dictionary_Key("CropBox"); ArrayStart(); Number(0); Space(); Number(0); Space(); Number(page.rWidth); Space(); Number(page.rHeight); ArrayEnd(); //Dictionary_Key("Rotate"); Number(0); // !!! Dictionary_Key("Contents"); IndirectReference(pdfIndirectObject_PageContents); Dictionary_End(); EndObj(); }
//------------------------------------------------------------------------------------------xx.01.2006 #region old //---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------x /// <summary>Builds the xref structure.</summary> private void BuildXObjectsX() { // foreach (ImageData imageData in report.ht_ImageData.Values) { // imageData.stream.Position = 0; // //Added By TechnoGuru - [email protected] - http://www.borie.org/ // using(Image image = Image.FromStream(imageData.stream)) { // // Tiff support // //Added By TechnoGuru - [email protected] - http://www.borie.org/ // if(image.RawFormat.Equals(ImageFormat.Tiff)) { // NewObjId(); // Debug.Assert(iObjIdCur == (Int32)imageData.object_Data, "invalid object id of viewer preferences object"); // WriteLine((Int32)imageData.object_Data + " 0 obj"); // WriteLine("<<"); // WriteLine("/Type /XObject"); // WriteLine("/Subtype /Image"); // WriteLine("/Name /I" + (Int32)imageData.object_Data); // WriteLine("/Width " + image.Width); // WriteLine("/Height " + image.Height); // //Int32 iImageStart = 0; // //Int32 iImageLength = 0; // //ImageFormat imageFormat = imageData.image.RawFormat; // //if (Object.Equals(imageFormat, ImageFormat.Jpeg)) { // // iImageLength = (Int32)imageData.stream.Length; // // WriteLine("/Filter /DCTDecode"); // //} // else if (Object.Equals(imageFormat, ImageFormat.Tiff)) { // imageData.stream.Position = 0; // BinaryReader br = new BinaryReader(imageData.stream); // br.BaseStream.Position = 4; // Int32 iPointer = br.ReadInt32(); // br.BaseStream.Position = iPointer; // Int16 nTagCount = br.ReadInt16(); // Int32 iImage = 0; // Int32 iRows = 0; // Int32 iStripByteCounts = 0; // while (nTagCount > 0) { // Int16 nTagType = br.ReadInt16(); // Int16 nDataType = br.ReadInt16(); // Int32 iLength = br.ReadInt32(); // Int32 iData = br.ReadInt32(); // if (nTagType == 259) { // Compression // if (iData == 1) { // } // else if (iData == 5) { // //WriteLine("/Filter /LZWDecode"); // //WriteLine("/Filter /CCITTFaxDecode"); //changed // } // else { // Debug.Fail("unknown compression"); // } // } // else if (nTagType == 262) { // Photometric Interpretation // //Debug.Assert(iData == 2); // RGB-Compression // } // else if (nTagType == 273) { // Strip Offset // iImage = iData; // iRows = iLength; // } // else if (nTagType == 279) { // Strip Byte Counts // iStripByteCounts = iData; // } // else if (nTagType == 317) { // Predictor // Debug.Assert(iData == 2); // Horizontal Predictor // //WriteLine("/DecodeParms [<< /Predictor 2 >>]"); // } // nTagCount--; // } // iPointer = br.ReadInt32(); // // br.BaseStream.Position = iImage; // iImageStart = br.ReadInt32(); // br.BaseStream.Position = iImage + (iRows - 1) * 4; // iImageLength = br.ReadInt32() - iImageStart; // // br.BaseStream.Position = iStripByteCounts + (iRows - 1) * 4; // Int32 iStripLength = br.ReadInt32(); // iImageLength += iStripLength; // // Console.WriteLine(""); // // } // else { // Debug.Fail("unknown image type: send image to [email protected]"); // } // Int32 iBitsPerComponent = 0; // String sColorSpace = null; // if (imageData.image.PixelFormat == PixelFormat.Format8bppIndexed) { // iBitsPerComponent = 8; // sColorSpace = "DeviceGray"; // } // else if (imageData.image.PixelFormat == PixelFormat.Format1bppIndexed) { // iBitsPerComponent = 1; // sColorSpace = "DeviceGray"; // } // else if (imageData.image.PixelFormat == PixelFormat.Format24bppRgb) { // iBitsPerComponent = 8; // sColorSpace = "DeviceRGB"; // } // else { // Debug.Fail("unknown image format: send image to [email protected]"); // } // WriteLine("/BitsPerComponent " + iBitsPerComponent.ToString()); // WriteLine("/ColorSpace /" + sColorSpace); // WriteLine("/Length " + iImageLength.ToString()); // WriteLine(">>"); // WriteLine("stream"); // FlushBuffer(); // // imageData.stream.Position = 0; // BinaryReader r = new BinaryReader(imageData.stream); // if (iImageStart > 0) { // r.BaseStream.Position = iImageStart; // } // Byte[] aByte = r.ReadBytes(iImageLength); // r.Close(); // // //stream.Flush(); // bufferedStream.Write(aByte, 0, aByte.Length); // iBytesWrittenToStream += aByte.Length; // WriteLine("\nendstream"); // WriteLine("endobj"); // } foreach (ImageData imageData in report.ht_ImageData.Values) { imageData.stream.Position = 0; //Added By TechnoGuru - [email protected] - http://www.borie.org/ #if !WindowsCE using (Image image = Image.FromStream(imageData.stream)) { // Tiff support //Added By TechnoGuru - [email protected] - http://www.borie.org/ if (image.RawFormat.Equals(ImageFormat.Tiff)) { // NewObjId(); PdfIndirectObject_ImageJpeg pdfIndirectObject_ImageJpeg = (PdfIndirectObject_ImageJpeg)imageData.oImageResourceX; WriteLine(pdfIndirectObject_ImageJpeg.iObjectNumber + " 0 obj"); WriteLine("<<"); WriteLine("/Type /XObject"); WriteLine("/Subtype /Image"); WriteLine("/Name /I" + pdfIndirectObject_ImageJpeg.iObjectNumber); WriteLine("/Width " + image.Width); WriteLine("/Height " + image.Height); // Handle B&W format with CCIT if (image.PixelFormat.Equals(PixelFormat.Format1bppIndexed)) { imageData.stream.Position = 0; BinaryReader r = new BinaryReader(imageData.stream); //CCIT 4 //This String contain the startinf sequence of the tiff file for CCIT 4 string patternTiffFile = "ÿÿÿÿÿÿÿÿÿ"; string startTiffFile = ""; int index = 0; int i = 0; for (index = 0; index < 2048; index++) { startTiffFile += (char)(((i = r.ReadByte()) == 0?1:i)); } int startPositionTiff = startTiffFile.IndexOf(patternTiffFile); //CCIT 3 if (startPositionTiff == -1) { //This String contain the startinf sequence of the tiff file for CCIT 3 patternTiffFile = "Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ Õ"; startPositionTiff = startTiffFile.IndexOf(patternTiffFile); WriteLine("/Filter [/CCITTFaxDecode]"); WriteLine("/DecodeParms [<< /Columns " + image.Width + " /Rows " + image.Height + " /EndOfBlock false/EncodedByteAlign true >>]"); // This line was added to support TIFF } else { WriteLine("/Filter /CCITTFaxDecode"); WriteLine("/DecodeParms << /K -1 /Columns " + image.Width + " >>"); // This line was added to support TIFF } if (startPositionTiff == -1) { startPositionTiff = 512; } WriteLine("/BitsPerComponent 1"); WriteLine("/ColorSpace /DeviceGray"); Int64 lLength = imageData.stream.Length; WriteLine("/Length " + (lLength - startPositionTiff).ToString()); // CHANGED WriteLine(">>"); WriteLine("stream"); FlushBuffer(); imageData.stream.Position = 0; r.ReadBytes((Int32)startPositionTiff); Byte[] aByte = r.ReadBytes((Int32)lLength - startPositionTiff); // CHANGED r.Close(); //stream.Flush(); bufferedStream.Write(aByte, 0, aByte.Length); iBytesWrittenToStream += aByte.Length; WriteLine("\nendstream"); WriteLine("endobj"); } else if (image.PixelFormat.Equals(PixelFormat.Format4bppIndexed)) { //Not supported I don't have tiff file to test it =) // WriteLine("/Filter /CCITTFaxDecode"); // WriteLine("/DecodeParms << /K -1 /Columns " + image.Width + " >>"); // This line was added to support TIFF // WriteLine("/BitsPerComponent 4"); // WriteLine("/ColorSpace /DeviceGray"); } else { //Tiff in gray or color are converted as jpeg in the tiff MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Jpeg); Byte[] aByte = ms.GetBuffer(); WriteLine("/BitsPerComponent 8"); WriteLine("/ColorSpace /DeviceRGB"); WriteLine("/Filter /DCTDecode"); WriteLine("/Length " + (aByte.Length).ToString()); // CHANGED WriteLine(">>"); WriteLine("stream"); FlushBuffer(); bufferedStream.Write(aByte, 0, aByte.Length); iBytesWrittenToStream += aByte.Length; WriteLine("\nendstream"); WriteLine("endobj"); } } imageData.stream.Close(); imageData.stream = null; } #endif } }