Block length does not match with its complement

Hi,

When I use the aspose.pdf and create document and load the pdf using EssentialObjects.PDFDocument(), it is throwing the following error.

Block length does not match with its complement.

Is there any measures that need to be taken from aspose while saving the file.

Could you please.

Below is the implementations:

HttpResponseMessage result = null;
var httpRequest = HttpContext.Current.Request;

invokePDF objInvoke = new invokePDF();
Document doc = new Document(HttpContext.Current.Server.MapPath("~/Convert/output.pdf"));

//Create image stamp
ImageStamp imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("~/test.png"));

for (int i = 0; i < wholeData.shapes.Count; i++)
{
//create stamp
Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

float shapeX = (wholeData.shapes[i].x * 72 / 150) / (float)Convert.ToDouble(wholeData.shapes[i].ratio);
float shapeY = (wholeData.shapes[i].y * 72 / 150) / (float)Convert.ToDouble(wholeData.shapes[i].ratio);
float shapeW = (wholeData.shapes[i].w * 72 / 150) / (float)Convert.ToDouble(wholeData.shapes[i].ratio);
float shapeH = (wholeData.shapes[i].h * 72 / 150) / (float)Convert.ToDouble(wholeData.shapes[i].ratio);

double yaxis = (float)(doc.Pages[wholeData.shapes[i].p].Rect.URY - (shapeH + shapeY));

var isSpecial = true;//regexItem.IsMatch(wholeData.shapes[i].imName);

if (wholeData.shapes[i].Itype == “highlight” || wholeData.shapes[i].Itype == “image”)
{

if (wholeData.shapes[i].Itype == “highlight”)
{
imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath(“test.png”));
}
else
{

imageStamp = new ImageStamp(HttpContext.Current.Server.MapPath("~/Images/" + wholeData.shapes[i].imName));

}

imageStamp.Background = false;
imageStamp.XIndent = (float)(shapeX);
imageStamp.YIndent = (float)(yaxis);
imageStamp.Height = shapeH;
imageStamp.Width = shapeW;

//Add stamp to particular page
doc.Pages[wholeData.shapes[i].p].AddStamp(imageStamp);
}
else if (wholeData.shapes[i].Itype == “text”)
{

//create text stamp
TextStamp textStamp = new TextStamp(wholeData.shapes[i].t);
//set whether stamp is background
// textStamp.Background = true;
//set origin
textStamp.XIndent = (float)(shapeX);
textStamp.YIndent = (float)(yaxis);
//rotate stamp
textStamp.RotateAngle = 360 - ((Convert.ToDouble(wholeData.shapes[i].fieldType)) * 180 / Math.PI);

//set text properties
textStamp.TextState.Font = FontRepository.FindFont(wholeData.shapes[i].n);
textStamp.TextState.FontSize = Convert.ToInt32(wholeData.shapes[i].s) * 0.75f;

if (wholeData.shapes[i].wt == “bold”)
{
textStamp.TextState.FontStyle = FontStyles.Bold;
}

if (wholeData.shapes[i].st == “italic”)
{
textStamp.TextState.FontStyle = FontStyles.Italic;
}


textStamp.TextState.ForegroundColor = objInvoke.GetColor(wholeData.shapes[i].c);
//add stamp to particular page
doc.Pages[wholeData.shapes[i].p].AddStamp(textStamp);

}
else if (wholeData.shapes[i].Itype == “field” && isSpecial)
{
if (wholeData.shapes[i].fieldType == “Text”)
{
// Get a field
TextBoxField textBoxField = doc.Form.Fields[Convert.ToInt32(wholeData.shapes[i].imName)] as TextBoxField;
// Modify field value
textBoxField.Value = wholeData.shapes[i].t;

}
else if (wholeData.shapes[i].fieldType == “CheckBox”)
{

// Get a field
CheckboxField checkBoxField = doc.Form.Fields[Convert.ToInt32(wholeData.shapes[i].imName)] as CheckboxField;
if (wholeData.shapes[i].t != “”)
// Modify field value
checkBoxField.Checked = Convert.ToBoolean(wholeData.shapes[i].t);
}
else if (wholeData.shapes[i].fieldType == “Radio”)
{
string[] txtString = wholeData.shapes[i].t.Split(’,’);
RadioButtonField radio = new RadioButtonField(doc.Pages[1]);
radio.PartialName = txtString[0];
FloatingBox fb = new FloatingBox();
fb.Left = (float)(shapeX * 0.05f);
fb.Top = (float)(shapeY * 0.9f);
doc.Pages[wholeData.shapes[i].p].Paragraphs.Add(fb);
//fb.Width = 50.0f;
RadioButtonOptionField opt1;
for (int loopStrArr = 1; loopStrArr < txtString.Length; loopStrArr++)
{
opt1 = new RadioButtonOptionField();
opt1.OptionName = txtString[loopStrArr].Replace(" ", string.Empty);
opt1.Width = Convert.ToInt32(wholeData.shapes[i].s);
opt1.Height = Convert.ToInt32(wholeData.shapes[i].s);
opt1.Caption = new Aspose.Pdf.Text.TextFragment(txtString[loopStrArr]);
radio.Add(opt1);
fb.Paragraphs.Add(opt1);

}
doc.Form.Add(radio);
}
else if (wholeData.shapes[i].fieldType == “ComboBox”)
{

// Get a field
ComboBoxField comboBoxField = doc.Form.Fields[Convert.ToInt32(wholeData.shapes[i].imName)] as ComboBoxField;
var values = wholeData.shapes[i].t.Split(new string[] { “^^^” }, StringSplitOptions.None)[0];

foreach (var item in comboBoxField.Options.Cast())
{
if (item.Value == values)
{

comboBoxField.Selected = item.Index;
}
}
}
}

}

doc.Save(HttpContext.Current.Server.MapPath(”~/Convert/Export.pdf"));

Hi,


Thank you for contacting support. Kindly share the input PDF, image and complete code. Your code is not in fully compilable form because the “wholedata” object is not defined. We need to replicate the same issue in our environment, and then we will be able to investigate and fix it. Your response is awaited.