Web App Builder - Public Notification Label PDF Creation via Download_Avery js file

659
7
Jump to solution
03-13-2018 03:22 PM
MikeCrook
New Contributor III

The default setup when using this PDF feature is that it creates a separate PDF file for each label page. For instance, if I have 45 labels, it generates 2 PDF files: Label_page_1.pdf and Label_page2.pdf.

I would like to create 1 PDF file with two documents inside. For instance, All_pages_of_Labels.PDF.

Has anyone tried and done this successfully?

Thanks

0 Kudos
1 Solution

Accepted Solutions
MikeCrook
New Contributor III

Hi Robert,

The Public Notification widget uses the Download_Avery.js file which uses the jsPDF library, to help generate the PDF files. After a spending several hours on this, I was able to create a configuration setting that allows me to toggle the PDF settings to allow each page to generate as its own PDF file or have multiple pages of labels inside one PDF file.

The code in the Download_Avery.js does not allow for this. So some small changes had to be made to accommodate for the toggle option. On  another note... I'm really impressed with how the web app builder operates behind the scene.

Thanks for your time,

Mike

View solution in original post

7 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Mike,

  From what I understand this widget uses a esri hosted print service to accomplish this. So bottom line is No you have no control over the print layout.

MikeCrook
New Contributor III

Hi Robert,

The Public Notification widget uses the Download_Avery.js file which uses the jsPDF library, to help generate the PDF files. After a spending several hours on this, I was able to create a configuration setting that allows me to toggle the PDF settings to allow each page to generate as its own PDF file or have multiple pages of labels inside one PDF file.

The code in the Download_Avery.js does not allow for this. So some small changes had to be made to accommodate for the toggle option. On  another note... I'm really impressed with how the web app builder operates behind the scene.

Thanks for your time,

Mike

RobertScheitlin__GISP
MVP Esteemed Contributor

Mike,


  That is great news. I was confusing this with the directions widget that uses a ESRI print service. Thanks for the info.

0 Kudos
MikeCrook
New Contributor III

Yes, there is a Print Settings to Export the map as a PDF, that uses esri print web services. But there is also a built-in Avery Label generator that generates PDFs and that uses the jsPDF library. It was my fault for not being clear.

Thanks

0 Kudos
AdamCottrell
Occasional Contributor

Thank you for posting this find.  Any possibility that you could share this bit of code?  At the very least, could you point me to where in the JS file that I could just hard code it to only use multiple pages as an option, even though there may only be one page?  I'm trying to move to this widget from the old javascript app and I keep finding these little things that make it less likely for the end user to switch over because you are asking them to do more work.

Any help would be greatly appreciated.  

0 Kudos
MikeCrook
New Contributor III

Here's a snippet of code to get you started. Below is at the beginning of the Download_Avery.js code. If you read my comment in the snippet, it explains more.  The 'labelMultiPagesPerPDF' you won't see in your copy because I created this parameter to be set in the config.json file, so I could turn the multi-page on or off. Basically, the 'pagesPerDoc' controls this. My comment also says, to set 'useVectorFonts' to true. This is a default setting in the config.json file under the 'notificationSettings' then the 'labelPageOptions' json nodes. You don't need to add the parameter to the config, feel free to hard code the changes.

good luck!

Mike

Beginning of Download_Avery.js code

0 Kudos
AdamCottrell
Occasional Contributor

Hey Mike, this is a great start.  First I was thrown off because the JS file that I was seeing is from the latest release.  The code is completely different now.  I was doing a search for those parameters (like "labelsPerPage", "pagesPerDoc", etc.) but they do not exist. Fortunately, I found an older copy of the JS file that has the same code structure has your screenshot.  Just so you are aware.  Also, I'm not using the Developer Edition.  I'm creating the app through web appbuilder inside of Portal and, after creating the initial app, I'm downloading so I can use it on straight from the server.  I'm not sure if this is part of the difference in the code or not.

Once again, thank you!  This has been extremely helpful.

0 Kudos