webviewer form fill text can't be printed

281 views
Skip to first unread message

Jayaseelan A

unread,
Nov 2, 2016, 12:35:03 PM11/2/16
to PDFTron WebViewer
Hi,
In the latest WebViewer to display the form fill xod document with enter text and then try to print the document,form fill text can't be printed. there is the possibility to add form fill text when printing the document?

I have attached the sample xod document for the same.

please help us to resolve the issue asap.

Waiting for your reply
form1.xod

Matt Parizeau

unread,
Nov 3, 2016, 6:00:12 PM11/3/16
to PDFTron WebViewer
Hi,

One option would be to merge the form data back to the PDF and flatten the forms on the server before converting back to XOD and then printing that document.

Another option would be for you to modify the prepareDocument function in BaseReaderControl.js. This is where the images for each page are created and you could read the form field locations and create the form elements over top of the image for each page. In particular take a look at the callback to the loadCanvasAsync call.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Jayaseelan A

unread,
Nov 4, 2016, 12:56:23 PM11/4/16
to PDFTron WebViewer
Matt,
Thanks for your response.
The above mentioned your suggestion.we implemented the form data over top of the image using prepareDocument function in BaseReaderControl.js,but it is not working. Can you please send me any sample code for the same?

waiting for your reply.

Matt Parizeau

unread,
Nov 7, 2016, 1:50:04 PM11/7/16
to PDFTron WebViewer
Hi Jayaseelan,

If you could send us some of the code that you tried we could see what might be going wrong. You would probably want to create a container element the same size as the page image and place the form elements in there.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Jayaseelan A

unread,
Nov 8, 2016, 12:34:04 PM11/8/16
to PDFTron WebViewer
Hi Matt,
Thank your for your response.

we have implemented the static text when printing the document & following code in the basereadercontrol.js,

doc.loadCanvasAsync(pageNumber - 1, zoom, rotation, function(canvas) {
                    var ctx = canvas.getContext('2d');

                    // transform the canvas context so that annotations are drawn in the correct location
                    var t = window.GetPageMatrix(zoom, annotationRotationOffset, pageInfo);
                    ctx.setTransform(t.m_a, t.m_b, t.m_c, t.m_d, t.m_h, t.m_v);

                   // me.docViewer.getAnnotationManager().drawAnnotations(2, canvas);
                    var xfdfString = me.docViewer.getAnnotationManager().exportAnnotations();
                    var annotManager = me.docViewer.getAnnotationManager();
                    var fieldManager = annotManager.getFieldManager();
                   
                    var x = (canvas.width / 2) - 260;
                    var y = (canvas.height / 2) - 220;
                    var space = 0;
                    var lines = 'sample first name text';
                    ctx.font = '20px san-serif';


                    ctx.fillText(lines, x, y);

                    
                    dataurl = canvas.toDataURL();

Currently I am getting the form data filled in webviewer but I want to print the filled data text.
                   
i have attached the before printed document and after printed document for your reference.

Can you please tell me how to get the dynamic form fill data & control postion(x,y) based on the document?.

Please help me ASAP

Thanks
After_Printed.png
Before_Printed.png

Matt Parizeau

unread,
Nov 10, 2016, 8:04:06 PM11/10/16
to PDFTron WebViewer
Hi Jayaseelan,

Taking the approach of filling the text on the canvas you could use code like this:

var am = readerControl.docViewer.getAnnotationManager();
am
.getAnnotationsList().filter(function(annot) {
   
return annot instanceof Annotations.TextWidgetAnnotation;
}).forEach(function(annot) {
    ctx
.font = annot.font.size + 'px sans-serif';
    ctx
.textBaseline = 'top';
    ctx
.fillText(annot.getValue() || '', annot.X, annot.Y);
});

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Jayaseelan A

unread,
Nov 14, 2016, 1:02:28 PM11/14/16
to PDFTron WebViewer
Matt, Thank you for your kind response.

 we have currently working on it.

Thanks

Loganathan S

unread,
Nov 21, 2016, 12:41:07 PM11/21/16
to PDFTron WebViewer
Matt,
There is the possibility to download form fill xod(webviewer)  data to pdf file.Can you please send me any sample code for the same?

Thanks

Matt Parizeau

unread,
Nov 22, 2016, 8:54:23 PM11/22/16
to PDFTron WebViewer
It depends what you mean by that. Do you want to download the original PDF file but with the fields filled in?

You could send the XFDF data to your server and then import it to the PDF using PDFNet and return the file for download.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Loganathan S

unread,
Dec 29, 2016, 1:32:02 PM12/29/16
to PDFTron WebViewer
Hi Matt,
   
When printing more than one page in Fillable form document, the text filled in the corresponding pages but the text filled for the all page the text gets repeated for all the pages. Please provide me the code for fixing this issue.
sample code:
var am = readerControl.docViewer.getAnnotationManager();
am.getAnnotationsList().filter(function (annot) {
                        return annot instanceof Annotations.TextWidgetAnnotation;
                    }).forEach(function (annot) {
                        ctx.font ='12px sans-serif';
                        ctx.textAlign = 'center';
                        ctx.textBaseline = 'top';
                        ctx.fillText(annot.getValue() || '', annot.X, annot.Y);
});

Herewith attached sample output:

input : page1.png,page2.png
current output : page 1 print.png, page 2 print.png
exempted output :Exempted_page1print.png,Exempted_page2print.png

Please help me ASAP

Thanks

Regards,
Loganathan S 
page 1 print.PNG
page1.PNG
page2.PNG
page 2 print.PNG
Exempted_page1print.png
Exempted_page2print.png

Matt Parizeau

unread,
Dec 30, 2016, 2:30:09 PM12/30/16
to PDFTron WebViewer
Hi Loganathan,

This is happening because getAnnotationsList returns all annotations in the document. So that means for each page you're going to be drawing every text widget which is what you're seeing. To do this by page you just need to filter by PageNumber as well. So change return annot instanceof Annotations.TextWidgetAnnotation to:
return annot instanceof Annotations.TextWidgetAnnotation && annot.PageNumber === pageNumber;

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Loganathan S

unread,
Jan 3, 2017, 12:40:09 PM1/3/17
to PDFTron WebViewer
Hi Matt,

             Working Fine.

             Thank you.

Regards,
Loganathan S

Volker Andres

unread,
Feb 15, 2017, 2:41:08 PM2/15/17
to PDFTron WebViewer
Hi Loganathan

Could you please post your full solution for others?

Best regards
Volker
Reply all
Reply to author
Forward
0 new messages