change pdf image background using Itextsharp - itext

I am trying to change background color of all images of pdf using Itextshap.
How can i loop through all images and change background color of the images
I used below code to extract pdf images
public static void ExtractImagesFromPDF(string sourcePdf, string outputPath)
{
// NOTE: This will only get the first image it finds per page.
PdfReader pdf = new PdfReader(sourcePdf);
RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(sourcePdf);
try
{
for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++)
{
PdfDictionary pg = pdf.GetPageN(pageNumber);
// recursively search pages, forms and groups for images.
PdfObject obj = FindImageInPDFDictionary(pg);
if (obj != null)
{
int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture));
PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);
PdfStream pdfStrem = (PdfStream)pdfObj;
byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem);
if ((bytes != null))
{
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes))
{
memStream.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(memStream);
// must save the file while stream is open.
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
string path = Path.Combine(outputPath, String.Format(#"{0}.jpg", pageNumber));
System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0);
System.Drawing.Imaging.ImageCodecInfo jpegEncoder = Utilities.GetImageEncoder("JPEG");
img.Save(path, jpegEncoder, parms);
}
}
}
}
}
catch
{
throw;
}
finally
{
pdf.Close();
raf.Close();
}
}
private static PdfObject FindImageInPDFDictionary(PdfDictionary pg)
{
PdfDictionary res =
(PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES));
PdfDictionary xobj =
(PdfDictionary)PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT));
if (xobj != null)
{
foreach (PdfName name in xobj.Keys)
{
PdfObject obj = xobj.Get(name);
if (obj.IsIndirect())
{
PdfDictionary tg = (PdfDictionary)PdfReader.GetPdfObject(obj);
PdfName type =
(PdfName)PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE));
//image at the root of the pdf
if (PdfName.IMAGE.Equals(type))
{
return obj;
}// image inside a form
else if (PdfName.FORM.Equals(type))
{
return FindImageInPDFDictionary(tg);
} //image inside a group
else if (PdfName.GROUP.Equals(type))
{
return FindImageInPDFDictionary(tg);
}
}
}
}
return null;
}
Many thanks in advance

Related

to upload two(photo and signature) image only in database from one page using c#

There is a page where I've to upload and view photo and signature (the snapshot of the page is attached )but whenever i click the view button the path to the image gets clear and the binary format of the image is saved something like 0x(only this much is saved in database nothing else) format in the database .And the 2nd thing is that both photo and signature are to be seen individually without saving in database.please suggest me a solution for this please.
code
protected void pichck()
{
string picextension = System.IO.Path.GetExtension(imgflup.PostedFile.FileName.ToString()).ToLower();
fs = imgflup.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
picbyte = br.ReadBytes((Int32)fs.Length);
byte[] picarray=new byte[]{255,216,255};
//Boolean match = true;
//int i;
//for (i = 0; i <= picarray.Length - 1;i=i+1 )
//{
// if(picarray[i]!=picbyte[i])
// {
// match = false;
// break;
// }
//}
//if (match == true)
//{
if (picextension == ".jpg" || picextension == ".jpeg")
{
if (imgflup.HasFile == true)
{
if (imgflup.PostedFile.ContentLength < 20000 & imgflup.PostedFile.ContentLength > 50000)
{
Response.Write("<script>alert('the file should be of size 20 mb to 50mb ')</script>");
check();
return;
}
else
{
string base64String = Convert.ToBase64String(picbyte, 0, picbyte.Length);
picimg.ImageUrl = "data:image/png;base64," + base64String;
Label1.Visible = true;
Label1.Visible = true;
Label1.Text = imgflup.PostedFile.FileName;
}
}
//}
else
{
Response.Write("<script>alert('the file should be of jpg or jpeg format')</script>");
check();
return;
}
}
else
{
Response.Write("<script>alert('Please Upload a file')</script>");
check();
return;
}
}
protected void signchckt()
{
string signextension = System.IO.Path.GetExtension(signflup.PostedFile.FileName.ToString()).ToLower();
fs1 = signflup.PostedFile.InputStream;
BinaryReader br1 = new BinaryReader(fs1);
signbyte = br1.ReadBytes((Int32)fs1.Length);
//Boolean match = true;
//int i;
//byte[] signarray=new byte[]{255,216,255};
//for (i = 0; i <= signarray.Length - 1;i=i+1 )
//{
// if(signarray[i]!=signbyte[i])
// {
// match = false;
// break;
// }
//}
//if (match == true)
//{
if (signflup.HasFile == true)
{
if (signextension == ".jpg" || signextension == ".jpeg")
{
if (signflup.PostedFile.ContentLength < 20000 & signflup.PostedFile.ContentLength > 50000)
{
Response.Write("<script>alert('the file should be of size 20 mb to 50mb ')</script>");
check1();
return;
}
else
{
string base64String = Convert.ToBase64String(signbyte, 0, signbyte.Length);
signimg.ImageUrl = "data:image/png;base64," + base64String;
Label2.Visible = true;
Label2.Visible = true;
Label2.Text =signflup.PostedFile.FileName;
}
}
else
{
Response.Write("<script>alert('The signature should be of jpg or jpeg type')</script>");
check1();
return;
}
}
//}
else
{
Response.Write("<script>alert('Please Upload a file')</script>");
check1();
return;
}
}
protected void imgviewbtn_Click(object sender, EventArgs e)
{
pichck();
}
protected void signviewbtn_Click(object sender, EventArgs e)
{
signchckt();
}
protected void updtbtn_Click(object sender, EventArgs e)
{
Int64 aplicationid = Convert.ToInt64(Session["ID"].ToString());
if (Session["ID"].ToString()=="")
{
Response.Write("<script>alert('There is no Application Id')</script>");
Response.Redirect("~/home.aspx");
}
else
{
using (obj.con)
{
pichck();
signchckt();
obj.con.Open();
obj.cmd = new SqlCommand("spPhotoandsignature",obj.con);
obj.cmd.CommandType = System.Data.CommandType.StoredProcedure;
obj.cmd.Parameters.AddWithValue("#Application_Id", aplicationid);
obj.cmd.Parameters.AddWithValue("#Pic_Scan",SqlDbType.Binary).Value =picbyte;
obj.cmd.Parameters.AddWithValue("#Pic_Size", fs);
obj.cmd.Parameters.AddWithValue("#Sign_Scan",SqlDbType.Binary).Value =signbyte;
obj.cmd.Parameters.AddWithValue("#Sign_Size", fs1);
obj.cmd.Parameters.AddWithValue("#Type", System.IO.Path.GetExtension(imgflup.PostedFile.FileName.ToString()).ToLower());
int a= obj.cmd.ExecuteNonQuery();
if (a == 1)
{
Response.Write("<script>alert('your data Submitted successfully')</script>");
Response.Redirect("~/Report.aspx");
}
}
}
}
problempage.png

Read roman page number of page

in Adobe Reader the first pages of a ebook can have roman format page number as shown in attached image below
Image : http://i.stack.imgur.com/GSm0Q.jpg
I would like to read these page numbers out (not the indexed page number) with iText but I don't know which properties (labels or annotations..) I should use. I could already open file with PdfReader, loop through all pages but have no idea what I should access for these roman numbers
using (Stream pdfStream = new FileStream(sourceFileName, FileMode.Open))
{
PdfReader pdfReader = new PdfReader(pdfStream);
for (int index = 1; index <= pdfReader.NumberOfPages; index++)
{
}
}
Thanks.
You are looking for the PageLabelExample. In this example, we have a PDF, page_labels.pdf that has pages numbered like this:
In the listPageLabels() method, we create a txt file with all the page labels:
public void listPageLabels(String src, String dest) throws IOException {
// no PDF, just a text file
PrintStream out = new PrintStream(new FileOutputStream(dest));
PdfReader reader = new PdfReader(src);
String[] labels = PdfPageLabels.getPageLabels(reader);
for (int i = 0; i < labels.length; i++) {
out.println(labels[i]);
}
out.flush();
out.close();
reader.close();
}
The result looks like this:
A
B
1
2
3
Movies-4
Movies-5
Movies-6
Movies-7
Movies-8
If you want an iTextSharp example, take a look at this method:
/**
* Reads the page labels from an existing PDF
* #param src the existing PDF
*/
public string ListPageLabels(byte[] src) {
StringBuilder sb = new StringBuilder();
String[] labels = PdfPageLabels.GetPageLabels(new PdfReader(src));
for (int i = 0; i < labels.Length; i++) {
sb.Append(labels[i]);
sb.AppendLine();
}
return sb.ToString();
}
Update
As promised in the comment section: PdfPageLabels.cs
I am not a C# developer, but this is a quick and dirty version of the GetPageLabels() method that doesn't add a prefix:
public static String[] GetPageLabels(PdfReader reader) {
int n = reader.NumberOfPages;
PdfDictionary dict = reader.Catalog;
PdfDictionary labels = (PdfDictionary)PdfReader.GetPdfObjectRelease(dict.Get(PdfName.PAGELABELS));
if (labels == null)
return null;
String[] labelstrings = new String[n];
Dictionary<int, PdfObject> numberTree = PdfNumberTree.ReadTree(labels);
int pagecount = 1;
char type = 'D';
for (int i = 0; i < n; i++) {
if (numberTree.ContainsKey(i)) {
PdfDictionary d = (PdfDictionary)PdfReader.GetPdfObjectRelease(numberTree[i]);
if (d.Contains(PdfName.ST)) {
pagecount = ((PdfNumber)d.Get(PdfName.ST)).IntValue;
}
else {
pagecount = 1;
}
if (d.Contains(PdfName.S)) {
type = ((PdfName)d.Get(PdfName.S)).ToString()[1];
}
else {
type = 'e';
}
}
switch (type) {
default:
labelstrings[i] = "" + pagecount;
break;
case 'R':
labelstrings[i] = RomanNumberFactory.GetUpperCaseString(pagecount);
break;
case 'r':
labelstrings[i] = RomanNumberFactory.GetLowerCaseString(pagecount);
break;
case 'A':
labelstrings[i] = RomanAlphabetFactory.GetUpperCaseString(pagecount);
break;
case 'a':
labelstrings[i] = RomanAlphabetFactory.GetLowerCaseString(pagecount);
break;
case 'e':
labelstrings[i] = "";
break;
}
pagecount++;
}
return labelstrings;
}

iTextSharp different results on Windows 7 vs Windows 8.1

When I run the following code on Windows 7 and 8.1 I get different results. On Windows 7 if I re-run the code on the newly created file it throws exceptions while the Windows 8.1 code works fine.
Any Clues?????
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string a = #"C:\temp\Materials\20130911134612877_3.pdf";
string b = #"C:\temp\Materials\20130911134612877_4.pdf";
Program p = new Program();
p.Open(a);
p.SaveSource(b);
}
public List<Bitmap> Bitmaps { get; private set; }
private string sourceFileName { get; set; }
private string destPath { get; set; }
public List<int> Source { get; set; }
public List<int> Destination { get; set; }
public void Open(string fileName)
{
this.sourceFileName = fileName;
this.destPath = Path.Combine(Path.GetDirectoryName(fileName), "Processed");
if (!Directory.Exists(destPath))
{
Directory.CreateDirectory(this.destPath);
}
string original = Path.Combine(Path.GetDirectoryName(fileName), "Orginal", Path.GetFileName(fileName));
if (!File.Exists(original))
{
string originalPath = Path.GetDirectoryName(original);
if (!Directory.Exists(originalPath))
{
Directory.CreateDirectory(originalPath);
}
File.Copy(fileName, original);
}
if (this.Bitmaps != null)
{
for (int _i = 0; _i < this.Bitmaps.Count; _i++)
{
this.Bitmaps[_i].Dispose();
}
}
PDFDocument doc = GetDocument(fileName);
this.Bitmaps = new List<Bitmap>();
this.Source = new List<int>();
this.Destination = new List<int>();
for (int i = 0; i < doc.Count; i++)
{
this.Source.Add(i);
this.Bitmaps.Add(doc.GetImage(i));
}
doc.Close();
}
public void SaveSource(string file)
{
if (this.Source.Count != 0)
{
PDFDocument pdf = new PDFDocument();
pdf.FileName = file;
foreach (int i in this.Source)
{
pdf.Add(this.Bitmaps[i]);
}
pdf.Close();
}
else
{
if (File.Exists(this.sourceFileName))
{
File.Delete(this.sourceFileName);
}
}
}
private PDFDocument GetDocument(string file)
{
PDFDocument doc = null;
doc = new PDFDocument();
doc.Open(file);
return doc;
}
public static void MergePdfFiles(IEnumerable<string> files, string output)
{
iTextSharp.text.Document doc;
iTextSharp.text.pdf.PdfCopy pdfCpy;
doc = new iTextSharp.text.Document();
pdfCpy = new iTextSharp.text.pdf.PdfCopy(doc, new System.IO.FileStream(output, System.IO.FileMode.Create));
doc.Open();
foreach (string file in files)
{
// initialize a reader
iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(file);
int pageCount = reader.NumberOfPages;
// set page size for the documents
doc.SetPageSize(reader.GetPageSizeWithRotation(1));
for (int pageNum = 1; pageNum <= pageCount; pageNum++)
{
iTextSharp.text.pdf.PdfImportedPage page = pdfCpy.GetImportedPage(reader, pageNum);
pdfCpy.AddPage(page);
}
reader.Close();
}
doc.Close();
}
}
public class MyImageRenderListener : IRenderListener
{
public void RenderText(TextRenderInfo renderInfo) { }
public void BeginTextBlock() { }
public void EndTextBlock() { }
public Bitmap Image = null;
public void RenderImage(ImageRenderInfo renderInfo)
{
try
{
PdfImageObject image = renderInfo.GetImage();
if (image == null) return;
using (MemoryStream ms = new MemoryStream(image.GetImageAsBytes()))
{
Bitmap i = (System.Drawing.Bitmap)Bitmap.FromStream(ms);
Image = (System.Drawing.Bitmap)i.Clone();
i.Dispose();
// int dpi = i.Height / 11;
int yDPI = Image.Height / 11;
int xDPI = (Image.Width * 2) / 17;
xDPI = Math.Abs(xDPI - 300) < 10 ? 300 : xDPI;
yDPI = Math.Abs(yDPI - 300) < 10 ? 300 : yDPI;
xDPI = Math.Abs(xDPI - 600) < 10 ? 600 : xDPI;
yDPI = Math.Abs(yDPI - 600) < 10 ? 600 : yDPI;
if (xDPI == yDPI)
{
Image.SetResolution(xDPI, yDPI);
}
else
{
}
}
}
catch (IOException)
{
/*
* pass-through; image type not supported by iText[Sharp]; e.g. jbig2
*/
}
}
}
public class PDFDocument
{
public string FileName { get; set; }
~PDFDocument()
{
this.Close();
}
public static void AddImage(Stream inputPdfStream, Stream outputPdfStream, Stream inputImageStream)
{
PdfReader reader = new PdfReader(inputPdfStream);
iTextSharp.text.Rectangle size = reader.GetPageSize(1);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
image.SetAbsolutePosition(size.Width - 98, size.Height - 98);
PdfStamper stamper = new PdfStamper(reader, outputPdfStream);
int page = 1;
// for (int page = 1; page <= reader.NumberOfPages; page++)
{
PdfContentByte pdfContentByte = stamper.GetOverContent(page);
pdfContentByte.AddImage(image);
}
stamper.Close();
}
public void Open(string fileName)
{
this.reader = new PdfReader(fileName);
this.parser = new PdfReaderContentParser(reader);
this.listener = new MyImageRenderListener();
}
public int Count { get { return reader.NumberOfPages; } }
public Bitmap GetImage(int index)
{
parser.ProcessContent(index + 1, listener);
return listener.Image;
}
public Bitmap GetImage2(int index)
{
PdfDictionary page = reader.GetPageN(index + 1);
return GetImagesFromPdfDict(page);
}
private PdfReaderContentParser parser = null;
private MyImageRenderListener listener = null;
private PdfReader reader = null;
private Bitmap GetImagesFromPdfDict(PdfDictionary dict)
{
PdfDictionary res = (PdfDictionary)(PdfReader.GetPdfObject(dict.Get(PdfName.RESOURCES)));
PdfDictionary xobj = (PdfDictionary)(PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT)));
Bitmap bm = null;
if (xobj != null)
{
foreach (PdfName name in xobj.Keys)
{
PdfObject obj = xobj.Get(name);
if (obj.IsIndirect())
{
PdfDictionary tg = (PdfDictionary)(PdfReader.GetPdfObject(obj));
PdfName subtype = (PdfName)(PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE)));
if (PdfName.IMAGE.Equals(subtype))
{
int xrefIdx = ((PRIndirectReference)obj).Number;
PdfObject pdfObj = this.reader.GetPdfObject(xrefIdx);
PRStream str = (PRStream)(pdfObj);
iTextSharp.text.pdf.parser.PdfImageObject pdfImage = new iTextSharp.text.pdf.parser.PdfImageObject(str);
bm = (System.Drawing.Bitmap)pdfImage.GetDrawingImage();
bm.SetResolution(300.0f, 300.0f);
break;
}
else if (PdfName.FORM.Equals(subtype) || PdfName.GROUP.Equals(subtype))
{
GetImagesFromPdfDict(tg);
}
}
}
}
return bm;
}
public void Split(string fileName)
{
throw new NotImplementedException();
}
public void Save(System.Drawing.Bitmap bm, string filename)
{
Save(bm, filename, RotateFlipType.RotateNoneFlipNone);
}
const float PAGE_LEFT_MARGIN = 0;
const float PAGE_RIGHT_MARGIN = 0;
const float PAGE_TOP_MARGIN = 0;
const float PAGE_BOTTOM_MARGIN = 0;
public void Save(System.Drawing.Bitmap bm, string filename, System.Drawing.RotateFlipType rotate)
{
Bitmap image = bm;
if (rotate != RotateFlipType.RotateNoneFlipNone)
{
image.RotateFlip(rotate);
}
using (FileStream stream = new FileStream(filename, FileMode.Create))
{
using (iTextSharp.text.Document pdfDocument = new iTextSharp.text.Document(PageSize.LETTER, PAGE_LEFT_MARGIN, PAGE_RIGHT_MARGIN, PAGE_TOP_MARGIN, PAGE_BOTTOM_MARGIN))
{
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, stream);
pdfDocument.Open();
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms);
img.ScaleToFit(PageSize.LETTER.Width - (PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height - (PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN));
pdfDocument.Add(img);
pdfDocument.Close();
writer.Close();
}
}
}
public void Add(System.Drawing.Bitmap bm)
{
this.Add(bm, RotateFlipType.RotateNoneFlipNone);
}
FileStream stream;
iTextSharp.text.Document pdfDocument;
iTextSharp.text.pdf.PdfWriter writer;
public void Add(System.Drawing.Bitmap bm, System.Drawing.RotateFlipType rotate)
{
if (this.stream == null)
{
this.stream = new FileStream(this.FileName, FileMode.Create);
this.pdfDocument = new iTextSharp.text.Document(PageSize.LETTER, PAGE_LEFT_MARGIN, PAGE_RIGHT_MARGIN, PAGE_TOP_MARGIN, PAGE_BOTTOM_MARGIN);
this.writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDocument, stream);
this.pdfDocument.Open();
}
Bitmap image = bm;
if (rotate != RotateFlipType.RotateNoneFlipNone)
{
image.RotateFlip(rotate);
}
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
ms.Seek(0, SeekOrigin.Begin);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms);
img.ScaleToFit(PageSize.LETTER.Width - (PAGE_LEFT_MARGIN + PAGE_RIGHT_MARGIN), PageSize.LETTER.Height - (PAGE_TOP_MARGIN + PAGE_BOTTOM_MARGIN));
pdfDocument.Add(img);
}
}
public void Close()
{
if (this.pdfDocument != null)
{
this.pdfDocument.Close();
this.pdfDocument.Dispose();
this.writer.Close();
this.writer.Dispose();
this.stream.Close();
this.stream.Dispose();
this.pdfDocument = null;
this.writer = null;
this.pdfDocument = null;
}
if (this.reader != null)
{
this.reader.Close();
}
}
public void Tag(string oldFile, Stream fs, string text)
{
float x;
float y;
// open the reader
PdfReader reader = new PdfReader(oldFile);
iTextSharp.text.Rectangle size = reader.GetPageSizeWithRotation(1);
float height = 60;
float width = 150;
x = size.Width - 40 - width;
y = size.Height - height;
Document document = new Document(size);
// open the writer
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
// the pdf content
PdfContentByte cb = writer.DirectContent;
// create the new page and add it to the pdf
PdfImportedPage page = writer.GetImportedPage(reader, 1);
cb.AddTemplate(page, 0, 0);
cb.Rectangle(x, y, width, height);
cb.SetColorFill(BaseColor.WHITE);
cb.Fill();
// close the streams and voilá the file should be changed :)
// write the text in the pdf content
cb.BeginText();
// select the font properties
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(BaseColor.BLACK);
cb.SetFontAndSize(bf, 20);
// put the alignment and coordinates here
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, x + 5, y + 10, 0);
cb.EndText();
writer.Flush();
document.Close();
reader.Close();
// fs.Seek(0, SeekOrigin.Begin);
}
}
}

Extracted images from PDF using iTextsharp not in correct format - C#

I am using iTextsharp to extract images from the PDF file, i am able to extract images but the extracted images are not in correct format (i.e. it looks like negative proof).
Code:
string sFilePath = "Test3.pdf";
int pageNum = 1;
PdfReader pdf = new PdfReader(sFilePath);
PdfDictionary pg = pdf.GetPageN(pageNum);
PdfDictionary res = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES));
PdfDictionary xobj = (PdfDictionary)PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT));
if (xobj == null) { return; }
int imageCount = 0;
foreach (PdfName name in xobj.Keys)
{
PdfObject obj = xobj.Get(name);
if (!obj.IsIndirect()) { continue; }
PdfDictionary tg = (PdfDictionary)PdfReader.GetPdfObject(obj);
PdfName type = (PdfName)PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE));
if (!type.Equals(PdfName.IMAGE)) { continue; }
int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture));
PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);
PdfStream pdfStrem = (PdfStream)pdfObj;
byte[] bytes = PdfReader.GetStreamBytesRaw((PRStream)pdfStrem);
if (bytes == null) { continue; }
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytes))
{
try
{
memStream.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(memStream);
if (!Directory.Exists(imgPath))
Directory.CreateDirectory(imgPath);
string path = Path.Combine(imgPath, String.Format(#"{0}.jpg", ++imageCount));
System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0);
var jpegEncoder = ImageCodecInfo.GetImageEncoders().ToList().Find(x => x.FormatID == ImageFormat.Jpeg.Guid);
img.Save(path, jpegEncoder, parms);
}
catch (Exception ex)
{
}
}
}

Using a external Spinner control in Windows Mobile 6.0

I am using slideUI controls in my project . There is a spinner control which is used as wait cursor. I want to display the spinner when I load data in a List.
But when I try to display the spinner it visualize as an image not a rotating image.
Below is my code.
private void uiButton_Click(object sender, EventArgs e)
{
ShowFrame(this.uiPanel1);
Application.DoEvents();
LoadList();
HideFrame(uiPanel1);
}
private void LoadList()
{
try
{
//Call the BeginAddControls before starting manipulations with UIList
uiList1.BeginAddControls();
for (int i = 0; i < 100; i++)
{
UIListItem item = new UIListItem();
item.Text = "Primary Text" + i;
item.SecondaryText = "This is secondary text..";
item.ItemStyle = UIListItemStyle.SingleText;
item.Height = Utils.CalcScaleSize(38);
item.BackColor = System.Drawing.SystemColors.Window;
item.BackEndColorSelected = System.Drawing.SystemColors.Highlight;
item.BackStartColorSelected = System.Drawing.SystemColors.Highlight;
item.BottomBorderColor = System.Drawing.Color.Gainsboro;
item.Buffering = true;
item.ColorScheme = SlideUI.UIColorSchemesCustom.Orange;
item.Dock = System.Windows.Forms.DockStyle.Top;
item.GroupArrowColor = System.Drawing.Color.Gray;
item.GroupArrowColorSelected = System.Drawing.Color.White;
item.IconQVGA = null;
item.IconSize = new System.Drawing.Size(25, 31);
item.IconTransparent = false;
item.IconTransparentColor = System.Drawing.Color.Transparent;
item.IconVGA = null;
item.IconVisible = true;
item.InheritParentSettings = true;
item.IsGroup = false;
item.IsSelected = false;
item.SecondaryTextColor = System.Drawing.SystemColors.GrayText;
item.SecondaryTextColorSelected = System.Drawing.SystemColors.HighlightText;
item.SecondaryTextFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Regular);
item.TextColor = System.Drawing.SystemColors.WindowText;
item.TextColorSelected = System.Drawing.SystemColors.HighlightText;
item.TextFont = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold);
item.UseGradient = true;
item.VirtualBufferRendered = false;
uiList1.AddControl(item);
}
//Call of EndAddControls method when the UIListItems binding is done
uiList1.EndAddControls();
//HideFrame(uiPanel1);
//ShowFrame(this.panel1, "Panel1");
}
catch (Exception ex)
{
UIMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK,
UIMessageIcons.Done, UIColorSchemesCustom.Orange);
}
}
private void ShowFrame(Panel panel)
{
Panel pnlPanel = new Panel();
pnlPanel = panel;
//pnlPanel.Location = new System.Drawing.Point(0, 0);
pnlPanel.Show();
pnlPanel.BringToFront();
}
private void HideFrame(Panel panel)
{
Panel pnlPanel = new Panel();
pnlPanel = panel;
pnlPanel.Hide();
}
Thanks in advance