pdf Form and Print
I want to print out and Download the pdf in the SfPdfViewer2 in my Blazor Server Application.
The problem is that for my fillable form fields it actually prints the textbox with the data. All I want to print is the data and not the textbox. I can't seem to find any documentation regarding how to do that.
Thanks so much in advance.
Hi Charles Matvchuk,
Could you please confirm whether you would like to hide the border and background color of the form fields in the print preview? Based on your confirmation, we will review and provide a suitable workaround sample for your requirement.
Regards,
Venkada Subramanian Durai
The background and the border both need to be hidden, just the text should show on the printed pdf.
Hi Charles Matvchuk,
Sorry for the inconvenience. We will review your requirements and provide the sample by May 14, 2025.
Regards,
Venkada Subramanian Durai
Hi Charles Matvchuk,
We have prepared a
sample that meets your requirements. In the provided sample, we have used the
PrintStart event to update the thickness and background color of the form
fields to 0 and transparent, respectively. This ensures that in the print
preview, the background and border of the fields are hidden, and only the field
values are visible.
After a short delay, we reset the thickness and background color to their original values to ensure they are correctly restored in the PDF Viewer.
We have also attached a video for your reference. Please check whether it meets your requirements and feel free to reach out if you have any questions.
Code Snippet:
async Task OnPrintStart(PrintStartEventArgs
args)
{
if (Viewer != null)
{
formfields = await Viewer.GetFormFieldsAsync();
for (int i = 0; i < formfields.Count; i++)
{
// Store the original thickness
originalThickness[i] = formfields[i].Thickness;
originalBackgroundColors[i] = formfields[i].BackgroundColor;
FormFieldInfo field = formfields[i];
field.Thickness = 0;
field.BackgroundColor = "transparent";
await Viewer.UpdateFormFieldsAsync(new List<FormFieldInfo> { field });
}
// Schedule restoring thickness after 1.5 seconds, without blocking
_ = Task.Run(async () =>
{
await Task.Delay(1500);
for (int i = 0; i < formfields.Count; i++)
{
FormFieldInfo field = formfields[i];
field.Thickness = originalThickness[i];
field.BackgroundColor = originalBackgroundColors[i];
await Viewer.UpdateFormFieldsAsync(new List<FormFieldInfo> { field });
}
});
}
}
Sample
with PrintStart event
Regards,
- 4 Replies
- 2 Participants
-
CM Charles Matvchuk
- May 6, 2025 05:01 AM UTC
- May 14, 2025 03:51 AM UTC