- Home
- Forum
- Xamarin.Android
- Convert to PDF, large file size.
Convert to PDF, large file size.
Hello, I am creating a word document with images. When saving to a file, its size is 1Mb.
If I convert a document to PDF, when saving to a file, its size is 10Mb
10 times more, can this be somehow influenced? I need to reduce the file size.
string tempFileName = _dir.Path + "/pdfexample.pdf"
MemoryStream _ms = new MemoryStream();
DocIORenderer render = new DocIORenderer();
PdfDocument pdfDocument = render.ConvertToPDF(document);
render.Dispose();
document.Dispose();
pdfDocument.Save(_ms);
pdfDocument.Close();
using (FileStream _file = new FileStream(tempFileName, FileMode.Create, System.IO.FileAccess.Write)) _ms.CopyTo(_file);
SIGN IN To post a reply.
13 Replies
1 reply marked as answer
MR
Manikandan Ravichandran
Syncfusion Team
June 15, 2020 01:07 PM UTC
Hi Andrey,
Thank you for contacting Syncfusion support.
We unable to reproduce the mentioned issue using the given details in our end. So, could you please share the input document, output document and complete runnable sample or code example used at your end to reproduce the mentioned problem and also share the product version used at you end.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Thank you for contacting Syncfusion support.
We unable to reproduce the mentioned issue using the given details in our end. So, could you please share the input document, output document and complete runnable sample or code example used at your end to reproduce the mentioned problem and also share the product version used at you end.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
AB
Andrey Bogatov
June 16, 2020 04:00 AM UTC
Hello,
Attachment: pdfexample_b93e0525.zip
Version - 17.4451.0.39
Code:
WordDocument document = new WordDocument();
WSection section = document.AddSection() as WSection;
IWTable table = section.AddTable();
...
paragraph = table[RowCount, ColNum].AddParagraph();
IWPicture picture = paragraph.AppendPicture(stream);
...
MemoryStream _ms = new MemoryStream();
if (_PDF)
{
DocIORenderer render = new DocIORenderer();
PdfDocument pdfDocument = render.ConvertToPDF(document);
render.Dispose();
document.Dispose();
pdfDocument.Save(_ms);
pdfDocument.Close();
using (FileStream _file = new FileStream(tempFileName, FileMode.Create, System.IO.FileAccess.Write)) _ms.CopyTo(_file);
}
else
{
document.Save(_ms, Syncfusion.DocIO.FormatType.Doc);
using (FileStream _file = new FileStream(tempFileName, FileMode.Create, System.IO.FileAccess.Write)) _ms.CopyTo(_file);
}
Attachment: pdfexample_b93e0525.zip
MR
Manikandan Ravichandran
Syncfusion Team
June 16, 2020 01:50 PM UTC
Hi Andrey,
Thank you for your update.
We have tried to reproduce the reported issue using the provided code example, but it was working fine as expected in our end and the sample which we have used in our end to reproduce the issue can be downloaded from the following link.
Sample link:
https://www.syncfusion.com/downloads/support/forum/155189/ze/F155189_XamarinApp-210558241
Please find the out documents generated at our end from below link.
https://www.syncfusion.com/downloads/support/forum/155189/ze/Result695458290
If you are still facing the same issue, then kindly share the modified sample of above which will helpful for us to provide you the appropriate solution at the earliest.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Thank you for your update.
We have tried to reproduce the reported issue using the provided code example, but it was working fine as expected in our end and the sample which we have used in our end to reproduce the issue can be downloaded from the following link.
Sample link:
https://www.syncfusion.com/downloads/support/forum/155189/ze/F155189_XamarinApp-210558241
Please find the out documents generated at our end from below link.
https://www.syncfusion.com/downloads/support/forum/155189/ze/Result695458290
If you are still facing the same issue, then kindly share the modified sample of above which will helpful for us to provide you the appropriate solution at the earliest.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
AB
Andrey Bogatov
June 17, 2020 08:20 AM UTC
Hello,
The problem is not with the images.
When adding text in Cyrillic, one character is enough, it increases the file by more than 10MB.
Example: paragraph.AppendText("Я");
The problem on different devices with Android 9, 10. There is no such problem on Android 6 and 7.
MR
Manikandan Ravichandran
Syncfusion Team
June 18, 2020 04:00 PM UTC
Hi Andrey,
Thank you for your update.
We have tried to reproduce the mentioned issue at our end. But it was working fine. So, kindly provide us the complete sample or modified sample of the previously provided sample to reproduce the mentioned issue, so that we can proceed further to analyse and update you with the appropriate details. And, please see the video attached in the previous update and share the details which we missed in the replication procedure for reproduce the issue.
Please let us know if you have any further questions.
Regards,
Manikandan Ravichandran
Thank you for your update.
We have tried to reproduce the mentioned issue at our end. But it was working fine. So, kindly provide us the complete sample or modified sample of the previously provided sample to reproduce the mentioned issue, so that we can proceed further to analyse and update you with the appropriate details. And, please see the video attached in the previous update and share the details which we missed in the replication procedure for reproduce the issue.
Please let us know if you have any further questions.
Regards,
Manikandan Ravichandran
AB
Andrey Bogatov
June 19, 2020 12:21 AM UTC
Hello, in the attachment is an application that shows this problem.
Attachment: XamarinApp_1a53c950.zip
Attachment: XamarinApp_1a53c950.zip
MR
Manikandan Ravichandran
Syncfusion Team
June 19, 2020 05:48 PM UTC
Hi Andrey,
Sorry for the inconvenience.
We are facing some complexities to reproduce the reported problem at our end. Currently, we are checking on this problem with high priority and will update you with more details on 22nd June 2020
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Sorry for the inconvenience.
We are facing some complexities to reproduce the reported problem at our end. Currently, we are checking on this problem with high priority and will update you with more details on 22nd June 2020
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
MR
Manikandan Ravichandran
Syncfusion Team
June 22, 2020 05:08 PM UTC
Hi Andrey,
Sorry for the inconvenience.
We are facing some complexities to reproduce the reported problem at our end. Currently, we are checking on this problem with high priority and will update you with more details on tomorrow (23rd June 2020).
Meanwhile, we would like to set up a web meeting with you to reproduce the issue and provide the solution at earliest. Would you please let us know of your availability for this? Our team will make every effort to have this scheduled on a date and time per your convenience.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Sorry for the inconvenience.
We are facing some complexities to reproduce the reported problem at our end. Currently, we are checking on this problem with high priority and will update you with more details on tomorrow (23rd June 2020).
Meanwhile, we would like to set up a web meeting with you to reproduce the issue and provide the solution at earliest. Would you please let us know of your availability for this? Our team will make every effort to have this scheduled on a date and time per your convenience.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
MR
Manikandan Ravichandran
Syncfusion Team
June 23, 2020 06:08 PM UTC
Hi Andrey,
Sorry for the inconvenience.
We are facing some complexities to reproduce the reported problem at our end. Currently, we are checking on this problem with high priority and will update you with more details on tomorrow (24th June 2020).
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Sorry for the inconvenience.
We are facing some complexities to reproduce the reported problem at our end. Currently, we are checking on this problem with high priority and will update you with more details on tomorrow (24th June 2020).
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
MR
Manikandan Ravichandran
Syncfusion Team
June 24, 2020 04:47 PM UTC
Hi Andrey,
Thank you for your patience.
We can reproduce the mentioned issue with “File size increases while converting word document to PDF in Android version 9 and 10” at our end. We suspect this could be a defect and We will update you with more details on this on 26th June 2020.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Thank you for your patience.
We can reproduce the mentioned issue with “File size increases while converting word document to PDF in Android version 9 and 10” at our end. We suspect this could be a defect and We will update you with more details on this on 26th June 2020.
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
MR
Manikandan Ravichandran
Syncfusion Team
June 26, 2020 06:33 PM UTC
Hi Andrey,
Thank you for your patience.
On further validating the reported issue, we have found that it occurs due to the font size varies in different versions. We are using Skiasharp library as depend for rending the PDF which embed the necessary fonts in the PDF documents. Due to the embedding of fonts in PDF and various font size in android devices, the output PDF document has larger file size.
To overcome this file size increase issue, we suggest you to use font substitution event which will give constant file size in all versions and also we suggest you to update the Packages to latest version to avoid exception while using font substitution.
Please find the modified sample with font substitution event
https://www.syncfusion.com/downloads/support/forum/155189/ze/XamarinAppFontSubstitution93968727
Please refer the below UG link to know more about font substitution.
https://help.syncfusion.com/file-formats/docio/word-to-pdf?cs-save-lang=1&cs-lang=xamarin
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Thank you for your patience.
On further validating the reported issue, we have found that it occurs due to the font size varies in different versions. We are using Skiasharp library as depend for rending the PDF which embed the necessary fonts in the PDF documents. Due to the embedding of fonts in PDF and various font size in android devices, the output PDF document has larger file size.
To overcome this file size increase issue, we suggest you to use font substitution event which will give constant file size in all versions and also we suggest you to update the Packages to latest version to avoid exception while using font substitution.
Please find the modified sample with font substitution event
https://www.syncfusion.com/downloads/support/forum/155189/ze/XamarinAppFontSubstitution93968727
Please refer the below UG link to know more about font substitution.
https://help.syncfusion.com/file-formats/docio/word-to-pdf?cs-save-lang=1&cs-lang=xamarin
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
AB
Andrey Bogatov
June 30, 2020 06:29 AM UTC
Hello,
Attachment: exception_1991741d.zip
Your example is working correctly,
but when I added font substitution to my project,
I get an exception(System.NullReferenceException: Object reference not set to an instance of an object) on the line
PdfDocument pdfDocument = render.ConvertToPDF (document);
args.AlternateFontStream filled correctly, times.ttf file taken from your example
version 18.1.0.42
What can be done?
Attachment: exception_1991741d.zip
MR
Manikandan Ravichandran
Syncfusion Team
June 30, 2020 06:25 PM UTC
Hi Andrey,
Thank you for your update.
As mentioned earlier, to resolve the exception during the font substitution, we suggest you to update the NuGet packages to latest version (v18.1.0.59).
Please use the below link to download our latest weekly NuGet:
https://www.nuget.org/packages/Syncfusion.Xamarin.DocIORenderer/18.1.0.59
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Thank you for your update.
As mentioned earlier, to resolve the exception during the font substitution, we suggest you to update the NuGet packages to latest version (v18.1.0.59).
Please use the below link to download our latest weekly NuGet:
https://www.nuget.org/packages/Syncfusion.Xamarin.DocIORenderer/18.1.0.59
Please let us know if you have any other questions.
Regards,
Manikandan Ravichandran
Marked as answer
SIGN IN To post a reply.
- 13 Replies
- 2 Participants
- Marked answer
-
AB Andrey Bogatov
- Jun 15, 2020 04:50 AM UTC
- Jun 30, 2020 06:25 PM UTC