I am encountering a situation where I open a PDF both in a web browser and in the Acrobat PDF viewer. In the browser, the PDF is displayed correctly, but in the PDF viewer, I get a different output file. I'm trying to identify whether this discrepancy is related to an issue with the PDF file itself or if there are inherent differences between the PDF viewer and the browser rendering.
Has anyone experienced a similar issue, and could you provide insights or suggestions on how to troubleshoot and resolve this? Additionally, are there known differences in how PDFs are rendered between web browsers and dedicated PDF viewers that might explain this behavior?
I am modifying pdf with pdftron and java 1.8 Code for adding element and text in pdf:
Element tabElement = builder.createRect(x, y - 36, tabWidth, tabHeight);
tabElement.setPathFill(true);
GState gstate = tabElement.getGState();
gstate.setFillColorSpace(ColorSpace.createDeviceRGB());
gstate.setFillColor(new ColorPt(0.9, 0.9, 0.9));
elementWriterLine1.writeElement(tabElement);
Element tabTextElementLine1 = builder.createTextBegin(Font.createTrueTypeFont(outputPdfDoc, ARIAL, true), 8);
Element textLine1 = builder.createTextRun("TEXT LINE 1");
if(isLandscape) {
tabPosition = 4 - tabPosition;
tabTextElementLine1.getGState().setTransform(1, 0, 0, 1, pageWidth - gap - (tabPosition * tabWidth) - (tabWidth/2 + textLine1.getTextLength()/2) , tabHeight-13 );
} else {
tabTextElementLine1.getGState().setTransform(0, -1, 1, 0, pageWidth - 13 , pageHeight - gap - (tabPosition * tabHeight) - (tabHeight/2 - textLine1.getTextLength()/2) );
}
tabTextElementLine1.getGState().setFillColorSpace(ColorSpace.createDeviceRGB());
tabTextElementLine1.getGState().setFillColor(new ColorPt(0, 0, 0));
tabTextElementLine1.setPathFill(true);
elementWriterLine1.writeElement(tabTextElementLine1);
I shared pdf file among my colleagues, they are also facing same problem.


Your text is not drawn inside a text object. Text drawing instructions may only be used in text objects.
For drawing the first line you have
but you probably should have
It's the same issue for the second line.
I don't know, though, how you can make pdftron add the BeginText and EndText operators.
By the way, there is quite a lot of unnecessary stuff in here, like drawing the text line twice or manipulating the transformation matrix right before a Q (RestoreState) operation...