• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1190
  • Last Modified:

The type or namespace name 'PdfDecoder' could not be found

Dear Experts,
am trying to convert pdftoimage using the below link
http://threebit.net/mail-archive/itext-questions/msg00436.html

but i get this error how to get this code to work ?
"The type or namespace name 'PdfDecoder' could not be found"
I need a solution for this and am left with null ideas to proceed .
As i dont have freedom to
purchase third party and i did the best to use ghost script projects which got so many issues on server?
http://www.codeproject.com/KB/webforms/aspnetpdfviewer.aspx

Please suggest me your Ideas to convert pdftoimage in asp.net.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private void getPDFPagesasImages(Object file)
    {

        //open pdf file
        PdfDecoder decoder = openpdf(file.toString());
        String formname = file.toString();
        formname = formname.Substring(formname.LastIndexOf("\\") + 1).replace(".pdf", "");
        //for each page
        int PageCount = decoder.getPageCount();
        int PageNumber = 1;
        while (PageNumber <= PageCount)
        {
            //generate png files
            double ImageWidth = 0;
            double ImageHeight = 0;
            generatePNGfromPDF(decoder, PageNumber, ImageWidth, ImageHeight, formname);

            PageNumber++;
        }//end page code
        //close pdf
        decoder.closePdfFile();

    }

    private void generatePNGfromPDF(PdfDecoder decoder, int PageNumber, double width, double height, String formname){
    //int size = 100;
    try
    {
    //decoder.decodePage(PageNumber);
    //decoder.setPageParameters(1,PageNumber); //values scaling (1=100%). page number
    decoder.useHiResScreenDisplay(true);
   
    int dpi=300;
    decoder.setExtractionMode(32, dpi,2);
    BufferedImage PDF = decoder.getPageAsImage(PageNumber);
    width = PDF.getWidth() * .75;
    height = PDF.getHeight() * .75;
 
    GraphicsConfiguration gc = getDefaultConfiguration();
    final BufferedImage PNG = getScaledInstance(PDF, (int)Math.round(width), (int)Math.round(height), gc);
    String fileName = jTextAreaTargetDirectoryPath.getText() + "\\" + formname + "-" + PageNumber + ".png";
    ImageIO.write(PNG, "png", new File( fileName ));
    decoder.flushObjectValues(true);
    }
    catch(Exception ex){
        flogger.log(Level.SEVERE, "Cannot generate image from page.", ex);
    }  
   
}
    private static GraphicsConfiguration getDefaultConfiguration()
    {
        GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        return gd.getDefaultConfiguration();
    }
    private static BufferedImage toCompatibleImage(BufferedImage image, GraphicsConfiguration gc)
    {
        if (gc == null)
            gc = getDefaultConfiguration();
        int w = image.getWidth();
        int h = image.getHeight();
        int transparency = image.getColorModel().getTransparency();
        BufferedImage result = gc.createCompatibleImage(w, h, transparency);
        Graphics2D g2 = result.createGraphics();
        g2.drawRenderedImage(image, null);
        g2.dispose();
        return result;
    }
    private static BufferedImage copy(BufferedImage source, BufferedImage
    target)
    {
        Graphics2D g2 = target.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,

RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2.setRenderingHint(RenderingHints.KEY_DITHERING,
                                RenderingHints.VALUE_DITHER_DISABLE);
        g2.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_OFF);

        g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,

RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        double scalex = (double)target.getWidth() / source.getWidth();
        double scaley = (double)target.getHeight() / source.getHeight();
        AffineTransform xform = AffineTransform.getScaleInstance(scalex,
scaley);
        g2.drawRenderedImage(source, xform);
        g2.dispose();
        return target;
    }
    private static BufferedImage getScaledInstance(BufferedImage image, int width, int height, GraphicsConfiguration gc)
    {
        if (gc == null)
            gc = getDefaultConfiguration();
        int transparency = image.getColorModel().getTransparency();
        return copy(image, gc.createCompatibleImage(width, height, transparency));
    }
    private PdfDecoder openpdf(Object file)
    {
        //open pdf using jpedal
        PdfDecoder decoder = new PdfDecoder();
        try
        {
            decoder.openPdfFile(file.toString());
        }
        catch (org.jpedal.exception.PdfException ex)
        {
            flogger.log(Level.SEVERE, "Cannot open pdf.", ex);
        }
        return decoder;
    }
}

Open in new window

0
Rajar Ahmed
Asked:
Rajar Ahmed
1 Solution
 
Umar Topia.Net Full Stack DeveloperCommented:
1) You will have to refer that DLL
(using AddReference from Visual Studio)
2) Add using PdfDecoder;

then your code should work
0
 
Rajar AhmedConsultantAuthor Commented:
hi umartopia,

there is no such dll in the add reference window
0
 
Rajkumar GsSoftware EngineerCommented:
It seems that you didn't install the application -  PDFDecoder. Once you install, corresponding DLL would be available in GAC and you can refer to that assembly.

Since in your current code, you are using this assembly, better to install and proceed. So try get the setup of PDFDecoder, install and verify

Raj
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Rajar AhmedConsultantAuthor Commented:
hi rajkumargs, Thanks for ur valuable response .
 
  first of all  that was the link i tried , i dint find any dll or pdfdecoder setup file to install in that link .
  All i got a code which bluntly mentioned to convert pdf to image .
0
 
CodeCruiserCommented:
iText is being used in the code that you are working with

http://itextpdf.com/
0
 
Rajar AhmedConsultantAuthor Commented:
i included itext sharp latest dll and included these namespace but stilll am getting dese errorss..


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf.parser;
using iTextSharp.text.pdf;

Open in new window

errorss.png
0
 
CodeCruiserCommented:
Well some of the classes (BufferedImage, GraphicsConfiguration) seem to be Java classes. Are you sure that's C# code?
0
 
Rajar AhmedConsultantAuthor Commented:
CodeCruiser,

But when i google asp.net pdf to image using itext sharp
i got one of the post of this link .. and its pretty much looks like c# so i proceeded it .
Whether conversion of pdf to image is so so difficult to do in asp.net ?

0
 
Rajar AhmedConsultantAuthor Commented:
Codecruiser,
Not sure , whether its c# . u may be right it may be java also . !
in that way how can i accomplish this issue of conversion of pdftoimage
are there any opensource ?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now