Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pdf Margin with no units #2741

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
"parameters": ["firefox", "headful"],
"expectations": ["FAIL"]
},
{
"comment": "This is flaky on CI/CD",
"testIdPattern": "[oopif.spec] OOPIF should provide access to elements",
"platforms": ["win32"],
"parameters": ["chrome"],
"expectations": ["FAIL"]
},
{
"comment": "",
"testIdPattern": "[puppeteer-sharp] *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task ShouldWorkWithBothDomcontentloadedAndLoad()
}
}).ContinueWith(_ => bothFired = true);

await waitForRequestTask.WithTimeout();
await waitForRequestTask.WithTimeout(5_000);
await domContentLoadedTask.WithTimeout();
Assert.That(bothFired, Is.False);
responseCompleted.SetResult(true);
Expand Down
22 changes: 22 additions & 0 deletions lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,27 @@ public void PdfOptionsShouldBeSerializable()
var newPdfOptions = JsonSerializer.Deserialize<PdfOptions>(serialized);
Assert.That(newPdfOptions, Is.EqualTo(pdfOptions));
}

[Test]
public void PdfOptionsShouldWorkWithMarginWithNoUnits()
{
var pdfOptions = new PdfOptions
{
Format = PaperFormat.A4,
DisplayHeaderFooter = true,
MarginOptions = new MarginOptions
{
Top = "0",
Right = "0",
Bottom = "0",
Left = "0"
},
FooterTemplate = "<div id=\"footer-template\" style=\"font-size:10px !important; color:#808080; padding-left:10px\">- <span class=\"pageNumber\"></span> - </div>"
};

var serialized = JsonSerializer.Serialize(pdfOptions);
var newPdfOptions = JsonSerializer.Deserialize<PdfOptions>(serialized);
Assert.That(newPdfOptions, Is.EqualTo(pdfOptions));
}
}
}
4 changes: 2 additions & 2 deletions lib/PuppeteerSharp/Cdp/CdpPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,14 +1221,14 @@ private decimal ConvertPrintParameterToInches(object parameter)
}

decimal pixels;
if (parameter is decimal || parameter is int)
if (parameter is decimal or int)
{
pixels = Convert.ToDecimal(parameter, CultureInfo.CurrentCulture);
}
else
{
var text = parameter.ToString();
var unit = text.Substring(text.Length - 2).ToLower(CultureInfo.CurrentCulture);
var unit = text.Length > 2 ? text.Substring(text.Length - 2).ToLower(CultureInfo.CurrentCulture) : string.Empty;
string valueText;
if (_unitToPixels.ContainsKey(unit))
{
Expand Down
Loading