none
How to convert PDF to TIFF through C#?

    Question

  • Hi,

     

    I am sending PDF as fax from my application.It works fine bt the only issue is, Adobe Acrobat's new instance gets opened automatically.The solutions I got is to fax TIFF files rather than PDF.

     

    Can anyone do let meknow how to convert PDF to TIFF through C#?

     

    Thanks,

    Ravi Bhatt

    Wednesday, May 30, 2007 5:08 AM

Answers

  • The following code works for converting PDF to TIFF.But for that you have to use the ABCpdf 6.0 .NET Professional

     

     

    Doc theDoc = new Doc();

    theDoc.Read(Server.MapPath("../Pdfreports/Procedure_Report_" + ReportId.ToString() + ".pdf"));

    // set up the rendering parameters

    theDoc.Rendering.ColorSpace = "Gray";

    theDoc.Rendering.BitsPerChannel = 1;

    theDoc.Rendering.DotsPerInchX = 200;

    theDoc.Rendering.DotsPerInchY = 400;

    // loop through the pages

    int n = theDoc.PageCount;

    for (int i = 1; i <= n; i++)

    {

    theDoc.PageNumber = i;

    theDoc.Rect.String = theDoc.CropBox.String;

    theDoc.Rendering.SaveAppend = (i != 1);

    //theDoc.Rendering.SaveCompression = XRendering.Compression.G4;

    theDoc.SetInfo(0, "ImageCompression", "4");

    theDoc.Rendering.Save(Server.MapPath("../Pdfreports/Procedure_Report_" + ReportId.ToString() + "_" + i.ToString() + ".tiff"));

    }

    theDoc.Clear();

     

     

    Regards,

    Ravi Bhatt

    Tuesday, July 24, 2007 6:04 AM
  • Hi Ravi,

     

    Currently I don't find a class in the .NET Framework to convert PDF to TIFF file.

    However, you can use an external library PDF4NET to achieve your goal, which can handle very large files (30000+ pages in a PDF).

    See this threa Convert to TIFF image for detail.

     

    Another approach is checking this article including good samples and illustrations.

    100% .NET component for rendering PDF documents

    PDFRasterizer.NET is a component for rendering PDF documents and is written entirely in C#.

    This article describes how to use the PDFRasterizer.NET component to:

    1. Convert PDF documents to raster images such as BMP, GIF, PNG, TIFF etc.
    2. Display PDF documents in your WinForms application (with and without an EMF)
    3. Programmatically print PDF documents

    Hope that helps!

    Thursday, May 31, 2007 10:11 AM
  • NOTE:

    The following code is for converting TIFF files to other image files. NOT for converting PDF to TIFF. Sorry.

     

     

    Code Snippet

    public static byte[] ConvertImage(byte[] fromImage, string mimeType)

      

    {
        // Read the image from the byte variable into a bitmap variable
        MemoryStream fromImageStream = new MemoryStream();
        fromImageStream.Write(fromImage, 0, fromImage.Length);
        Image image = Image.FromStream( fromImageStream, true ) ;
        Bitmap bitmap = (Bitmap) image;
        // Instantiate the encoder
        EncoderParameters encoderParams = new EncoderParameters();
        encoderParams.Param[0] = new EncoderParameter( Encoder.Quality, 50L );
        ImageCodecInfo codecInfo = GetEncoderInfo( mimeType );
        MemoryStream newImage = new MemoryStream();
        // Convert the image to the new format
        bitmap.Save( newImage, codecInfo, encoderParams );
        // Read the new image into a byte variable
        byte[] data = newImage.ToArray();

        if (Logger.LogSwitch.LogInfo)
        {
         Logger.Write("ImageUtility", "EXITING ConvertImage method");
        }

        return data;

    }

     

    private static ImageCodecInfo GetEncoderInfo(String mimeType)
      {
       int j;
       ImageCodecInfo[] encoders;
       encoders = ImageCodecInfo.GetImageEncoders();
       for(j = 0; j < encoders.Length; ++j)
       {
        if(encoders[j].MimeType == mimeType)
         return encoders[j];
       }
       return null;
      }

     

     

    Thursday, May 31, 2007 6:30 PM
  • Hi,

     

    I got it solved.I was wble to send text and .jpeg successfully.Only the problwem came when i needed to send the pdf.So i convertedt it to tiff and treid to send it as a fax.Yest i sent it sucessfully and problem with the pdf got solved. No adobe instance gets open now.Big Relief to me.

     

     I used ABCPdf's professional edition to convert pdf to tiff. And that worked for me.

     

    Regards,

    Ravi bhatt.

    Saturday, June 23, 2007 6:07 AM

All replies

  • Hi Ravi,

     

    Currently I don't find a class in the .NET Framework to convert PDF to TIFF file.

    However, you can use an external library PDF4NET to achieve your goal, which can handle very large files (30000+ pages in a PDF).

    See this threa Convert to TIFF image for detail.

     

    Another approach is checking this article including good samples and illustrations.

    100% .NET component for rendering PDF documents

    PDFRasterizer.NET is a component for rendering PDF documents and is written entirely in C#.

    This article describes how to use the PDFRasterizer.NET component to:

    1. Convert PDF documents to raster images such as BMP, GIF, PNG, TIFF etc.
    2. Display PDF documents in your WinForms application (with and without an EMF)
    3. Programmatically print PDF documents

    Hope that helps!

    Thursday, May 31, 2007 10:11 AM
  • NOTE:

    The following code is for converting TIFF files to other image files. NOT for converting PDF to TIFF. Sorry.

     

     

    Code Snippet

    public static byte[] ConvertImage(byte[] fromImage, string mimeType)

      

    {
        // Read the image from the byte variable into a bitmap variable
        MemoryStream fromImageStream = new MemoryStream();
        fromImageStream.Write(fromImage, 0, fromImage.Length);
        Image image = Image.FromStream( fromImageStream, true ) ;
        Bitmap bitmap = (Bitmap) image;
        // Instantiate the encoder
        EncoderParameters encoderParams = new EncoderParameters();
        encoderParams.Param[0] = new EncoderParameter( Encoder.Quality, 50L );
        ImageCodecInfo codecInfo = GetEncoderInfo( mimeType );
        MemoryStream newImage = new MemoryStream();
        // Convert the image to the new format
        bitmap.Save( newImage, codecInfo, encoderParams );
        // Read the new image into a byte variable
        byte[] data = newImage.ToArray();

        if (Logger.LogSwitch.LogInfo)
        {
         Logger.Write("ImageUtility", "EXITING ConvertImage method");
        }

        return data;

    }

     

    private static ImageCodecInfo GetEncoderInfo(String mimeType)
      {
       int j;
       ImageCodecInfo[] encoders;
       encoders = ImageCodecInfo.GetImageEncoders();
       for(j = 0; j < encoders.Length; ++j)
       {
        if(encoders[j].MimeType == mimeType)
         return encoders[j];
       }
       return null;
      }

     

     

    Thursday, May 31, 2007 6:30 PM
  • i also have the same problem, when fax pdf file\

     

    anyone can solve, can share with me

    email:

    hajor#msn.com

    Sunday, June 03, 2007 4:38 PM
  • good
    Monday, June 04, 2007 2:04 AM
  • DId you find a solution if so can you send me some info
    Tuesday, June 05, 2007 9:17 PM
  • i didn't solove it ,

    now I try Ghostscript

    Wednesday, June 06, 2007 5:21 AM
  • I tried using your code but received an error on the

     

    Image image = Image.FromStream.....

     

    "Parameter is not valid"

     

    Only happens when I open a PDF.  I tried with .tif and it worked.

     

    Any ideas

     

     

    Friday, June 08, 2007 7:15 PM
  • I am not sure. It may has something to do with how you read the PDF into the byte[]

    Here is how I did it.  

     

    Code Snippet

       byte[] data = null;

       FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fs);
        // Read the image into the byte variable
        data = br.ReadBytes((int)fs.Length);
        br.Close();
        fs.Close();

     

     Then I passed the "data" to the method in my previous post. It worked fine for me.

     

    --------------------------------------------------------------------------------------------------------------------------------

    www.dotnetideas.com

    Monday, June 11, 2007 2:05 PM
  • Try this free online service to convert PDF files to TIFF or up to 117 other file formats.  www.freepdfconvert.com To incorporate this service directly into your website or application, refer to http://www.freepdfconvert.com/service_integration.asp .  This service is free with limitations and for a nomonal membership fee you can unlock the limitations.
    Monday, June 18, 2007 10:58 AM
  • i also happen the same problem

     

     

    Image image = Image.FromStream.....

     

    "Parameter is not valid"

    Tuesday, June 19, 2007 8:00 AM
  • I seem to be getting the invalid parameter error as well. Is there other objects that need referencing?

     

    Thanks

    Friday, June 22, 2007 11:55 AM
  • Hi,

     

    I got it solved.I was wble to send text and .jpeg successfully.Only the problwem came when i needed to send the pdf.So i convertedt it to tiff and treid to send it as a fax.Yest i sent it sucessfully and problem with the pdf got solved. No adobe instance gets open now.Big Relief to me.

     

     I used ABCPdf's professional edition to convert pdf to tiff. And that worked for me.

     

    Regards,

    Ravi bhatt.

    Saturday, June 23, 2007 6:07 AM
  • I'm getting this "Parameter is not valid" exception, as well.

    It's not only PDF, using RTF files causes the same exception.

    Actually, I cannot imagine that it's possible to instanciate an Image with the data of an arbitray file without any previous conversion.

    But I'm still interested in any solution of this problem.

     

     

     

    Sunday, June 24, 2007 10:55 AM
  • Hi, great work

    can you say details?

     

    thanks

    Friday, June 29, 2007 2:00 AM
  • Hi ,
          As I have the same problem? If you got solution for your problem,please let me know friend....
    Saturday, June 30, 2007 12:01 PM
  • The following code works for converting PDF to TIFF.But for that you have to use the ABCpdf 6.0 .NET Professional

     

     

    Doc theDoc = new Doc();

    theDoc.Read(Server.MapPath("../Pdfreports/Procedure_Report_" + ReportId.ToString() + ".pdf"));

    // set up the rendering parameters

    theDoc.Rendering.ColorSpace = "Gray";

    theDoc.Rendering.BitsPerChannel = 1;

    theDoc.Rendering.DotsPerInchX = 200;

    theDoc.Rendering.DotsPerInchY = 400;

    // loop through the pages

    int n = theDoc.PageCount;

    for (int i = 1; i <= n; i++)

    {

    theDoc.PageNumber = i;

    theDoc.Rect.String = theDoc.CropBox.String;

    theDoc.Rendering.SaveAppend = (i != 1);

    //theDoc.Rendering.SaveCompression = XRendering.Compression.G4;

    theDoc.SetInfo(0, "ImageCompression", "4");

    theDoc.Rendering.Save(Server.MapPath("../Pdfreports/Procedure_Report_" + ReportId.ToString() + "_" + i.ToString() + ".tiff"));

    }

    theDoc.Clear();

     

     

    Regards,

    Ravi Bhatt

    Tuesday, July 24, 2007 6:04 AM
  • What do I 'use' to get the Doc() library?
    Friday, August 24, 2007 8:11 PM
  • I don't see how this code can work.  We are all getting an error of "parameter is not valid"

    after this line:  Image image = Image.FromStream( fromImageStream, true ) ;

     

    Since the image coming in is from a PDF file how does it know how to format it correctly to the image object?

     

    Are you leaving something out?

     

    Frankly, I don't think it is even possible to convert a PDF to a TIFF without purchasing third party software of some sort but I would love to be corrected.

     

    Davicito

    Washington, DC

    Monday, September 24, 2007 7:47 PM
  • The PDF we are using is generated using ComponentOne. It may be much than regular PDF. That's probably why the code worked for me. Like I said, we were able to convert the PDF we generated to GIF format using above code. Then we can fax the GIF. I haven't tried the code with just any PDF file.

    Tuesday, September 25, 2007 2:10 PM
  • I also got the invalid parameter on the FromStream method. There must be something that he left out in the code example for everyone to get this same error.

     

     

     

     

    Wednesday, September 26, 2007 7:48 PM
  • I just tested this code with a bitmap file instead of  PDF , and works fine, if i try with PDF files, I got the same "Parameter not Valid" error, perhaps image class do not know to handle PDF data.

     

    Does  anybody know how to use tihis sample with PDF ?

     

    Regards,

     

    Monday, October 01, 2007 10:48 PM
  • I appologize for misleading everyone. The code I posted here was used to convert TIFF to other format of images. I made mistake by thinking it was used for converting PDF to TIFF. Sorry about that.

    Tuesday, October 02, 2007 2:48 PM
  • Hello All,

        After a week of reading through Adobe SDK documentation and looking through a lot of forums, I have successfully written a test application to convert PDF to .TIFF. Note: you must have the Adobe standard or Professional 7.0 or greater installed to make this work. I did it using the trial version of Adobe Pro 8.0. You will have to set a reference to the Acrobat COM object. Here is my coding in VB.NET:

     

     

    Code Block

    Public Class Form1

    Dim PDFApp As Acrobat.AcroApp

    Dim PDDoc As Acrobat.CAcroPDDoc

    Dim AVDoc As Acrobat.CAcroAVDoc

     

    Private Sub btnBrowsePath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowsePath.Click

    Dim result As DialogResult

     

    OpenFileDialog1.FileName = ""

    OpenFileDialog1.AddExtension = True

    OpenFileDialog1.DefaultExt = ".TIF"

    OpenFileDialog1.Filter = "Adobe PDF Files (*.PDF) | *.PDF"

    OpenFileDialog1.InitialDirectory = "DeskTop"

    result = OpenFileDialog1.ShowDialog()

     

    If (result = Windows.Forms.DialogResult.OK) Then

    Me.txtPDFPath.Text = OpenFileDialog1.FileName

    End If

     

    End Sub

     

    Private Sub btnLoadPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadPDF.Click

    ' Dim javaString As String

    Dim JSObj As Object, strPDFText As String

     

    ' Create Acrobat Application object

    PDFApp = CreateObject("AcroExch.App")

    ' Create Acrobat Document object

    PDDoc = CreateObject("AcroExch.PDDoc")

    ' Open PDF file

    PDDoc.Open(Me.txtPDFPath.Text)

    ' Create AV doc from PDDoc object

    AVDoc = PDDoc.OpenAVDoc("TempPDF")

    ' Hide Acrobat application so everything is done in silent mode

    PDFApp.Hide()

    ' Create Javascript bridge object

    JSObj = PDDoc.GetJSObject()

    ' Test making change to one of the text fields

    ' Syntax for GetField method GetField( strFieldName )

    JSObj.GetField("Text2.0.0.0.0").value = "JESSICA"

    ' Test pulling data from a PDF text field and showing in a Windows Messagebox

    strPDFText = JSObj.GetField("Text2.0.0.2.0").value

    ' Attempt to save PDF to TIF image file.

    ' SaveAs method syntax .SaveAs( strFilePath, cConvID )

    ' For TIFF output the correct cConvid is "com.adobe.acrobat.tiff"

    ' cCovid MUST BE ALL LOWERCASE.

    JSObj.SaveAs("C:\TestTiffs\TestGood.tif", "com.adobe.acrobat.tiff")

    PDDoc.Close()

    PDFApp.CloseAllDocs()

     

    ' Clean up

    System.Runtime.InteropServices.Marshal.ReleaseComObject(JSObj)

    JSObj = Nothing

    System.Runtime.InteropServices.Marshal.ReleaseComObject(PDFApp)

    PDFApp = Nothing

    System.Runtime.InteropServices.Marshal.ReleaseComObject(PDDoc)

    PDDoc = Nothing

    System.Runtime.InteropServices.Marshal.ReleaseComObject(AVDoc)

    AVDoc = Nothing

     

    End Sub

    End Class

     

     

    Tuesday, October 02, 2007 3:43 PM
  • Hai

     

    Great!  I too have a requirement the same way.  But my pdf does not have any js or objects included in pdf.  Its a simple clean pdf contains only text.

     

    Hence, I get nothing at

    ' Create Javascript bridge object

    JSObj = PDDoc.GetJSObject()

    ' Test making change to one of the text fields

    ' Syntax for GetField method GetField( strFieldName )

    JSObj.GetField("Text2.0.0.0.0").value = "JESSICA"

    and the code does not run after the above line.

     

    Can you please help me out.  How to save a pdf as tiff, which does not produce any value by executing JSObj = PDDoc.GetJSObject().

     

     

    Wednesday, October 17, 2007 2:50 PM
  • Do you have the standard or Professional Acrobat installed not just the reader? Did you set a reference to Acrobat?

     

    Thursday, October 18, 2007 1:15 AM
  •  

    Let me thank you first for your interest and quick response!

     

    Yes.  I have installed Acrobat 8.0.1 Professional trial version.

    I have set references.

     

    Your code runs fine for me.  But when the execution encounters the statement JSObj = PDDoc.GetJSObject(), GetJSObject returns nothing, and rest of the code gets messed up.  I guess with JSObj you are reading and assigning values to some controls available in the pdf.  But my PDF does not contain any.  Its just a simple PDF. 

    Thursday, October 18, 2007 4:38 AM
  • Yes, the GetField("Text2.0.0.0.0").value = "JESSICA" references a text field already in my pdf file. You would need to add some text fields in your pdf and changed the getfield parameter to reference the name of your fields. If you take out all the code after the JSOBJ = PDDOC.GetJSObj() and immediately put the PDDoc.SaveAs it should work. The path of the SaveAs cannot be a root or system folder.

     

     

     

    Thursday, October 18, 2007 4:49 AM
  • Thanks!

    But PDDoc does not have SaveAs method.  By any chance if you come to know how to do this please post.
    Thursday, October 18, 2007 1:38 PM
  • Sorry, I mistakenly said PDDoc.SaveAS when I mean JSObj.SaveAs

     

    This code should work and I have seen a similar code sample on another site by someone else, so I am sure it works.

     

    Code Block
    Public Class Form1

    Dim PDFApp As Acrobat.AcroApp

    Dim PDDoc As Acrobat.CAcroPDDoc

    Dim AVDoc As Acrobat.CAcroAVDoc

     

     

    Private Sub btnLoadPDF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadPDF.Click

    ' Dim javaString As String

    Dim JSObj As Object, strPDFText As String

     

    ' Create Acrobat Application object

    PDFApp = CreateObject("AcroExch.App")

    ' Create Acrobat Document object

    PDDoc = CreateObject("AcroExch.PDDoc")

    ' Open PDF file

    PDDoc.Open("C:\Test.pdf") ' Path of some PDF you want to open

     

    ' Hide Acrobat application so everything is done in silent mode

    PDFApp.Hide()

     

    ' Create Javascript bridge object

    JSObj = PDDoc.GetJSObject()

    ' Create Tiff file

    JSObj.SaveAs("C:\TestTiffs\TestGood.tif", "com.adobe.acrobat.tiff")

     

    PDDoc.Close()

    PDFApp.CloseAllDocs()

     

    ' Clean up

    System.Runtime.InteropServices.Marshal.ReleaseComObject(JSObj)

    JSObj = Nothing

    System.Runtime.InteropServices.Marshal.ReleaseComObject(PDFApp)

    PDFApp = Nothing

    System.Runtime.InteropServices.Marshal.ReleaseComObject(PDDoc)

    PDDoc = Nothing

     

    End Sub

     

    End Class

     

     

     

    Friday, October 19, 2007 1:12 PM
  • Thanks you! 

     

    You have done a great help!

     

    Thank you once again!

    • Proposed as answer by selvaCTS Tuesday, November 18, 2008 12:02 PM
    Tuesday, October 23, 2007 11:03 AM
  • Hi i am developer PdfCreator from gotdotnet.
    Tiff to PDF with CCITT compression is not diffucult. In the market very tool successfully make to it. Such as PDF Technologies for .NET

    This product very easy

      PDFDocument MyPDF = new PDFDocument("Tiff2Pdf.pdf");                                                                                            
                MyPDF.TiffToPDF("sample.tif");

                MyPDF.Save();


    Also this product have a live demo.


    Friday, January 25, 2008 1:50 PM
  • Many thanks to New2bi.

       Is there a way I can save it as Multipage Tif images?

    Thanks

    =BlackSpider=
    Wednesday, July 30, 2008 2:37 PM
  • Hi,

    I tried your code it works fine. If i have "test.PDF" file which contains 20 pages. i want to convert the test.PDF in to single "test.tif"

    If i tried same file with ur approach it converted each page in single tiff.

    Please help its bit urgent

    Thanks in Advance
    Selvaraj P 

     
    Tuesday, November 18, 2008 12:06 PM
  • hi,

    Thanks for the code .This is what am looking for conversion of pdf to tif.
    But i got the  error
    "Cannot create ActiveX component."  on line

    PDFApp = CreateObject("AcroExch.App")


    AM using the Adobe reader 7.0.

    Please guys clarify me.

    Thanks
    vijay



    Thursday, March 05, 2009 9:23 AM
  • hi,

    Now i had upgraded Acrobat reader to 8.0 and now workign fine. But when i try to transfer multi page pdf file to a single tiff file, it actually creates each page as a seperate tiff file.But i want all the pages as a whole sinlge tiff fiel only...Are we missing any property?


    Regards
    vijay
    Thursday, March 05, 2009 12:40 PM
  • hi ,

    i was looking for code to convert image pdf to searchable pdf using acrobat SDK since last week . but i did not get anything on that. . my fortune is that i find one article here about coverting PDF to TIff. its very nice . can any body help me to convert that tiff file to searchable pdf? i am not strict into only one  way. one way or other i have to convert image pdf to searchable pdf using acrobat sdk .. please post code for this process...


    thanks in advance for ur helping mind...

    Thursday, February 18, 2010 5:30 AM
  • Hi,

      My application needs to convert pdf to tiff and I used your code. In project, to add reference, I selected Adobe Acrobat library8.0 from the COM tab of Addreference window. While running the application, error throwing at this line JSObj.SaveAs("C:\TestGood.tif", "com.adobe.acrobat.tif"). Could you please help me on this issue. I am using VS 2008 windows form.

    The error is System.Runtime.InteropServices.COMException was unhandled
      ErrorCode=1001
      Message="UnsupportedValueError: Value is unsupported. ===> Parameter cConvID."
      Source="Acrobat JavaScript"
      StackTrace:
           at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
           at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
           at Pdf2Tiff.Form1.btnLoadPDF_Click(Object sender, EventArgs e) in C:\Code\Pdf2Tiff\Pdf2Tiff\Form1.vb:line 43
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ButtonBase.WndProc(Message& m)
           at System.Windows.Forms.Button.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(ApplicationContext context)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
           at Pdf2Tiff.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    Thursday, August 19, 2010 1:54 PM
  • Very nice solution.

     

    Just a quick question - will it work if you have Acrobat reader 8 installed only?

     

    Thaks guys

     

    Thursday, November 18, 2010 1:53 PM
  • Hi

    I need to fill acro and xfa forms using acrobat in a desktop application. I have tried with the following piece of code. It works well on acro form but seems to do nothing on xfa form.

    Type AcrobatCAcroAppType = Type.GetTypeFromProgID("AcroExch.AVDoc");

                    Type AcrobatPDDocType = Type.GetTypeFromProgID("AcroExch.PDDoc");

                    if ((AcrobatCAcroAppType == null) || (AcrobatPDDocType == null))

                        throw new Exception("Acrobat not installed on this system.");

     

                    CAcroAVDoc avDoc = (Acrobat.CAcroAVDoc)Activator.CreateInstance(AcrobatCAcroAppType);

                    CAcroPDDoc pdDoc = (Acrobat.CAcroPDDoc)Activator.CreateInstance(AcrobatPDDocType);

     

                    // Open the pdf

                    if (!avDoc.Open(fileName, ""))

                    {

                        string szMsg = "Cannot open" + fileName + ".";

                        throw new Exception(szMsg);

     

                    }

                    pdDoc.Open(fileName);

     AFORMAUTLib.AFormApp formApp = (AFORMAUTLib.AFormApp)Activator.CreateInstance(Type.GetTypeFromProgID("AFormAut.App"));

                    // Get the IFields object associated with the form

     

                    AFORMAUTLib.Fields myFields = (AFORMAUTLib.Fields)formApp.Fields;

     

                    // Get the IEnumerator object for myFields

     

                    IEnumerator myEnumerator = myFields.GetEnumerator();

     

                    //bool bFound = false;

     

                    // Fill the "Name" field with value "John Doe"

                    IField myField;

                    while (myEnumerator.MoveNext())

                    {

                        // Get the IField object

     

                        myField = (IField)myEnumerator.Current;

    if (myField.Name == "businessaddress")

                            {

                                //bFound = true;

                                myField.Value = txtEntry.Text;

                                break;

                            }

     }

       pdDoc.Close();

     

     

    If  I create a js object.. It throws an exception:

    dynamic jsObj = pdDoc.GetJSObject();

    string strPDFText = jsObj.GetField("businessaddress").value

    System.ArgumentException: Value does not fall within the expected range.

       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)

       at System.Dynamic.ComRuntimeHelpers.CheckIfMissingTypeInfoIsExpected(Int32 hresult, Boolean throwIfMissingExpectedTypeInfo)

       at System.Dynamic.ComRuntimeHelpers.GetITypeInfoFromIDispatch(IDispatch dispatch, Boolean throwIfMissingExpectedTypeInfo)

       at System.Dynamic.IDispatchComObject.EnsureScanDefinedMethods()

       at System.Dynamic.IDispatchComObject.System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(Expression parameter)

       at System.Dynamic.DynamicMetaObject.Create(Object value, Expression expression)

       at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)

       at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)

       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)

       at CallSite.Target(Closure , CallSite , Object , String )

       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)

       at SampleAcroXfa.Form1.ReadWritePdf(Boolean isWrite) in D:\sharmishta\Acro\SampleAcroXfa\SampleAcroXfa\Form1.cs:line 72

     

     

    Please help me out in filling the xfa form using acrobat. I am very new to it.

    Tuesday, April 05, 2011 11:54 AM
  • Thank you very much.

    I have to convert a single PDF File to a single TIF (multi-frame) file, and this bit of code helped me get the individual TIF images exported in sequence.
    I then used ImageMagick command line CONVERT to assemble the pieces into a single multi-frame tif file. (convert temp*.tif -depth 8 -compress LZW mynewfile.tif)

    Wednesday, April 20, 2011 6:05 AM
  • Try component PDF Vision .NET
    SautinSoft - .Net components to convert between PDF, HTML, RTF, DOC, XHTML, EXCEL, IMAGES etc. http://www.sautinsoft.com
    Wednesday, May 04, 2011 12:39 PM
  • Aspose.Pdf for .NET can be used to convert PDF to TIFF in C#. You can either convert individual PDF pages to TIFF images, or convert the whole PDF to single TIFF image. It can work on all Windows OS and 32-bit/64-bit systems as well.
    I work as developer evangelist at Aspose. I love to explore and learn new technologies and help other developers along the way.
    Tuesday, July 12, 2011 6:49 PM
  • Thanks Ravi, that was very helpful. I g ave up on ImageMagick and gave a try to ABCpdf and the code worked fine for me. Your code snippet came in handy for that purporse. Apparently, you can also use theDoc.Rendering.GetData("dummy.tiff") to get the byte[] instead of writing to a physical file.


    Windows Developer
    • Proposed as answer by kulkarna Thursday, September 22, 2011 9:09 PM
    • Unproposed as answer by kulkarna Thursday, September 22, 2011 9:09 PM
    Thursday, September 22, 2011 9:08 PM
  • The PDF Focus .Net can do it in such way:

    1. PDF to TIFF

    SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
    
    string pdfPath = @"c:\My.pdf";
    string imageFolder = @"c:\images\";
    
    f.OpenPdf(pdfPath);
    
    if (f.PageCount > 0)
    {
        //Save all PDF pages to image folder as tiff images, 200 dpi
        int result = f.ToImage(imageFolder, "page",System.Drawing.Imaging.ImageFormat.Tiff, 200);
    }
    


    2. PDF to Multipage-TIFF

    //Convert PDF file to Multipage TIFF file
    SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
    
    string pdfPath = @"c:\Document.pdf";
    string tiffPath = @"c:\Result.tiff";
    
    f.OpenPdf(pdfPath);
    
    if (f.PageCount > 0)
    {
        f.ToMultipageTiff(tiffPath, 120) == 0)
        {
            System.Diagnostics.Process.Start(tiffPath);
        }
    }            
    
    

    Thanks,

    Max

    Wednesday, October 12, 2011 11:36 AM
  • I search for solution to convert PDF to TIFF and find this post.

    There are so many solutions that I don't know which I should choose.

    But thanks for all the solutions.

    • Proposed as answer by Wanderson_ Wednesday, December 26, 2012 1:13 PM
    Thursday, October 11, 2012 7:57 AM
  • There is no native support for PDF in standard .NET. However you can use a third-party component like the Ultimate PDF.
    Friday, December 28, 2012 2:50 PM
  • It can be done using professional component,

    here is the code that can be used to handle the task:

     

    // taken from 
    // http://apitron.com/HowToConvertPDFtoTIFF
    
    using Apitron.PDF.Rasterizer;
    using Apitron.PDF.Rasterizer.Configuration;
    ...
    // open and load the file
    using (FileStream fs = new FileStream(@"Documents\testfile.pdf", FileMode.Open), fsOut = File.Create("out.tiff"))
    {
        // this object represents a PDF document
        Document document = new Document(fs);
     
        // save to tiff using CCIT4 compression, black and white tiff.
        // set the DPI to 144.0 for this sample, so twice more than default PDF dpi setting.
        TiffRenderingSettings tiffRenderingSettings = new TiffRenderingSettings(TiffCompressionMethod.LZW, 144, 144);
     
        document.SaveToTiff(fsOut, tiffRenderingSettings);
     
        Process.Start("out.tiff");
    }
    
    

     

     

    Tuesday, July 23, 2013 6:48 AM
  • Hi, 

    PDF or Portable Document Format is the widely used format so if you want to convert it into image format you need to use a professional software. For converting your PDF document to an image format you can use PDF to Image converter

    http://www.softwaredownloadcentre.com/software/pdf-to-image-converter.php

    Monday, August 04, 2014 9:14 AM