Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:49:05+00:00 2026-05-27T02:49:05+00:00

I am successfully able to extract images from a pdf using pdfsharp. The image

  • 0

I am successfully able to extract images from a pdf using pdfsharp. The image are of CCITFFaxDecode. But in the tiff image created , the image is getting rotated. Any idea what might be going wrong?

This is the code im using :

byte[] data = xObject.Stream.Value;
Tiff tiff = BitMiracle.LibTiff.Classic.Tiff.Open("D:\\clip_TIFF.tif", "w");
tiff.SetField(TiffTag.IMAGEWIDTH, (uint)(width));
tiff.SetField(TiffTag.IMAGELENGTH, (uint)(height));
tiff.SetField(TiffTag.COMPRESSION, (uint)BitMiracle.LibTiff.Classic.Compression.CCITTFAX4);
tiff.SetField(TiffTag.BITSPERSAMPLE, (uint)(bpp));
tiff.WriteRawStrip(0,data,data.Length);
tiff.Close();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:49:06+00:00Added an answer on May 27, 2026 at 2:49 am

    Since the question is still tagged w/iTextSharp might as add some code, even though it doesn’t look like you’re using the library here. PDF parsing support was added starting in iText[Sharp] 5.

    Didn’t have an test PDF with the image type you’re using, but found one here (see the attachment). Here’s a very simple working example in ASP.NET (HTTP handler .ashx) using that test PDF document to get you going:

    <%@ WebHandler Language="C#" Class="CCITTFaxDecodeExtract" %>
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Web;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using iTextSharp.text.pdf.parser;
    using Dotnet = System.Drawing.Image;
    using System.Drawing.Imaging;
    
    public class CCITTFaxDecodeExtract : IHttpHandler {
      public void ProcessRequest (HttpContext context) {
        HttpServerUtility Server = context.Server;
        HttpResponse Response = context.Response;
        string file = Server.MapPath("~/app_data/CCITTFaxDecode.pdf");
        PdfReader reader = new PdfReader(file);
        PdfReaderContentParser parser = new PdfReaderContentParser(reader);
        MyImageRenderListener listener = new MyImageRenderListener();
        for (int i = 1; i <= reader.NumberOfPages; i++) {
          parser.ProcessContent(i, listener);
        } 
        for (int i = 0; i < listener.Images.Count; ++i) {
          string path = Server.MapPath("~/app_data/" + listener.ImageNames[i]);
          using (FileStream fs = new FileStream(
            path, FileMode.Create, FileAccess.Write
          ))
          {
            fs.Write(listener.Images[i], 0, listener.Images[i].Length);
          }
        }         
      }
      public bool IsReusable { get { return false; } }
    /*
     * see: TextRenderInfo & RenderListener classes here:
     * http://api.itextpdf.com/itext/
     * 
     * and Google "itextsharp extract images"
     */
      public class MyImageRenderListener : IRenderListener {
        public void RenderText(TextRenderInfo renderInfo) { }
        public void BeginTextBlock() { }
        public void EndTextBlock() { }
    
        public List<byte[]> Images = new List<byte[]>();
        public List<string> ImageNames = new List<string>();
        public void RenderImage(ImageRenderInfo renderInfo) {
          PdfImageObject image = renderInfo.GetImage();
          PdfName filter = image.Get(PdfName.FILTER) as PdfName;
          if (filter == null) {
            PdfArray pa = (PdfArray) image.Get(PdfName.FILTER);
            for (int i = 0; i < pa.Size; ++i) {
              filter = (PdfName) pa[i];
            }
          }
          if (PdfName.CCITTFAXDECODE.Equals(filter)) {
            using (Dotnet dotnetImg = image.GetDrawingImage()) {
              if (dotnetImg != null) {
                ImageNames.Add(string.Format(
                  "{0}.tiff", renderInfo.GetRef().Number)
                );
                using (MemoryStream ms = new MemoryStream()) {
                  dotnetImg.Save(
                  ms, ImageFormat.Tiff);
                  Images.Add(ms.ToArray());
                }
              }
            }
          }
        }
      }
    }
    

    If the image(s) is/are being rotated, see this thread on the iText mailing list; perhaps some of the pages in the PDF document have been rotated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created WCF service in project. Now using Jquery I am successfully able
I am successfully able to send email using the smtplib module. But when the
I've created my own WCF service and I've successfully been able to talk to
Hi I'm able to successfully integrate iphone app with facebook framework. But I need
I am trying to create virtual desktop. I complete successfully.But i am not able
I am able to successfully extract the icons for file system drives, folders and
I've successfully been able to add controls (labels, images, buttons, etc) to a panel
I'm using storyboard in my ipad application and successfully able to do transitions, use
I am successfully able to Make custom Zoom using Slider in my Custom Camera
I'm trying to read only the strings from an image file. I was able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.