Articles in this section
Category / Section

How to convert a secured webpage to pdf using .NET PDF in WinForms?

1 min read

 

We can convert the authenticate webpages as PDF by passing its username and password as arguments to the HtmlConverter.

Here are some code snippet

C#

using (System.Drawing.Image img = html.ConvertToImage(this.TextBox1.Text, ImageType.Metafile, (int)width, -1, AspectRatio.KeepWidth,"UserName","Password"))

{

if (img != null)

{

PdfMetafile metafile = (PdfMetafile)PdfImage.FromImage(img);

PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();

format.Break = PdfLayoutBreakType.FitPage;

format.Layout = PdfLayoutType.Paginate;

doc.PageSettings.Height = img.Height;

format.SplitTextLines = false;

metafile.Draw(page, new RectangleF(0, 0, pageSize.Width, -1), format);

}

else

Response.Write("Warning ! Please check the HTML link");

}

VB

Using img As System.Drawing.Image = html.ConvertToImage(Me.TextBox1.Text, ImageType.Metafile, CInt(Fix(width)), -1, AspectRatio.KeepWidth,"UserName","Password")

If Not img Is Nothing Then

Dim metafile As PdfMetafile = CType(PdfImage.FromImage(img), PdfMetafile)

Dim format As PdfMetafileLayoutFormat = New PdfMetafileLayoutFormat()

format.Break = PdfLayoutBreakType.FitPage

format.Layout = PdfLayoutType.Paginate

doc.PageSettings.Height = img.Height

format.SplitTextLines = False

metafile.Draw(page, New RectangleF(0, 0, pageSize.Width, -1), format)

Else

Response.Write("Warning ! Please check the HTML link")

End If

End Using


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied