Groups > Asp .Net > ASP.NET components > Re: itextsharp: screen to pdf




itextsharp: screen to pdf

itextsharp: screen to pdf
Tue, 11 Mar 2008 17:40:21 +000
Hello, and thanks in advance for any assistance.

I am trying to utilize itextsharp to create PDFs, ideally invoking the content
within a specific content window in the master template.  However, I am not
quite sure how.  

I am guessing that it might be possible to recreate the content and then save
that as an image, then incorporate the image as a pdf, except that I am not sure
how to go about creating the image in the first place.  Essentially saving a
screen capture into a jpg or other format would allow me to accomplish the task,
but I am stuck as to how to create the image.

Any suggestions?

Thanks a ton for taking the time to address this issue.
Post Reply
Re: itextsharp: screen to pdf
Wed, 12 Mar 2008 06:17:48 +000
i think itextsharp is used to create new PDF & to edit old PDF.
Post Reply
Re: itextsharp: screen to pdf
Wed, 12 Mar 2008 16:21:57 +000
Yes, which is why I am using the itextsharp control.

My main question is getting the content.

Option 1: Save the page as an image on the server, then use itextsharp to save
the image as a pdf.

Option 2: Render a specific panel into itextsharp, where itextsharp would carry
over the html, stylesheets, etc. and display the content the same way in the PDF
as it does on the screen.

 
I'm thinking Option 1 is the most logical way, but how to do it I am not sure.
Post Reply
Re: itextsharp: screen to pdf
Wed, 12 Mar 2008 18:14:08 +000
This code might help you:

 

    protected void btnSubmit_Click( object sender, EventArgs e )
            {
            string strDocExt;
            //strDocType to store Document type which will be Stored in the
Database
            string strDocType;

            //Will be used to determine Document length
            int intDocLen;

            //Stream object used for reading the contents of the Uploading
Documnet
            Stream objStream;

             SqlCommand cmd;
            
            if ( IsValid )
                {
                if ( txtFileContents.PostedFile!=null )
                    {
                    //Determine File Type
                    string m_String=txtFileContents.PostedFile.FileName;
                    int m_Start=m_String.IndexOf( "." );
                    strDocExt=m_String.Substring( m_Start, 4 );
                    strDocExt=strDocExt.ToLower( );
                   

                    switch ( strDocExt )
                        {
                        case ".doc":
                            strDocType="doc";
                            break;

                        case ".ppt":
                            strDocType="ppt";
                            break;

                        case ".htm":
                            strDocType="htm";
                            break;

                        case ".html":
                            strDocType="htm";
                            break;

                        case ".jpg":
                            strDocType="jpg";
                            break;

                        case ".gif":
                            strDocType="gif";
                            break;
                        case ".txt":
                            strDocType="txt";
                            break;
                        default:
                            strDocType="pdf";
                            break;
                        }
                    //Grab the Content of the Uploaded Document

                    intDocLen=txtFileContents.PostedFile.ContentLength;
                    //buffer to hold Document Contents
                    byte [] Docbuffer=new byte [intDocLen];

                    //InputStream:
                    //Gets a Stream object which points to an uploaded Document;

                    //to prepare for reading the contents of the file.
                    objStream=txtFileContents.PostedFile.InputStream;

                    //Store the Content of the Documnet in a buffer
                    //This buffer will be stored in the Database
                    objStream.Read( Docbuffer, 0, intDocLen );
                    try
                        {
                        //Add Uploaded Documnet to Database as Binary
                        //You have to change the connection string
                        SqlConnection RB=new SqlConnection( "Server=XXXXX;
UID=YYYYY; Password=PPPPP;Database=ZZZZZZ" );
                        
                        //Setting the SqlCommand
                        cmd=new SqlCommand( "MyStoredProcedure", RB
);
                        cmdUploadDoc.CommandType=CommandType.StoredProcedure;
                        cmdUploadDoc.Parameters.Add( "@Title ",
SqlDbType.VarChar, 200 );
                        cmdUploadDoc.Parameters.Add( "@Doc",
SqlDbType.Image );
                        cmdUploadDoc.Parameters.Add( "@DocType",
SqlDbType.VarChar, 4 );
                        cmdUploadDoc.Parameters [0].Value=txtTitle.Text;
                        cmdUploadDoc.Parameters [1].Value=Docbuffer;
                        cmdUploadDoc.Parameters [2].Value=strDocType;

                        RB.Open( );
                        cmd.ExecuteNonQuery( );
                        RB.Close( );
                        }
                    catch ( Exception ex )
                        {
                        ex.StackTrace.ToString();
                        ex.StackTrace.ToString();
                        }
                    }//End of if(txtFileContents.PostedFile != null)
                }//End Of if(IsValid)

            }
Post Reply
Re: itextsharp: screen to pdf
Wed, 12 Mar 2008 19:02:27 +000
ks2007,

 From what I can tell from the code, it appears that this is a script that
allows you to save a document into the database.  I'm not sure that's exactly
what I'm trying to do.

 
I need to essentially create a screenshot of the site, save the image on the
server (hence the requirement that it be a server-side script), which I could
then put the generated image into a PDF.  I can then redirect the user to the
PDF using response.redirect.
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact