Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 13065 |  Welcome, Guest!   Register  Login
 Home > Forums > C# > Convert HTML to PDF using activePDF WebGrabber getting blank page in pdf? ...
Divs99

Convert HTML to PDF using activePDF WebGrabber getting blank page in pdf?

Replies: 2 | Posted by: Divs99 on 8/12/2012 | Category: C# Forums | Views: 777 | Status: [Member] | Points: 10  


unnecesarily iam getting second page as blank page in pdf if i have only one page of content in pdf when Converting HTML to PDF using activePDF WebGrabber ...i want to remove blank page in final pdf....pls help me out.....see my active pdf web grabber code given below:

APWebGrbNET.APWebGrabber oWG = new APWebGrbNET.APWebGrabber();

try
{
string strHTMLToPDF = this.OutputFolder + "\\htmltopdf";
if (Directory.Exists(strHTMLToPDF) == true)
directory.DeleteFiles(strHTMLToPDF);
else
Directory.CreateDirectory(strHTMLToPDF);
//Specifies the directory in which WebGrabber will place the output PDF.
oWG.OutputDirectory = strHTMLToPDF;
//Sets the filename for the output PDF. By default, WebGrabber uses an auto-generated unique identifier
oWG.NewDocumentName = "output.pdf";
//The Uniform Resource Locator (URL) to convert to PDF.
oWG.URL = sURL;
//Embeds all fonts used in the input file.
oWG.EmbedAllFonts = true;
oWG.ColorMode = 2;
//The size of the top, bottom, left, and right margins for the output, measured in inches.
oWG.SetMargins(topMargin, bottomMarigin, leftMargin, rightMargin);
// Set timeout properties.

// A true value instructing WebGrabber to use a temporary file.Sends the raw data passed with
//CreateFromHTMLText to a temporary file during rendering, which can improve performance on large documents.
oWG.HTMLTextToFile = true;
oWG.CreateFromHTMLText = strHTML;
oWG.Timeout = conTimeout;
//Submits the job parameters and input data to WebGrabber for PDF generation.
int iTest = oWG.DoPrint(sIP, 64320);
//Generate the pdf and catch the error if any error occurs.
if (iTest == 0)
{
DirectoryInfo di = new DirectoryInfo(strHTMLToPDF);
FileInfo[] rgFiles = di.GetFiles("*.pdf");
foreach (FileInfo fi in rgFiles)
{
FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
PDFStream = new byte[fs.Length];
fs.Read(PDFStream, 0, (int)fs.Length);
fs.Close();
File.Delete(fi.FullName);
break;
}
//Directory.Delete(strHTMLToPDF);
}
else
{
throw new Exception("HTML to PDF conversion failed '" + logmsg.ToString() + "'.");
}
}
finally
{
oWG.CleanUp(sIP, 64320);
}
}
return PDFStream;


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Megan00
Megan00  
Posted on: 8/12/2012 9:44:45 PM
Level: Starter | Status: [Member] | Points: 25

I think your method is rather complex and if you use this .NET PDF component: http://www.e-iceblue.com/Introduce/pdf-for-net-introduce.html , it can easily convert webpage to PDF , only three key steps:

using Spire.Pdf;

namespace htmltopdf
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
String url = "http://www.london2012.com/news/articles/paralympic-torch-relay-route-revealed-1258473.html";
doc.LoadFromHTML(url, false, true, true);
//Save pdf file.
doc.SaveToFile("sample.pdf");
doc.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("sample.pdf");
}
}
}


Never give up! Smile to the world!
http://excelcsharp.blog.com/

Divs99, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Divs99
Divs99  
Posted on: 8/13/2012 2:40:21 AM
Level: Starter | Status: [Member] | Points: 25

I want to do through AP Webgrabber itself......pls let me know how to remove blank page in pdf while converting html to pdf using APWebgrabber ?

Divs99, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 12:36:32 AM