IronPdf / Iron-Pdf-Documentation

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

Can't create snapshots for testing PDFs #17

Closed greg-cann closed 1 year ago

greg-cann commented 2 years ago

When using IronPdf to generate Pdf documents from HTML it's not possible to create binary snapshots.

Most likely because it generates different metadata per request.

This metadata is not exposed, so cannot be overridden for testing.

cannot find any clear indication in the docs as to why this happens.

public byte[] GetFile(Request request)
{
    string htmlContentBase64 = request.Html;
    byte[] htmlContentBytes = Convert.FromBase64String(htmlContentBase64);
    string htmlContent = Encoding.UTF8.GetString(htmlContentBytes);
    var render = new HtmlToPdf();
    render.PrintOptions.InputEncoding = Encoding.UTF8;
    render.PrintOptions.PaperSize = PdfPrintOptions.PdfPaperSize.A4;
    render.PrintOptions.PaperOrientation = PdfPrintOptions.PdfPaperOrientation.Portrait;
    render.PrintOptions.MarginBottom = 0;
    render.PrintOptions.MarginLeft = 0;
    render.PrintOptions.MarginRight = 0;
    render.PrintOptions.MarginTop = 6.3;
    render.PrintOptions.GenerateUniqueDocumentIdentifiers = false;

    return render.RenderHtmlAsPdf(htmlContent).BinaryData;
}

Given

public Task SomeScenario(request Request);
{
    var a = GetFile(request);
    var b = GetFile(request);

    /* a should equal b */
}

However A does not equal B and the binary data differs even though GenerateUniqueDocumentIdentifiers is set.

user-named-void commented 2 years ago

Having the same issues, the same html does not result in the same bytes. Tested with the latest available version 2022.1.4599