IronPdf / Iron-Pdf-Documentation

ReadTheDocs Build Files for IronPDF C#/.Net PDF Library http://ironpdf.com
8 stars 2 forks source link

Problem when try to AspxToPdf #11

Open mauriciocargas opened 4 years ago

mauriciocargas commented 4 years ago

Hi,

I have the following problem: image

my code:

protected void Page_Load(object sender, EventArgs e)
{
    var AspxToPdfOptions = new IronPdf.PdfPrintOptions()
    {                
        PrintHtmlBackgrounds = true,
        CustomCssUrl = new Uri(HttpContext.Current.Server.MapPath("/PaginaAE/")).ToString(),
        PaperSize = PdfPrintOptions.PdfPaperSize.A4,
        Header = new HtmlHeaderFooter()
        {
            BaseUrl = HttpContext.Current.Server.MapPath("/PaginaAE/").ToString()
        }                
    };
    IronPdf.AspxToPdf.RenderThisPageAsPdf(IronPdf.AspxToPdf.FileBehavior.InBrowser,"recibo.pdf", AspxToPdfOptions);
}

I apply this code, but the error keeps appearing, could someone tell me what I am doing wrong?

What I am trying to do is generate an invoice in pdf format to download it

sorry for my english.

iron-production-team commented 2 years ago

To solve this please comment this line:

CustomCssUrl = new Uri(HttpContext.Current.Server.MapPath("/PaginaAE/")).ToString(),

or edit it:

CustomCssUrl = new Uri(HttpContext.Current.Server.MapPath("/PaginaAE/main.css")).ToString(),

https://ironpdf.com/object-reference/api/IronPdf.PdfPrintOptions.html#IronPdf_PdfPrintOptions_CustomCssUrl

Like the error said: CustomCssUrl should link to a stylesheet rather than a directory.