Hello,
I using the community license of syncfusion Xls.IO. I am in an Razor Application in .Net 6.0 hosted in a docker.
I am using latest nuget :
I need to convert all worksheet of an Excel File identically to PDF but the convertion is not working for all my files ..Only part of the XLSX File is converted to PDF.
If i use your live demo (http://asp.syncfusion.com/demos/web/xlsio/exceltopdf.aspx) the problem is repoduced.
My code :
/// <summary>
/// Converts the workbook to PDF.
/// </summary>
/// <param name="workbook">The workbook.</param>
/// <param name="orientationMode">The orientation mode.</param>
/// <param name="settings">The settings.</param>
/// <returns></returns>
private static PdfDocument ConvertWorkbookToPDF(this IWorkbook workbook, OrientationMode orientationMode, PdfSettings settings)
{
//Intialize the PdfDocument Class
var pdfDoc = new PdfDocument
{
Compression = PdfCompressionLevel.None
};
// Configure Renderer
XlsIORenderer renderer = new();
// Allow chart rendering
renderer.ChartRenderingOptions.ImageFormat = ExportImageFormat.Png;
renderer.ChartRenderingOptions.ScalingMode = ScalingMode.Best;
//Intialize the ExcelToPdfConverterSettings class
var _XlsIORendererSettings = new XlsIORendererSettings
{
EmbedFonts = true,
AutoDetectComplexScript = true,
ExportBookmarks = false,
ExportDocumentProperties = true,
ExportQualityImage = false,
EnableFormFields = false,
ThrowWhenExcelFileIsEmpty = true,
IsConvertBlankPage = false,
IsConvertBlankSheet = false,
RenderBySheet = true,
PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B,
DisplayGridLines = GridLinesDisplayStyle.Auto,
//Assign the output PdfDocument to the TemplateDocument property of ExcelToPdfConverterSettings
TemplateDocument = pdfDoc
};
//Set the layout options of converter settings
if (orientationMode == Application.Enums.OrientationMode.Portrait)
{
// Portrait
_XlsIORendererSettings.TemplateDocument.PageSettings.Orientation = PdfPageOrientation.Portrait;
_XlsIORendererSettings.TemplateDocument.PageSettings.Size = PdfPageSize.A4;
}
else
{
// Landscape
_XlsIORendererSettings.TemplateDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;
_XlsIORendererSettings.TemplateDocument.PageSettings.Size = PdfPageSize.A3;
}
_XlsIORendererSettings.LayoutOptions = LayoutOptions.FitSheetOnOnePage;
_XlsIORendererSettings.TemplateDocument.PageSettings.Margins.All = 0.1f;
pdfDoc = renderer.ConvertToPDF(workbook, _XlsIORendererSettings);
return pdfDoc;
}
Could you help me ?
Thank you.
Only the range in Print Area is being converted to PDF because the input Excel document has Print Area configured. This is the behaviour of Microsoft Excel. Hence, we suggest you clear the print area in the input document and use that for conversion.
Thank you for your response, i will try your solution.
You're welcome, Nonobis. Please try the solution and contact us if you need any further assistance.