PDF saves with 0 bytes and no errors

Today I have discovered some very odd behaviour with the PDF Generator.





I had a web service that takes in a JSON object which is serialised into custom .NET class structure I have built. This all works fine and the data populates the object with all the correct information.



Many PDFs have been successfully created with this web service with no issue whatsoever until today (Though the system has only been running for around 3-4 weeks).



When the web service receives a specific set of data our client was attempting to post, it created a 0 byte PDF file. All the PDF creation is surrounded by a try/catch block and no exceptions were thrown. When trying to open the PDF Windows 8 PDF viewer app would just say its unable to open the file.



As there was no error I attempted a trial and error approach to the problem. Removing certain elements from the PDF until it would build properly.



In the PDF that is created I have a number of sections, each of these sections have a number of tables which contain a number of rows. The first thing I did was to disable all images within these sections which still resulted in the 0 byte PDF. I then commented out the creation of the table rows. This produced a readable PDF.



I then added the row creation back in and started removing columns from the rows and found the precise column causing the issue. However the problem with this column is only affected by 1 of the 100+ rows that are created across the PDF. This specific row and input happened to be an empty string “” which there are about 50 other rows that have this as an empty cell which seems to generate the PDF fine when this particular row is emitted from the PDF.



The next thing I tried was to enter some text into this column for that particular row. ‘test’. This also seemed to generate the PDF fine. So it would appear that out of 100+ rows, a random row in the middle of all of them, having a empty string “” value caused the PDF to break, despite many rows before and after this has the same column as an empty string “”.



Now whats more is, after I uncommented the image adding to double check it would all work if I replace “” with " ". This still had the same issue with producing a 0 byte PDF. So now I have a similar issue with images somewhere else in the PDF. So I went through the process of narrowing down which row was causing this to happen, which I found. This row itself does not actually contain an image and thus executes no Aspose functions of any kind. If I set an if statement to skip this row, but uncomment the images code, the PDF creates fine again, but without that row. So somehow now another random table row, in the middle of 100+ rows is somehow causing an issue with another rows image to cause a 0 byte pdf.



To make matters even more confusing. As it is an iOS app that is hooked into this web service. We used the app to remove this row altogether from the section. Posted the data back to the web service, and the PDF created fine. We then re-added this row (which put it at the end of the section instead of the middle) with exactly the same data input, posted to the server and it created fine.



Im really quite confused how something like this could even be happening, clearly something is going wrong when saving this PDF as its being created as 0 bytes, but how does this not throw an error at all? And how can moving a row of data from the middle, which causes it to break, to the end of the table somehow fix this issue. Or how can a row having an empty string “” cause an issue but putting a space in it " " doesn’t?



My biggest concern at the moment is as far as we know, this could happen to any PDF being uploaded in the future as well. Currently the system in use is creating between 2-4 certificates a day, but this could very well increase. We certainly can’t spend several hours or days each time a PDF randomly doesn’t create properly, trying to find which row is causing the problem and trying to remove/add rows until it works again.



Im not sure what kind of information is needed to look into this. There is quite a bit of code as we are producing 40-60 + page documents.



Thanks in advance.

Hi Chris,


Thanks for your inquiry. I am afraid it is difficult to investigate the issue without replicating it at our end. We will appreciate it if you please share sample code(console application) and problematic source documents(Images/files) here, so we will test the scenario and will provide you more information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi,



Thanks for your response. Its hard to supply sample code from a console application when we have trouble replicating it ourselves. Without all the data from the first issue we found (which is around 10mb of json) the issue does not happen very often. Today we have a reported second file that is just not creating the PDF. Without giving you the web service and the json file in question I’m not sure how easy it will be to replicate on a smaller scale. Again, about 10 other PDFs have gone through and created just fine.



What we have noticed today however is when we log into the server and try to copy/paste the pdf we get an error from windows saying ‘The action can’t be completed because the file is open in IIS Worker Process’. This sounds like IIS may still have access to the file, and has potentially kept the file locked and not written the data to the file yet? Not sure why the save function would pass this without any issues though.



Does this new information help shed any light on this issue?



Thanks

Hi Chris,


Thanks for your feedback. It is quite difficult to suggest anything without replicating the issue. However, I am coordinating with our development team and will update you the findings.

We are sorry for the inconvenience caused.

Best Regards,