We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Problem while converting word docs into pdf

I am using syncfusion for one of my client.

While converting word documents into pdf, that it aligns the documents left in the pdf file while in the original document, alignment was centered.

And also images on a word docs does not get transferred over when its converted to pdf.

Please provide me solution for this problem.


21 Replies

BP Bhuvaneswari P Syncfusion Team November 17, 2008 12:05 PM UTC

Hi Sandeep,

Thank you for your interest in Syncfusion products.

Could you please clarify me how you are converting Doc to PDF. If you are using Doc to HTML then HTML to PDF. If so could you please provide your word document to reproduce the issue in our end, since we are not able to reproduce the issue in our end.


Best Regards,
Bhuvana



AD Administrator Syncfusion Team November 18, 2008 01:08 PM UTC

Below are the codes i am using to convert .doc into pdf in c#.

MemoryStream ms = ConvertToPdf(hifUploadFile.PostedFile.InputStream);

protected MemoryStream ConvertToPdf(Stream st)
{


HtmlConverter html = new HtmlConverter();
WordDocument wd = new WordDocument(st, FormatType.Doc); // Save stream to word document

HTMLExport htmlExport = new HTMLExport();
MemoryStream PDF_STREAM = new MemoryStream();
MemoryStream HTML_STREAM = new MemoryStream();


htmlExport.SaveAsXhtml(wd, HTML_STREAM); // Convert Doc to html


Byte[] bt = HTML_STREAM.GetBuffer();




PdfDocument doc = new PdfDocument();
doc.PageSettings.Margins.All = 10;
doc.PageSettings.Width =750f;

PdfPage page = doc.Pages.Add();
PdfGraphics g = page.Graphics;
SizeF pageSize = page.GetClientSize();

PdfUnitConvertor convertor = new PdfUnitConvertor();


using (MemoryStream PDF_STREAM1 = new MemoryStream(bt))
{
using (System.Drawing.Image img = html.ConvertToImage(PDF_STREAM1, System.Text.Encoding.UTF8 , ImageType.Metafile,1024,-1,AspectRatio.KeepWidth))
{
PdfMetafile metafile = (PdfMetafile)PdfImage.FromImage(img);
if (img.Size.Width > pageSize.Width)
{
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
format.SplitTextLines = false;
metafile.Draw(page, new RectangleF(0, 0, pageSize.Width, pageSize.Height), format);
}
else
{
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
format.SplitTextLines = false;
metafile.Draw(page, new RectangleF(0, 0, img.Width, img.Height), format);

}
}
}

doc.Save(PDF_STREAM);
doc.Close();

return PDF_STREAM;

}



>Hi Sandeep,

Thank you for your interest in Syncfusion products.

Could you please clarify me how you are converting Doc to PDF. If you are using Doc to HTML then HTML to PDF. If so could you please provide your word document to reproduce the issue in our end, since we are not able to reproduce the issue in our end.


Best Regards,
Bhuvana





BP Bhuvaneswari P Syncfusion Team November 19, 2008 12:17 PM UTC

Hi Sandeep,

Thanks for the code and details.

Could you please provide your word document, so that we can reproduce in our end and provide a solution.

Best Regards,
Bhuvana



AD Administrator Syncfusion Team November 19, 2008 03:26 PM UTC

Here is document file in the attachement.

Thanks and Regards

Sandeep Verma

>Hi Sandeep,

Thanks for the code and details.

Could you please provide your word document, so that we can reproduce in our end and provide a solution.

Best Regards,
Bhuvana





Acknowledgement letter_6dcb7a4b.zip


BP Bhuvaneswari P Syncfusion Team November 20, 2008 04:39 AM UTC

Hi Sandeep,

Thanks for the document.

I am able to reproduce the issue in the given docx file, the image is not preserved, so the content is moved to up. But this is working fine for doc format. The image and the alignments are perfect.

We suspect the issue "While converting the docx file to html the image is not preserved “to be a defect and we have forwarded this to our development team for more analysis. We will update you in two business days with more details.

Here is the output PDF document after converting the .doc file to PDF:
http://websamples.syncfusion.com/samples/DocIO.Windows/77744_Sample.pdf

Best Regards,
Bhuvana




AD Administrator Syncfusion Team November 21, 2008 05:50 AM UTC

Can you please test this attached .doc file for both alignment and images.

Thanks and Regards
Sandeep Verma



BP Bhuvaneswari P Syncfusion Team November 21, 2008 06:01 AM UTC

Hi Sandeep,

I couldn't find any attachment in your last update. Can you please send the .doc file once again. So that I can test and update you.

Best Regards,
Bhuvana



AD Administrator Syncfusion Team November 21, 2008 06:25 AM UTC

If pdf conversion of the sent doc file works perfect, please show me the code you are using to covert doc/docs into pdf(using memory stream).


Thanks and Regards
Sandeep Verma



AD Administrator Syncfusion Team November 21, 2008 06:28 AM UTC

I am sending again the doc file in the attachement.

If pdf conversion of the sent doc file works perfect, please show me the code you are using to covert doc/docs into pdf(using memory stream).


Thanks and Regards
Sandeep Verma




Adjusters Priveleged and Confidential Report_New_86a96e40.zip


BP Bhuvaneswari P Syncfusion Team November 21, 2008 12:24 PM UTC

Hi Sandeep,

Thanks for the update.

I am able to reproduce the issue when streaming the HTML into the PDF file. I have forward regarding this to our development team for more analysis and I will update the details by Monday.

Best Regards,
Bhuvana




AD Administrator Syncfusion Team November 27, 2008 09:09 AM UTC

Please update me regarding the current issue.



Thanks and Regards
Sandeep Verma



AD Administrator Syncfusion Team December 2, 2008 10:33 AM UTC

Hi Bhuvana,

I am waiting for your reply since 11/21/2008 7:24:46 AM as you replied previously
"I am able to reproduce the issue when streaming the HTML into the PDF file. I have forward regarding this to our development team for more analysis and I will update the details by Monday."

So, Please suggest me solution as it is most important requirement for my client.

Thanks and Regards
Sandeep Verma




BP Bhuvaneswari P Syncfusion Team December 2, 2008 10:41 AM UTC

Hi Sandeep,

We regret for the delay in responding.

This issue has been confirmed as a defect and our developers are working on this to fix this issue. Fix for the issue will be available on or before December 5 , 2008. We will get back to you on the specified date.

Thank you for your patience.

Best Regards,
Bhuvana




AD Administrator Syncfusion Team December 3, 2008 09:46 AM UTC

Thanks for reply.


Thanks and Regards
Sandeep Verma



AD Administrator Syncfusion Team December 15, 2008 12:51 PM UTC

Hi Bhuvana,

I am still waiting for your reply since as you mentioned in the previous mail that
Fix for the issue will be available on or before December 5 , 2008.


Thanks and Regards
Sandeep Verma




BP Bhuvaneswari P Syncfusion Team December 16, 2008 12:52 PM UTC

Hi Sandeep,

Sorry for the delay in getting back to you.

Unfortunately we are unable to fix this issue in the specified time frame. Currently our developers are working on this issue. We will try to fix this issue on or before Dec 29th, 2008 and we will get back to you one the specified date. We regret for the fix delay.

Best Regards,
Bhuvana




BP Bhuvaneswari P Syncfusion Team December 24, 2008 04:03 AM UTC

Hi Sandeep,

After analysis the issue we found the below details.

When you save a Document in HTML DocIO needs to save all images embedded in the document as standalone files. If you save the document into a file and provide a file name, DocIO saves the embedded images in the same folder where the document file is saved.

However, if you save the document into a stream, DocIO does not have a folder where to save the images, but still needs to save the embedded images somewhere as files. In this case, HtmlExportImagesFolder allows you to specify where the images will be save.

Please refer the below code snippet to do so:

wd.SaveOptions.HtmlExportImagesFolder = Server.MapPath(".");
htmlExport.SaveAsXhtml(wd, HTML_STREAM);


So please export the images into the folder before streaming the HTML page. Let me know if you need any further details.

Best Regards,
Bhuvana




AD Administrator Syncfusion Team December 31, 2008 01:24 PM UTC

Hello Bhuvana,

Thanks for reply,

I am implementing your solution but problem still occurs. Images are not shown in pdf file even though images are saved in the specified location using
wd.SaveOptions.HtmlExportImagesFolder = Server.MapPath("~/Files/Images");

Sometime i receives following error : --

"An exception of type 'System.Runtime.InteropServices.ExternalException' occurred in Syncfusion.DocIO.Base.dll but was not handled in user code

Additional information: Couldnt create storage."



"An exception of type 'System.Runtime.InteropServices.COMException' occurred in AxSHDocVw.DLL but was not handled in user code

Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component."

The code i using is in the attached file.

Please test it in your side and give me solution.

Thanks and Regards

Sandeep Verma



Code_523b8663.zip


BP Bhuvaneswari P Syncfusion Team January 2, 2009 02:09 PM UTC

Hi Sandeep,

Thanks for the update and code.

I am able to reproduce the issue and I have forward regarding this to our development team and I will get back you within two business days time frame.

Best Regards,
Bhuvana




AL AlexK July 22, 2010 03:25 PM UTC

My friend often works with doc files. He opened and started working with his document but something happened. He lost whole data. Luckily he told me this incident some days ago. I advised him a tool - [url=http://www.recoverytoolbox.com/how_to_recover_word_files_after_windows_recovery.html]how to recover word files[/url]. And to my and his great surprise it relieved him quite easy. Today I have used it too and I'm glad...


AL AlexK July 22, 2010 03:25 PM UTC

My friend often works with doc files. He opened and started working with his document but something happened. He lost whole data. Luckily he told me this incident some days ago. I advised him a tool - [how to recover word files. And to my and his great surprise it relieved him quite easy. Today I have used it too and I'm glad...

Loader.
Live Chat Icon For mobile
Up arrow icon