Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is code :
C#
public int Convert(string sourceFileName, ImageFormat outPutImageFormat)
{
    if (pdfDoc.Open(sourceFileName))
    {

        // pdfapp.Hide();
        pageCount = pdfDoc.GetNumPages();

        for (int i = 0; i < pageCount; i++)
        {
            pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i);
            pdfPoint = (Acrobat.AcroPoint)pdfPage.GetSize();
            pdfRect.Left = 0;
            pdfRect.right = pdfPoint.x;
            pdfRect.Top = 0;
            pdfRect.bottom = pdfPoint.y;

            pdfPage.CopyToClipboard(pdfRect, 0, 0, 100);

            string outimg = "";
            string filename = sourceFileName.Substring(sourceFileName.LastIndexOf("\\") + 1);
            filename = filename.Remove(filename.LastIndexOf("."));
            if (pageCount == 1)
                outimg = strMapath + filename + "." + outPutImageFormat.ToString();
            else
                outimg = strMapath + filename + "_" + i.ToString() + "." + outPutImageFormat.ToString();

....................
I need a solution to save "outimg" in asp.net.
Pls help me.Thank a lots.
Posted
Updated 29-Nov-11 21:05pm
v4

Hi,

1 - Which PDF component you are using?
2 - You have
C#
pdfPage.CopyToClipboard(...)
function. Do you have other function in the PDF library that can copy it to other stream.. for example File stream or binary stream?

3 - with the above code where you have copied data to Clipboard you can extract data from clipboard http://msdn.microsoft.com/en-us/library/c2thcsx4.aspx[^] but you will need to specify format of data being extracted i.e. text/image etc.

After pdfPage.CopyToClipboard(...) function open paint brush i.e. MS Paint and press Ctrl + V and see if you are getting any image. if you are getting an image in MS Paint then saving data as image is very much possible but if you are not getting an image then probably the data cannot be covnerted to image.

Thanks,
hemant

Edit
I believe i've found solution. You are using Adobe's Acrobat SDK to copy data to clipboard and i was right that you can get data from clipboard.

[Create thumbnail from Acrobat]
Read the above article it has exactly what you are looking for.

VB
Call pdfPage.CopyToClipboard(pdfRect, 0, 0, 100)

Dim clipboardData As IDataObject = Clipboard.GetDataObject()


Hope this will help.

Thanks,
Hemant
 
Share this answer
 
v2
Comments
hieupn 30-Nov-11 4:41am    
thank you for your ideas.
I don't know how to use File stream or binary,please give me example to replace copyToClipboard().
It is very important with me.Pls help me!
Thanks you so much.
Hemant__Sharma 30-Nov-11 5:50am    
You didn't anwer my questions. Which PDF component you are using in our code give us the name?
- Did you try pasting the clipboard data to MS paint? you can debug your code and put a breakpoint somewhere after pdfPage.CopyToClipboard(..) function, run your code when you reach to your debug breakpoint by that time the data must be copied to clip board. Open MS paint program and press Ctrl+V or Edit> paste.

i don't know if you can replace code to copy to file/binary stream with CopyToClipboard function as i don't know which component you are using.
hieupn 30-Nov-11 21:40pm    
It is ok with winform,but i want to use with webforms.
All code :
public partial class ConvertWeb : System.Web.UI.Page
{
public int pageCount = 0;
Acrobat.CAcroPDDoc pdfDoc = new Acrobat.AcroPDDoc();
Acrobat.CAcroPDPage pdfPage = null;
Acrobat.CAcroRect pdfRect = new Acrobat.AcroRect();
Acrobat.AcroPoint pdfPoint = new Acrobat.AcroPoint();
public string strMapath = string.Empty;

protected void Page_Load(object sender, EventArgs e)
{
strMapath = Server.MapPath("TempFiles\\");
}

protected void BtnConvert_Click(object sender, EventArgs e)
{
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
string strPathFile = string.Format("{0}{1}{2}", strMapath, fileName, Path.GetExtension(FluFile.PostedFile.FileName));
FileInfo fileContent = new FileInfo(strPathFile);
FluFile.SaveAs(strPathFile);
if ((fileContent.Exists))
{
ImageFormat imageFormat = new ImageFormat(Guid.Empty);
switch (ddlFormat.SelectedValue.ToString())
{
case "Jpeg": imageFormat = ImageFormat.Jpeg; break;
case "Bmp": imageFormat = ImageFormat.Bmp; break;
case "Png": imageFormat = ImageFormat.Png; break;
case "Gif": imageFormat = ImageFormat.Gif; break;
}

int filescount = Convert(strPathFile, imageFormat);
}
}
public int Convert(string sourceFileName, ImageFormat outPutImageFormat)
{
if (pdfDoc.Open(sourceFileName))
{

// pdfapp.Hide();
pageCount = pdfDoc.GetNumPages();

for (int i = 0; i < pageCount; i++)
{
pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i);
pdfPoint = (Acrobat.AcroPoint)pdfPage.GetSize();
pdfRect.Left = 0;
pdfRect.right = pdfPoint.x;
pdfRect.Top = 0;
pdfRect.bottom = pdfPoint.y;

pdfPage.CopyToClipboard(pdfRect, 0, 0, 100);
IDataObject clipboardData = Clipboard.GetDataObject();

string outimg = "";
string filename = sourceFileName.Substring(sourceFileName.LastIndexOf("\\") + 1);
filename = filename.Remove(filename.LastIndexOf("."));
if (pageCount == 1)
outimg = strMapath + filename + "." + outPutImageFormat.ToString();
else
outimg = strMapath + filename + "_" + i.ToString() + "." + outPutImageFormat.ToString();
/////////......./////////////////
}
Dispose();
}
else
{
Dispose();
throw new System.IO.FileNotFoundException(sourceFileName + " Not Found!");
}
return pageCount;
}
~ConvertWeb()
{
GC.Collect();
if (pdfPage != null)
Marshal.ReleaseComObject(pdfPage);
Marshal.ReleaseComObject(pdfPoint);
Marshal.ReleaseComObject(pdfRect);
Marshal.ReleaseComObject(pdfDoc);
}
public void Dispose()
{
GC.Collect();
if (pdfPage != null)
Marshal.ReleaseComObject(pdfPage);
Marshal.ReleaseComObject(pdfPoint);
Marshal.ReleaseComObject(pdfRect);
Marshal.ReleaseComObject(pdfDoc);
}
I hope you can understand what i do and help me to solve this problem!!
Thanks,
HieuPN
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900