Hi AsposeTeam,
The requirement of my project is to convert a html file to images and insert these images into a pdf document.
THe code I am using is as follows:
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(@"C:\Jetstream\500\Resources\net3.5_ClientProfile\Aspose.Words.lic");
Aspose.Pdf.License license2 = new Aspose.Pdf.License();
license2.SetLicense(@"C:\Jetstream\500\Resources\Aspose.Pdf.Kit.lic");
//load the html file into Aspose.Words
Aspose.Words.LoadOptions lo = new Aspose.Words.LoadOptions();
lo.LoadFormat = Aspose.Words.LoadFormat.Html;
//Aspose.Words.Document doc = new Aspose.Words.Document(@"D:\Aspose\RDP\NEWFiles\Depp_backup.htm", lo);
Aspose.Words.Document doc = new Aspose.Words.Document(@"D:\Aspose\RDP\NEWFiles\ImagePDF2.html", lo);
//Make the text display in individual rows
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
foreach (Aspose.Words.Tables.Table tbl in tables)
{
tbl.AllowAutoFit = true;
tbl.AutoFit(AutoFitBehavior.AutoFitToWindow);
// tbl.AutoFit(AutoFitBehavior.AutoFitToContents);
//tbl.AutoFit(AutoFitBehavior.FixedColumnWidths);
//tbl.Alignment = TableAlignment.Left;
tbl.Alignment = TableAlignment.Left;
foreach (Aspose.Words.Tables.Row r in tbl.Rows)
{
r.RowFormat.AllowBreakAcrossPages = false;
// r.RowFormat.AllowAutoFit = true;
//NodeCollection cells = r.Cells;
foreach (Aspose.Words.Tables.Cell c in r.Cells)
{
c.CellFormat.WrapText = false;
//CellFormat.PreferredWidth = PreferredWidth.FromPercent(100);
//c.CellFormat.PreferredWidth = PreferredWidth.FromPoints(1000);
}
}
}
////Generate the images
doc.Save(@"D:\Aspose\RDP\NEWFiles\Depp_DOc.doc");
for (int pageCounter = 0, stop = doc.PageCount; pageCounter < stop; pageCounter++)
{
Aspose.Words.Saving.ImageSaveOptions options2 = new Aspose.Words.Saving.ImageSaveOptions(SaveFormat.Png);
options2.PageIndex = pageCounter;
options2.PrettyFormat = true;
// images are of the format \<0-padded-page-index>.png, e.g. (somepath\myfile02.png)
doc.Save(string.Format("{0}{1}{2}{3:d2}.png", "D:\\Aspose\\RDP\\NEWFiles\\Images\\", "", "MyImage", pageCounter + 1), options2);
}
//Aspose.Words.License license = new Aspose.Words.License();
//license.SetLicense(@"D:\jetstream\500\Resources\Aspose.Words.lic");
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
string[] fileEntries = Directory.GetFiles(@"D:\Aspose\RDP\NEWFiles\Images\", "*.png");
int length = fileEntries.GetLength(0);
int counter;
for (counter = 0; counter < length; counter++)
{
// Create a section object
Aspose.Pdf.Generator.Section section1 = pdf.Sections.Add();
// creat an image object
section1.PageInfo.PageWidth = Aspose.Pdf.Generator.PageSize.A4Width;
section1.PageInfo.PageHeight = Aspose.Pdf.Generator.PageSize.A4Height;
section1.PageInfo.Margin.Top = 0;
section1.PageInfo.Margin.Left = 0;
section1.PageInfo.Margin.Bottom = 0;
section1.PageInfo.Margin.Right = 0;
Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(section1);
image1.ImageInfo.File = fileEntries[counter];
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png;
image1.ImageInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;
image1.ImageInfo.FixHeight = section1.PageInfo.PageHeight - section1.PageInfo.Margin.Top - section1.PageInfo.Margin.Bottom;
// specify the image Width information eqaul to Section Width minus Left and Right margin of page
image1.ImageInfo.FixWidth = section1.PageInfo.PageWidth - section1.PageInfo.Margin.Left - section1.PageInfo.Margin.Right;
// Create a BitMap object in order to get the information of image file
//Bitmap myimage = new Bitmap(fileEntries[counter]);
//// check if the width of the image file is greater than Page width or not
//if (myimage.Width > section1.PageInfo.PageWidth)
//// // if the Image width is greater than page width, then set the page orientation to Landscape
// section1.IsLandscape = true;
//else
//// // if the Image width is less than page width, then set the page orientation to Portrait
section1.IsLandscape = false;
//// add the image to paragraphs collection of the PDF document
//section1.IsLandscape = false;
section1.Paragraphs.Add(image1);
}
pdf.Save(@"D:\Aspose\RDP\NEWFiles\Images_to_PDF_Conversion2.pdf");
The above code is working fine for ImagePdf2.htm…I am able to obtaing the CSS but not the client logo.(PLease see the attached folder by name “working”)
The above code is not working for “Depp_backup.htm”.I am not able to get the CSS applied as well as the client logo.(Please see the attached folder by “No Working”).
If you observer the “Depp_backup.htm” the columns are placed side by side in the browser.i.e in multiple columns.
THe CSS used for this purpose is: https://staging.brassring.com/WelcomePages.UserInterface/CSS/LayoutForms.css
.
Can you please look into the code and suggest me the changes need to be implemented to have the client logo as well as the fields to be displayed in multiple columns.
Thanks,
siddi.