We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML is Ok, bit PDF not

Hello,

i try to generate a Info (HTML as transferformat) page with some infos and convert it to PDF.
The HTML in Temp Path seems good, but in the Output PDF, the text and the table is cut at the right side.

What i am doing wrong? :slight_smile:

TranformAndConvertToPdfIssue.zip (5,9 KB)

Kind regards,
Andy

@AStelzner

You are saving HTML to PDF using Aspose.PDF. You can also use Aspose.Words to save HTML to PDF. The issue you are facing is related to HTML table. We are moving this forum thread to Aspose.Words’ forum where you will be guided appropriately.

1 Like

@AStelzner In HTML format there is no page width concept, but in PDF or word document the content should fit the page. In your case the long string without whitespaces does not wrap properly and goes outside the page bounds. You can specify cell width explicitly to force the string wrap. For example see the following code:

var doc = new global::Aspose.Words.Document();

var builder = new DocumentBuilder(doc);
builder.PageSetup.Orientation = Orientation.Landscape;
double pageWidth = builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin;
                
var table = builder.StartTable();
builder.InsertCell();
// Specify width of the cell.
builder.CellFormat.Width = pageWidth;
builder.CellFormat.Borders.Right.Color = Color.FromArgb(204, 119, 119);
builder.CellFormat.Borders.Left.Color = Color.FromArgb(204, 119, 119);
builder.CellFormat.Borders.Top.Color = Color.FromArgb(204, 119, 119);
builder.CellFormat.Borders.Bottom.Color = Color.FromArgb(204, 119, 119);
builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(255, 221, 221);
builder.CellFormat.WrapText = true;
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Top;
builder.Font.Bold = true;
builder.InsertBreak(BreakType.LineBreak);
builder.Writeln("Folgende Fehler sind aufgetreten:");
builder.InsertBreak(BreakType.LineBreak);
builder.Font.Bold = false;
builder.Write(exceptionAfterTransformUsingCustomNamespaces.Message);
builder.InsertBreak(BreakType.LineBreak);
builder.EndRow();

builder.InsertCell();
// Specify width of the cell.
builder.CellFormat.Width = pageWidth;
builder.CellFormat.Borders.ClearFormatting();
builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
builder.RowFormat.HeightRule = HeightRule.Auto;
builder.Font.Bold = true;
builder.InsertBreak(BreakType.LineBreak);
builder.Writeln("Original XML:");
builder.InsertBreak(BreakType.LineBreak);
builder.Font.Bold = false;
builder.Write(inputXml);
builder.EndRow();
builder.EndTable();

table.AutoFit(AutoFitBehavior.FixedColumnWidths);

doc.Save(@"C:\Temp\out.html", new Aspose.Words.Saving.HtmlSaveOptions() { PrettyFormat = true});
doc.Save(@"C:\Temp\out.pdf", SaveFormat.Pdf);

Also, as Tahir mentioned you do not need Aspose.PDF in this case to save the document as PDF, you can save the created document directly to PDF using Aspose.Words.

1 Like