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

Free Support Forum - aspose.com

Can not open a pdf file by adobe reader converted from word

hi,
I have a docx file converted into a pdf file. But I can't open it by the newest adobe reader application on my computer. Although the pdf file can been opened by chrome web browser and Foxit Reader.
I got the follow error message when I open the pdf file by adobe reader:
An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the pdf document to correct the problem.

thanks.

Hi there,


Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for .NET 16.3.0 and have not found the shared issue. Please use Aspose.Words for .NET 16.3.0. We have attached the output Pdf with this post for your kind reference.

Thanks for reply, I have tested the new dll found it works will. But when I add a PdfPageStamp to the pdf, the problem appears again.



watermarkSetting=new WatermarkSetting
{
Watermark=“hello from louis”,
WatermarkFontSize=18,
WatermarkFont=“Calibri”
}

Code:

public static Byte[] AddContentWatermarkForPdf(Byte[] pdfBytes, WatermarkSetting watermarkSetting)
{
using (var pdfStream = new MemoryStream(pdfBytes))
using (var pdfDocument = new Aspose.Pdf.Document(pdfStream))
using (var singlePdfStream = new MemoryStream(GetSinglePdf(pdfBytes, watermarkSetting)))
using (var resultStream = new MemoryStream())
{
var pageCount = pdfDocument.Pages.Count;
var pdfStamp = new PdfPageStamp(singlePdfStream, 1);
pdfStamp.XIndent = 0;
pdfStamp.YIndent = 0;
pdfStamp.Opacity = watermarkSetting.Opacity;
for (int index = 1; index <= pageCount; index++)
{
pdfDocument.Pages[index].AddStamp(pdfStamp);
}
pdfDocument.Save(resultStream, SaveFormat.Pdf);
return resultStream.ToBytes();
}
}




private static Byte[] GetSinglePdf(Byte[] pdfBytes, WatermarkSetting watermarkSetting)
{
using (var stream = new MemoryStream(pdfBytes))
using (var pdfDocument = new Aspose.Pdf.Document(stream))
{
return GetSinglePdf(pdfDocument.Pages[1].MediaBox.Height, pdfDocument.Pages[1].MediaBox.Width, watermarkSetting);
}
}

private static Byte[] GetSinglePdf(Double height, Double width, WatermarkSetting watermarkSetting)
{
try
{
Aspose.Pdf.Text.FontRepository.FindFont(watermarkSetting.WatermarkFont);
}
catch
{
watermarkSetting.WatermarkFont = “Calibri”;
}
watermarkSetting.WatermarkFontSize = watermarkSetting.WatermarkFontSize.Replace(“pt”, “”).Replace(“Pt”, “”);
var fontSize = 48;
Int32.TryParse(watermarkSetting.WatermarkFontSize, out fontSize);
watermarkSetting.WatermarkFontSize = fontSize + “”;

using (var g = Graphics.FromImage(new Bitmap(800, 800)))
using (var ms = new MemoryStream())
{
g.PageUnit = GraphicsUnit.Pixel;

using (var transparentImg = new Bitmap((Int32)width, (Int32)height))
using (var transparentG = Graphics.FromImage(transparentImg))
using (var transparentPNGMS = new MemoryStream())
{
transparentG.Clear(System.Drawing.Color.Transparent);
transparentImg.Save(transparentPNGMS, ImageFormat.Png);
using (var middleStream = new MemoryStream(transparentPNGMS.ToArray()))
{
var PdfConvertorFactory = new PdfConvertorFactory();
using (var transparentPdfStream = PdfConvertorFactory.GetConvertor(“png”).Convert(middleStream))
using (var mmStream = new MemoryStream(transparentPdfStream.ToBytes()))
using (var singlePdf = new Aspose.Pdf.Document(mmStream))
using (var resultStream = new MemoryStream())
{
singlePdf.Background = Aspose.Pdf.Color.Transparent;
var formatedSingleText = formateSingleText(watermarkSetting);
var textStamp = new TextStamp(formatedSingleText);
SetSingleStamp(textStamp, watermarkSetting, width, height);
System.Drawing.Font _Font = new System.Drawing.Font(watermarkSetting.WatermarkFont, (float)fontSize, System.Drawing.FontStyle.Regular);
SizeF _SizeF = g.MeasureString(watermarkSetting.Watermark, _Font);
var textHeight = _SizeF.Height;
var textWidth = _SizeF.Width;
//add stamp to particular page
if (watermarkSetting.IsRepeated)
{
if (watermarkSetting.Direction == -90)
{
for (int i = 0; i < width / (textWidth - 25); i++)
{
for (int j = 0; j < height / (textHeight + 25); j++)
{

//setStamp(ts, entity);
textStamp.XIndent = j * (textHeight - 25) + 10;
textStamp.YIndent = i * (textWidth + 25);
singlePdf.Pages[1].AddStamp(textStamp);
}
}
}
else
{
for (int i = 0; i < height / (textHeight + 25); i++)
{
for (int j = 0; j < width / (textWidth - 25); j++)
{
//setStamp(ts, entity);
textStamp.XIndent = j * (textWidth - 25) + 10;
textStamp.YIndent = i * (textHeight + 25);
singlePdf.Pages[1].AddStamp(textStamp);
}
}
}
}
else
{
singlePdf.Pages[1].AddStamp(textStamp);
}
singlePdf.Save(resultStream, SaveFormat.Pdf);
return resultStream.ToArray();
}
}
}
}
}









public class WatermarkSetting
{

public String Watermark { get; set; }

public String WatermarkFont { get; set; }

public String WatermarkFontSize { get; set; }

public Color WatermarkColor { get; set; }

public Double Opacity { get; set; }

public Boolean IsRepeated { get; set; }
}


Hi there,


Thanks for your inquiry. Your query is related to Aspose.Pdf. I am moving this forum thread to Aspose.Pdf forum. Aspose.Pdf team will investigate the issue and reply you about it.

Hi there,


We are sorry for the delayed response. In reference to your another query, we have already noticed the issue and logged a ticket PDFNEWNET-40704 in our issue tracking system. We will notify you as soon as it is resolved.

Best Regards,