In one of our applications, we are generating a pdf document by combining user input collected via DevExpress Rich Editor ( word like Editor)
Steps of Document generation process
1. Collect data from user for each Item as HTML via DevExpress Editor.
2. Store them in SQL Server database
3. Retrieve HTML from Database and generate separate documents for each Item.
4. Combine all the generated documents in to final document ( we are doing this as we have to add attachments in-between PDF pages)
The Problem.
Since user has the freedom to copy and paste content from anywhere, sometimes we come up with scenarios where users paste images that has a higher width compared to the document.
therefore when individual document is generated, sometimes we get pages that are slightly larger than usual width.
once we combine all individual pdf files, the section that contain the document with above mentioned issue becomes shrank ( about 70%)
This is the code we are using to save the HTML to individual PDF
- Code: Select all
private void ConvertHtmlToPdf(string content, string outputFileName, string fileOutputPath, bool isCoverPage)
{
string input = string.Empty;
PdfMargins margin = new PdfMargins();
margin.Top = 70;
margin.Bottom = 60;
margin.Left = Convert.ToInt32(90);
margin.Right = Convert.ToInt32(70);
input = @"<div style=""width: " + PageSize + @"px !important;"">" + content + @"</div>";
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(input,
outputFileName,
true,
10 * 1000,
PdfPageSize.A4,
margin,
LoadHtmlType.SourceCode
);
}
This is the code we are using to merge individual pdf in to one PDF
- Code: Select all
foreach (var item in combineFileList)
{
try
{
if (item.Type.Equals("AgendaGroupItem"))
{
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.LoadFromFile(outputFilePath + "AgendaGroupItem_" + item.PageName + ".pdf");
Doc.AppendPage(pdfDocument);
}
else if (item.Type.Equals("AttandaceReport"))
{
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.LoadFromFile(outputFilePath + "Attandance.pdf");
Doc.AppendPage(pdfDocument);
}
else if (item.Type.Equals("AgendaGroup"))
{
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.LoadFromFile(outputFilePath + "AgendaGroup_" + item.PageName + ".pdf");
Doc.AppendPage(pdfDocument);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Logger.Log(e);
}
}
Doc.SaveToFile(outputPath);
Can you please help me to get this fixed and keep all pages with equal width